Hi
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:
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"
when
Item wine changed
then
if(wine.state == OFF){
Serial.println("2") // sent over serial to arduin0
}
else{
Serial.println("3") // sent over serial to arduin0
}
end
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"
when
Item wine changed
then
if(wine.state == OFF){
Arduino.sendCommand("2")
}
else{
Arduino.sendCommand("3")
}
end
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" }
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:
Note2: If you are using non standard serial ports you have to adapt start.sh to have the serial port included. the java command line should then include the following parameters:
-Dgnu.io.rxtx.SerialPorts=/dev/ttyAMA0
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 start.sh 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:
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: https://www.sparkfun.com/products/11771 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 -Dgnu.io.rxtx.SerialPorts=/dev/ttyAMA0
Where in init.d/Openhab did you add that line? Somewhere else as well?
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.