I am yet again stuck on serial communications and in need of some help please.
The Plan
I am trying to send some data from an Arduino Nano to a Raspberry Pi Model B. I want to do this via the Tx pin on the Arduino and the Rx pin on the Raspberry.
What I have done so far:
The serial tty setup and so has been done and I have been able to set up successful serial connection between 2 Raspberry Pis
I have written a sketch for the Tx on the Arduino and the Rx on the Pi but I am not sure this is the correct way of doing it (well its obviously not because its not working)
Arduino Nano Tx Sketch
int iCount = 10000;
// ----------------------------------
void setup(){
Serial.begin(9600);
}
void loop(){
while(iCount < 30000){
Serial.write(iCount);
//Serial.flush(); // is this needed?
//Serial.println(iCount); // should i rather use print than write?
iCount = iCount + 1;
if (iCount == 30000){
iCount = 10000;
}
}
}
Questions - Arduino:
Is this the right way of doing this?
is the flush needed?
should I rather be doing it with Serial.print? I didnt think this worked since the Tx LED did nothing with this meaning no Tx activity. Correct?
Raspberry Rx:
import Serial
oSer = serial.Serial("/dev/ttyAMA0")
oSer.baudrate = 9600
sSerialInput = oSer.read(6)
#sSerialInput = oSer.realine() # Is this the right way of doing it?
print sSerialInput
Questions RPi:
given that I am sending a 6 digit number is the oSer.read(6) the right method?
Should I rather use readline?
I am not sure where my error is, can anyone help sort this out with me please? Also I would like to send over a list at a later stage with 7 to 9 entries? how is this best done?
Aucun commentaire:
Enregistrer un commentaire