Go Down

Topic: Serial communication between Python and off-board Arduino (Read 799 times) previous topic - next topic

Hello,

I'm working on a project that involves two Arduinos implemented off-board receiving serial data from a computer.

Currently I've got the project receiving the data from the MIDI output on my Firebox, which works great (inexplicably - didn't use an optoisolator and it doesn't like to receive MIDI data from any other devices).  What I'd like to do is use my Arduino board (ATmega-less) for its USB-Serial chip and communicate directly Python -> ATmegas.

I'm concerned that there's some sort of message mismatch, maybe bytes or something.

On the Arduino, this is what I'm doing:
Code: [Select]
byte incomingByte;
incomingByte = Serial.read();
if (Serial.available() > 0) {
    incomingByte = Serial.read();
    if (incomingByte== 176){
      action=1;
    }
    else if ( (action==1)&&(controller==0) ){
      controller=incomingByte;
    }else if ( (action==1)&&(controller!=0) ){
      value=incomingByte;
      writeLights(controller, value);
      controller=0;
      value=0;
      action=0;
    }else{
    }
  }



and this is what I was doing with Python:

Code: [Select]
ser = serial.Serial("/dev/tty.usbserial-A6008hrf", 31250)

def sendMidi(status, controller, value):
ser.write(str(status))
ser.write(str(controller))
ser.write(str(value))

def main():
sendMidi(176, 37, 127)


Now I was hoping that I could just connect the Serial RX pin on the Arduino board (ATmega-less) to the Serial RX pin on my off-board Arduino.  This didn't work.  The board's Rx LED lit up, so it's receiving something... I'm just not entirely sure how to troubleshoot this.  I would love to know the actual bytes coming off the Arduino, but I don't have an LCD...


skyjumper

Why are you doing a Serial.read() before checking to see if there is any data to be read?

Err that'd be a typo.  It's not there in my real code.

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy