Communicating our own Raspberry Pi with Farmbot

@Gabriel, thank you for your help and explanation. Also, thank you for being willing to add pyserial back in a future release. I am eagerly awaiting that release. I may tinker with building a custom FarmBot OS image in the meantime to add pyserial, but then I worry that updates will break it.

@unhfarmbot, I have come up with a half-way workaround for until the next version of FarmBot OS is released with pyserial. I am detailing this solution below in case it is helpful to you:

My temporary workaround

The problem: Since I cannot use pyserial in my Farmware, I cannot send and receive messages from FarmBot pi to the second pi.
The (half) solution: But I can read the debugging messages (including python print statements!) from FarmBot pi since these are output to serial. So this means that I can have one-way communication from the FarmBot pi to the second pi. Instead of waiting for the second pi to complete its actions and send a “completed” signal, I need to, instead, use sleep() to tell the FarmBot pi to wait a sufficient length of time to ensure completion of the task(s).

The physical setup

I am just using a simple UART connection that requires connecting 3 wires between the two pis. Using the BCM numbering, GPIO 14 is Tx and 15 is Rx. There is a Ground pin 2 pins down from those on physical pin #14. Here is a nice diagram of the pin layout if you aren’t already familiar with it:

  1. Connect Tx on FarmBot pi to Rx on the other pi.
  2. Connect Rx on FarmBot pi to Tx on the other one.
  3. Connect Ground to Ground.

The Farmware code

On the second pi, set up pyserial as usual and read the serial data sent. You will find that you get various messages (including the ImportError that I mentioned previously if you run your current Farmware).

Create a Farmware with a print statement and it will be sent to your second pi.

from time import sleep 

# Send "ON" signal to initiate process
print("SomethingUniquePiON")  # make this print something unique (serial sends debugging text)
sleep(10)  # Wait for second pi to finish its tasks.

Because you are also reading a bunch of debugging messages, you will want to send something unique that won’t be sent in these messages by chance. Then your code on the second pi can just check for "SomethingUniquePiON" in serial_data to start your SPAD measurements.

What’s missing?

For me, I would very much like to start the next step in the sequence based on confirming that the task is completed, rather than a set a waiting period. For you, I think you wanted to send the SPAD measurement values back over serial. I don’t have any workaround for that other than the HTTP method mentioned above which relies on a (reliable) internet connection for both pis.

1 Like

Nice write-up! Glad you figured something out and thanks for sharing it.

The pySerial package will be installed in the next minor FarmBot OS release.

It probably doesn’t make a difference in your case, but to clarify for others: the HTTP approach only requires the pis to be connected through a local network (intranet rather than internet). The non-FarmBotOS pi doesn’t need to be connected to the internet.

FarmBot OS v6.3.2 has been released, which includes the pySerial package.

1 Like

@Gabriel Thank you for the update and for posting that! Much appreciated.

@Sven @Gabriel Thank you very much, can you send us a link of where we can download it? I went to the github website and the file is still called FarmBot-rpi3-6.0.1

You will need to press the UPDATE button in the FarmBot OS line of the Device page Device widget.