Raspberry Pi serialport support

@valentin after reviewing the Yun code, I realized that you are using serial port communication exclusively.

By copying and modifying the code you had in place, it was fairly trivial to enable the same for the Pi. The only “gotcha” is that the default OS install ties the Pi’s serial communication channel to the console (for login purposes). This is easy to disable, but it’s a manual process, so I updated the README with the appropriate steps.

Here’s the pull request, with Pi support. I wasn’t sure what to do about the copywrite info, because it’s largely borrowed code, so I left your standard header on the new file.


1 Like

Also, @valentin what are you connecting to your Yun that’s providing the serial input?
I’m trying to figure out what the serialServer() is trying to parse - that seems to be an application specific protocol.

The serial communication is between the two processors i think

The Yun has two processors. One MCU which handles the gpio input /output and another processor which is running openwrt as os (see https://www.arduino.cc/en/Main/ArduinoBoardYun). The communication between those two processors happens via a serial interface.
So the serial server you see runs on the openwrt chip and parses the information it receives from the MCU. There is a library for the MCU which you can use in your arduino sketch (see https://github.com/openhybrid/HybridObject). This is what creates the input for the serial server. For the pi the serial communication part won’t be necessary because the pi only has one chip. So you can directly access the gpio pins from within your javascript code for example with the onOff library you found. You dont’t need this whole switch statement for the pi.
If I were you I would probably implement a hardware interface for each application you want to create. For example if you control a switch which is connected to the gpio pins of the pi, I would create a hardwareInterface “piSwitch” and just read the state and write it to the OpenHybrid Server each time the value changes. Accordingly you would have to update the switch state if the OpenHybrid server passes a value through to the hardwareInterface.

1 Like

Thanks, @Carsten, that is crystal-clear - it makes perfect sense. I’ll retract my PR for serial communication and continue waiting for my Pi break-out board so I can start testing GPIO pin communications.

1 Like

Something else of note to folks who have an arduino + Pi lying around, but don’t have the Yun…

I was able to connect my Uno to the Pi via a simple USB cable and send serial data over the cable to the Pi. OpenHybrid w/ the serialport support code I referenced in the PR can detect and process that data. This is similar in concept to the Yun - 2 cpu’s: one for linux and one for sensor data. So it’s kinda cool :slight_smile:

1 Like

@KevinOrtman that is awesome , this way we could maybe use the arduino GPIO ,the Pi is not very good for analog I/O ,so maybe we can use arduino for that :smile:

1 Like