Python Forum
assign the variable to every value received serial from Arduino
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
assign the variable to every value received serial from Arduino
#1
Hi, I am continuously getting the output of the temperature sensor from Arduino is like

28.92 64.26 93.77
and I want to assign the variable to these values.
Need suggestion about how can I be able to assign the variable to these values?

Will be very helpful.
Reply
#2
First of all, it's the other way around - you assign values to variables, not variables to values.
Second, because it's a constant stream of data, it's better to use some sort of data structure - e.g. list to store data into memory in a variable.
You may want to store data simultaneously in a database or write to file
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Thanks for the reply,
Any kind of useful example which help?
Reply
#4
Working with lists

show your code so far if you want more specific help
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#5
Hi, Mentioned below is my "Embedded C code" for temperature sensor connected to Arduino
#include<Wire.h> // SHT25 I2C address is 0x40(64) #define Addr 0x40 void setup() { // Initialise I2C communication as MASTER Wire.begin(); // Initialise serial communication, set baud rate = 9600 Serial.begin(9600); delay(300); } void loop() { unsigned int data[2]; // Start I2C transmission Wire.beginTransmission(Addr); // Send humidity measurement command, NO HOLD master Wire.write(0xF5); // Stop I2C transmission Wire.endTransmission(); delay(500); // Request 2 bytes of data Wire.requestFrom(Addr, 2); // Read 2 bytes of data // humidity msb, humidity lsb if(Wire.available() == 2) { data[0] = Wire.read(); data[1] = Wire.read(); // Convert the data float humidity = (((data[0] * 256.0 + data[1]) * 125.0) / 65536.0) - 6; // Output data to Serial Monitor Serial.println(humidity); } // Start I2C transmission Wire.beginTransmission(Addr); // Send temperature measurement command, NO HOLD master Wire.write(0xF3); // Stop I2C transmission Wire.endTransmission(); delay(500); // Request 2 bytes of data Wire.requestFrom(Addr, 2); // Read 2 bytes of data // temp msb, temp lsb if(Wire.available() == 2) { data[0] = Wire.read(); data[1] = Wire.read(); // Convert the data float cTemp = (((data[0] * 256.0 + data[1]) * 175.72) / 65536.0) - 46.85; float fTemp = (cTemp * 1.8) + 32; // Output data to Serial Monitor Serial.println(cTemp); Serial.println(fTemp); } delay(300); }
And This is My python code which I am using in my Laptop to receive the serial data:

import serial ard = serial.Serial('COM4', 9600); while True: k = ard.readline().decode('ascii') print(k)


and my output is continuously mentioned as

20.79 69.42 90.01
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  sending strings to arduino over serial/accessing DLLs HeWhoHas 0 1,375 Nov-09-2024, 06:01 PM
Last Post: HeWhoHas
  pyserial/serial "has no attribute 'Serial' " gowb0w 11 33,605 Sep-27-2024, 12:18 PM
Last Post: NigelHalse
Star Pyserial not reading serial.readline fast enough while using AccelStepper on Arduino MartyTinker 4 11,979 Mar-13-2023, 04:02 PM
Last Post: deanhystad
Question How to understand the received bytes of ser.read? pf2022 3 4,311 Mar-24-2022, 11:37 AM
Last Post: pf2022
  serial connection to Arduino Jack9 4 4,582 Oct-22-2021, 10:18 AM
Last Post: Jack9
  Attribute Error received not understood (Please Help) crocolicious 5 4,772 Jun-19-2021, 08:45 PM
Last Post: crocolicious
  When I print a key from dict it prints it but when I try to assign it to a variable I stefanvelikov 3 3,825 Nov-27-2020, 01:29 PM
Last Post: stefanvelikov
  Serial loopback with Arduino doesn't work ThomasS 3 4,632 Sep-19-2020, 12:47 PM
Last Post: deanhystad
  How to assign a module to a variable even if it's not defined? mandaxyz 5 5,742 Aug-12-2020, 10:34 PM
Last Post: snippsat
  Can't transmit serial fast Python to Arduino pyserial mRKlean 0 3,331 Mar-29-2020, 08:12 PM
Last Post: mRKlean

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020
This forum uses Lukasz Tkacz MyBB addons.
Forum use Krzysztof "Supryk" Supryczynski addons.