Using PyFirmata to transmit IR signals from an Arduino

Apologies in advance, as I'm really not sure where to post this as it falls between 2 separate approaches.

My current project involves getting signals from various sensors (e.g. motion, colour etc.) and then based on the value sending the appropriate IR signal.

I have a Python script on a Raspberry Pi which uses the PyFirmata library to get inputs from the Arduino and then sends an IR signal from the Pi. This approach works, but is limited as realistically the IR signal probably won't be strong enough from where the Pi is located, so whilst its fine for testing, in the real world scenario it may be impractical.

Additionally I have a standard .ino file which sends an IR signal, based on xyz, this is good as it means I can have the IR transmitter and sensor on the same Arduino board and the location isn't a problem...but the problem here is the Pi is better placed to determine when to send the signal as it needs to assess inputs from 2 other Arduino's too (i.e. in the real world situation in order to know what IR signal to send, I need to see the sensor value from that Arudino, send to the PI, then the PI sends back a decision and the Arduino outputs the signal).

So my plan was to simply (in theory) handle all the logic on the Pi using Python (which I'm far more familiar with), and just use the Arduino for reading / emitting. I think that approach is probably okay, but this is where I get stuck...I can send an IR signal from the Pi using Python and the various libraries that rely on LIRC. Additionally I can send an IR signal from the Arduino using a .ino file....

but what I can't seem to do, is use the PyFirmata library to send an IR signal from the Arduino based on an input from the Pi. So does anyone have any suggestions for that (I have used PyFirmata before, so I can get inputs and/or output to Arduino pins, but not an IR signal as all the Python libraries seem to rely on LIRC which is Pi specific)?

Hopefully that makes sense and I wasn't sure if this was the correct section as in my mind this is a coding question, but I appreciate some may think the approach is wrong, so I wasn't sure which category to post in!

Without more details on what sensors your running with the Arduino your wanting to send IR with it is difficult to suggest anything but my gut feeling is ditch Firmata and use a simple serial protocol on the Arduino that Python can use to request sensor readings, receive sensor readings and transmit IR codes.

I suspect you're right, that approach should work and I can't find a single example of anyone successfully using PyFirmata to do this, so maybe its not possible.

What I'm trying to do effectively is transmit an IR code taken from a LIRC config file, on the Pi. The config file is taken from here: lego-lirc/Single_Output at master · iConor/lego-lirc · GitHub

So the most simplistic test case would simply be as follows:

  1. Script starts on Pi
  2. After 1 second IR signal is sent once via Pyfirmta emitting from the Arudino (the bit I can't do)
  3. Script ends on Pi

There is also an Arduino library here:

Which is how I was able to verify I can send an IR signal from the Arduino, so I can write some functions that should work in C, but to avoid switching between languages, I was hoping to write everything in Python on the Pi and control everything centrally.

If that's not possible and I have to get more familiar with C, then so be it, it will be useful to learn anyway I guess.

I have looked into this a bit more and you may be able to use Firmata to do this.
The Arduino Firmata example here shows how to receive a string and echo it back but you could put your IR control commands in this string to decode and send over IR.
The Arduino-IRRemote library here supports Lego, you would just need to confirm these two library's work okay together and determine the structure of the data sent in a string that gets passed out to IR.

Ah interesting, that looks like it could be quite helpful, much appreciated!

I may try both approaches (i.e. this and using PySerial) just from a personal interest perspective to see if I can get both working.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.