Serial on RPI

I have my bar nicely up running on my arduino with 4 buttons which opens and close the two parts of it, one for wine and one for spirits, however it would be awesome to get it integrated with openhab as well.

I have defined 2 switches to simulate my 4 buttons:

Switch spirit (Group_LivingRoom) Mappings("UP","DOWN)
Switch wine (Group_LivingRoom) Mappings("UP","DOWN)

In my arduino code I need to read in 0 spirit up,1 for spirit down, 2 for wine up 3 for wine down

I have tested my serial this way:
String Arduino "Arduino" { serial="/dev/ttyUSB0@115200" }

But can I connected it to GPIO pin 14 (pin 8 txd) or RPI instead? (its should be sending out 3.3v which my 5v arduino can read, I will get a pro 3.3 arduino later for two way comunication, feedback to openhab). And how can I then figure what serial it is? Also the cable is rather long, but i will test if it works before i go down the rs485 line.

And finally how should my rule look like:

rule "Wine"

    Item wine changed 
if(wine.state == OFF){
	Serial.println("2") // sent over serial to arduin0
     Serial.println("3") // sent over serial to arduin0

I will upload a video of it soon.

For interacting with the GPIO pins look at the GPIO binding. Keep in mind that you will need to run openHAB as root to access the GPIO pins. Also keep in mind that I think the binding only supports binary type Items (i.e Switches and Contacts) which I think will work for you if you wire them directly to your Arduinos.

I have some reed switches wired to a RasPi with a wire that is probably 100` plus in some cases so I doubt distance will be too much of a problem for you. Just be sure to put a resistor in there to prevent a spike that could kill your RasPi (I used 10k resistors).

Please see the Rules wiki page, examples on bottom right of wiki pages, and use Designer to learn proper syntax.

Given your Items your rule should be:

rule "Wine"

    Item wine changed 
    if(wine.state == OFF){

If you wire them up to your GPIO pins you won’t need a rule.

Thanks, the reason why I need to use serial or 1 wire or similiar and can not connect buttons directly to rpi are :
Only 4 wires available, i.e GND,VCC and tx/rx or i2c,pwm,1 wire (bad planning…)
I am running out of pins on my rpi

So my question is how do i set up serial on GPIO and not on USB?

I have tested my serial this way:
String Arduino "Arduino" { serial="/dev/ttyUSB0@115200" }

Thanks for the rule change :smile:

Trying to acess your pins as a serial device, if it is even possible, isnt going to solve your problems as a standard serial device needs 9 pins.

You will need to find or write something custom that can read and write on two pins kind of like morse code. The 1wire binding MAY be of some help but I don’t know. I do know the serial binding and serial device drivers built into Linux will be no help.

This might be going in the wrong direction (e.g. fix the problem, don’t work around it), but there are very cheap i2c extenders which work very reliably in my experience. I’ve mainly used them to hook up keypads with limited wires between the microcontroller and the ‘keypad wallmount box’ or whatnot:

Standard serial needs 3 wires gnd, tx and rx. I might not even rx since I don’t really rely on feedback

Both rpi and arduino has built in i2c the question is just how to bind openhab to i2c…

You don’t. You ‘simply have more pins at your disposal’ once you’ve hooked it up correctly, etc.

Now, whether the OpenHAB GPIO binding understands that - good question.

Looks promising?

this should be the right syntax:

String Arduino "Arduino" { serial="/dev/ttyAMA0@9600" }

And it should be connected to pin8/gpio14 on RPI. I cant get it to work, so I will go for a walk and check in later:)

I think I need to do this:

Note2: If you are using non standard serial ports you have to adapt to have the serial port included. the java command line should then include the following parameters:

whereas ttyAMA0 is the path to your serial port. Please be aware to change all scripts you might use for startup (debug, automatic start in linux,…)

However where is located when i start openhab with this script?
sudo /etc/init.d/openhab start

I don’t actually use any physical bindings directly with OpenHAB, so I can’t really confirm your suggestions regarding the serial connection, and I don’t use the init script myself, however my version has $DAEMON_ARGS, like many init scripts:

# get path to equinox jar inside $eclipsehome folder
cp=$(find $ECLIPSEHOME/server -name "org.eclipse.equinox.launcher_*.jar" | sort | tail -1);

DAEMON_ARGS="-Dosgi.clean=true -Declipse.ignoreApp=true -Dosgi.noShutdown=true -Djetty.port=$HTTPPORT -Djetty.port.ssl=$HTTPSPORT -Djetty.home=$ECLIPSEHOME -Dlogback.configurationFile=$ECLIPSEHOME/configurations/logback.xml -Dfelix.fileinstall.dir=$ECLIPSEHOME/addons -Djava.library.path=$ECLIPSEHOME/lib$ECLIPSEHOME/etc/login.conf$ECLIPSEHOME/etc/ -Djava.awt.headless=true -jar $cp -console ${TELNETPORT}"

To connect a 3.3V Raspberry Pi to a 5V Arduino over serial or I2C you will need a level shifter or you will damage your Pi. Something like this can be used: After you’ve got that wired up you should be able to use the serial binding. I’ve run 5V serial over at least 5m of UTP cable at 2400baud without any problem so I don’t think distance will be a problem for you. (That was using a Arduino on one side and the USB-to-serial part of a Launchpad on the other end)

You can also get Arduino Pro 3.3V that runs 3.3V to avoid the level shifter:)
For my test setup I am using a 5v Nano and a potentiometer as voltage divider (Couldnt find the sparkfun level shifter yesterday). How did you get accsess to

Where in init.d/Openhab did you add that line? Somewhere else as well?

So How do I append to DAMEON_ARGS?

My startup script can be found here.

Just add your parameter to the huge list. I don’t think the order makes any difference, but I’d make it the second parameter, or so. Make sure you have a space before and after it, like the other parameters.

I think I might have to do like this to get it to work, I will try tomorrow: