I get a float from raspberry pi (via struct module) and my sketch only shows the data on an LCD screen.
After 26 corrects loop, on the 27th, the Arduino crashes.
Can you tell me what's wrong with the 27th?
- Changing delay from 20ms to 1s: NOK
- Put the byte pointer out of the function: NOK
float f;
void getFloat(){
byte *fdata = (byte *) &f;
while(Serial.available() <= 4){}
Serial.readBytes(fdata,4);
}
void loop() {
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
lcd.setCursor(0, 0);
lcd.print("Ready to receive");
getFloat();
AZ=f;
getFloat();
AL=f;
lcd.setCursor(0, 0);
lcd.print("Moving ");
lcd.setCursor(0, 1);
// print the number of seconds since reset:
lcd.print("AZ");
lcd.print(String(AZ));
lcd.setCursor(7, 1);
lcd.print("; AL");
lcd.print(String(AL));
delay(1000);
Serial.println("ok");
}
At the 27th, the arduino no longer acknoledge the data and the LCD shows : ==ving AZy ; AL0.00=
=== Resolution ===
Before, I have to send twice the floats via the next code to get the last if not, I get the previous data on my arduino but i think the limitation comes from there :
def sendFloatToArduino(self,data):
self.serial.write(struct.pack('<f', data))
self.serial.flush()
def pointer(self,AZ,AL):
#send the data
print("AZ : "+str(AZ)+" ; AL : "+str(AL))
self.sendFloatToArduino(AZ)
self.sendFloatToArduino(AL)
self.sendFloatToArduino(AZ)
self.sendFloatToArduino(AL)
#wait for ack
while (self.serialArduino.in_waiting==0):
pass
print(self.serialArduino.readline())
After deleting the double sending, everything is fine.