I also have Node Red setup along with an Arduino UNO attached via USB with the Firmata firmware running on it. Node Red is running fine, I have some servo's and led's I can control on the Arduino with no problems. I'd like to add the same kind of functionality within my app. I would like to continue using Firmata but if I have to write a simple sketch on Arduino to retrieve the serial data and use PySerial so be it.
So where I'm at right now. I'm trying to use PyFirmata to send TCP data from my app to the RPi ->Arduino to blink a LED. Using this documentation(http://raspberrypi-aa.github.io/session3/firmata.html) the furthest I've gotten was turning the LED by adding the red to the script
I added this line: board.digital.write(1) to the script, which does turn the LED on the first time data is received, but that's about it. I tried replacing the (1) with (data) and some other variations but I can't seem to get the LED to turn ON/OFF. I'm confused at this point. I haven't tried PySerial yet so I dont know if I would have a easier time using that library instead. If you've read this far, thanks, Im open to any ideas.
Code: Select all
from pyfirmata import Arduino, util board = Arduino('/dev/ttyACM0') import socket host = '' # Symbolic name meaning all available interfaces port = 12345 # Arbitrary non-privileged port s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind((host, port)) print host , port s.listen(1) conn, addr = s.accept() print('Connected by', addr) while True: try: data = conn.recv(1024) if not data: break print "Client Says: "+data board.digital.write(1) conn.sendall("Server Says:hi") except socket.error: print "Error Occured." break conn.close()