HomeGenie Forum

Automation Program Plugins and Wizard Scripting => Raspberry Pi GPIO/SPI/I2C => Topic started by: ram on October 28, 2014, 11:03:29 AM

Title: Homegenie + Raspberry Pi + Arduino + NanPy
Post by: ram on October 28, 2014, 11:03:29 AM
Hi,
I'm quiet new to Homegenie. I've installed HG in my RPi. I was wondering what would be the best way to connect my RPi with my Arduino UNO so that I can use HG to control my Arduino.

I came across a python library called Nanpy. Nanpy allows one to control Arduino connected to RPi (via USB) using python scripts.

I was wondering if nanpy can be used inside HG. Here is the details about Nanpy https://github.com/nanpy/nanpy

On the other hand, I would appreciate if someone could help me out in setting up a simple communication connection between RPi, Arduino and HG. What I would like to do is use the GUI of HG Program and control the GPIO on Arduino (like how I can control the GPIO of RPi).
Title: Re: Homegenie + Raspberry Pi + Arduino + NanPy
Post by: haitch on October 29, 2014, 01:22:32 AM
I am not sure what you plan on controlling with the Arduino but starting with HG --> serial --> Arduino seems like one way.  HG has a serial helper interface built in and python is supported.
Title: Re: Homegenie + Raspberry Pi + Arduino + NanPy
Post by: ram on October 29, 2014, 06:24:27 AM
Hi,
I'm a newbie to IoT and to the MCU's. I've followed some of the earlier forum posts to try to get a serial connection with my Arduino and that didn't work.

What I intend to achieve with HG is to have the a way of controlling all the digital and analog I/O pins on the arduino. For instance, if I have a temperature sensor plugged in to my Arduino pin, I would like to see it's value in HG.

Can someone give some form of connection drawing with Fritzing and also any form script to get me started with HG + RPi + Arduino. Thanks in advance
Title: Re: Homegenie + Raspberry Pi + Arduino + NanPy
Post by: haitch on October 29, 2014, 01:30:50 PM
For starters, are you able to communicate with the Ardino via the RPI?  Would you past some sample output from the serial monitor of Arduino software?

This is a basic example.
Code: [Select]
def ser_rec (mymessage):
    # this will be called every time a message is received from serial port
    hg.Program.Notify("SerialPort String", mymessage);
    print mymessage
    return None

#setup program stuff
def setup():
  portname = "/dev/ttyUSB0"  #this changes depending on the PRI USB or GPIO connection
  #ser = hg.SerialPort.WithName( portname ).OnMessageReceived( ser_rec ).Connect(9600)   # 9600
  ser = hg.SerialPort.WithName( portname ).OnMessageReceived( ser_rec ).Connect()   # defaults to 115200
  hg.Program.Notify("Python Test", "Hello Python "+portname)
  return None
hg.Program.Setup(setup)
Title: Re: Homegenie + Raspberry Pi + Arduino + NanPy
Post by: ram on October 29, 2014, 01:42:13 PM
I should use that script on Arduono IDE or on the HG automation Program? I've connected my Arduino via the USB cable to the RPi. The port name is /dev/ttyACM0
Title: Re: Homegenie + Raspberry Pi + Arduino + NanPy
Post by: haitch on October 29, 2014, 02:52:31 PM
The script is for HG.  As for the usb port name, it would be the same port that the Arduino programmer uses.  ttyACM0 is normally the GPIO pins.  I normally use the built in usb ports on the PRI and system sees my Arduino as ttyUSB0.

Code: [Select]
pi@raspberrypi / $ dmesg | grep FTDI
[400099.785264] ftdi_sio ttyUSB0: FTDI USB Serial Device converter now disconnected from ttyUSB0
[400141.208318] usb 1-1.2: Manufacturer: FTDI
[400141.258193] ftdi_sio 1-1.2:1.0: FTDI USB Serial Device converter detected
[400141.259700] usb 1-1.2: FTDI USB Serial Device converter now attached to ttyUSB0
Title: Re: Homegenie + Raspberry Pi + Arduino + NanPy
Post by: ram on October 29, 2014, 03:09:12 PM
Hi Haitch,
Thanks for the reply. I've tried your code in HG Automation Program with /dev/ttyACM0 and it successfully communicates with the Arduino UNO connected via USB to RPi. I tried using ttyUSB0 and it looks like it works too. I'm not sure.

Upon running the script, i see the message "Python Test Hello Python /dev/ttyACM0".

I'm getting some error in your script. It says "Runtime.Error = "TC: Object reference not set to an instance of an obje"

Also, when I try to execute the demise | grep FTDI, my RPi just returns with a carriage. There is no result displayed.
Title: Re: Homegenie + Raspberry Pi + Arduino + NanPy
Post by: haitch on October 29, 2014, 04:00:09 PM
Are you using the RPI to program the Arduino?  If so, which port does the Arduino IDE use when uploading a sketch?  The sample program ran because you were able to see the notify massage in HG.  You can also confirm if HG has a connection to the serial port by running "sudo lsof /dev/ttyUSB0".
Title: Re: Homegenie + Raspberry Pi + Arduino + NanPy
Post by: ram on October 30, 2014, 02:09:19 AM
Hi,
Yes. I use RPi to program Arduino. When I use the Arduino IDE, it shows /dev/ttyACM0.

When I use the following command at dev $ ls -la tty*, I don't see ttyUSB0 anywhere. All i see is ttyACM0 and ttyAMA0 in it.

When I used your sudo lsof /dev/ttyUSB0, i get the following:

l
Code: [Select]
sof: status error on /dev/ttyUSB0: No such file or directory
lsof 4.86
 latest revision: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/
 latest FAQ: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/FAQ
 latest man page: ftp://lsof.itap.purdue.edu/pub/tools/unix/lsof/lsof_man
 usage: [-?abhKlnNoOPRtUvVX] [+|-c c] [+|-d s] [+D D] [+|-f[gG]] [+|-e s]
 [-F [f]] [-g [s]] [-i [i]] [+|-L [l]] [+m [m]] [+|-M] [-o [o]] [-p s]
[+|-r [t]] [-s [p:s]] [-S [t]] [-T [t]] [-u s] [+|-w] [-x [fl]] [--] [names]
Use the ``-h'' option to get more help information.
Title: Re: Homegenie + Raspberry Pi + Arduino + NanPy
Post by: ram on October 30, 2014, 04:13:46 AM
I now get the following:

Code: [Select]
pi@ramServer /dev $ sudo lsof /dev/ttyACM0
COMMAND  PID USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
mono    4741 root    8u   CHR  166,0      0t0  803 /dev/ttyACM0
Title: Re: Homegenie + Raspberry Pi + Arduino + NanPy
Post by: ram on October 30, 2014, 04:15:47 AM
When i try the built-in Serial Port I/O Test with the following script I get message saying "DISCONNECTED". FYI, I've connected my RPi and Arduino via USB

v
Code: [Select]
ar portname = "/dev/ttyACM0";

 
Action<string>
HandleStringReceived = (string message) => {
 
  // this will be called every time a message is received from serial port
Program.Notify("SerialPort String", message);
 
};

Action<byte[]>
HandleMessageReceived = (byte[] message) => {
 
  // this will be called every time a message is received from serial port
Program.Notify("SerialPort Bytes", BitConverter.ToString(message));
 
};

Action<bool>
HandleStatusChanged = (bool connected) => {
 
  // this will be called every time the connection status changes
  Program.Notify("SerialPort Status", connected ? "CONNECTED!" : "DISCONNECTED!");
 
};

// open the serial port channel and register handlers
SerialPort
  .WithName( portname )
  .OnStatusChanged( HandleStatusChanged )
  .OnMessageReceived( HandleMessageReceived )
  .OnStringReceived( HandleStringReceived )
  .Connect( 9600 ); // change baud rate if needed

while (Program.IsEnabled)
{
  // send a test message through serial port every 10 seconds
  //
  byte[] message = { 0x00, 0x00, 0x00, 0x00, 0x00 };
  SerialPort.SendMessage(message);
  //
  Pause(5);
  SerialPort.SendMessage("Hello Things!");
  //
  Pause(10);
}
Title: Re: Homegenie + Raspberry Pi + Arduino + NanPy
Post by: haitch on October 30, 2014, 04:52:15 AM
Maybe someone else can help then... I know nothing of C#. 
Title: Re: Homegenie + Raspberry Pi + Arduino + NanPy
Post by: ram on October 30, 2014, 04:57:59 AM
Hi
What I meant by using IDE was when I don't use HG, I use IDE to program. If you have any success with Python to control the I/O pins in Arduino via HG, do please help me.
Title: Re: Homegenie + Raspberry Pi + Arduino + NanPy
Post by: ram on October 30, 2014, 09:38:42 AM
I figured it myself. Everything works as expected now. RPi successfully talking to Arduino via Serial USB sending commands which can now be controlled via HG. Thanks
Title: Re: Homegenie + Raspberry Pi + Arduino + NanPy
Post by: Bitcraze on March 30, 2015, 05:01:20 PM
Hi, Gene

Is it possible to use a USB-to-GPIO in Windows, and make use of the GPIO's in HG? GPIO is only under the RPI section, which isn't listed in Windows.

http://www.ebay.com/itm/12-I-O-USB-Controller-PIC18F14K50-USB-GPIO12-/221591439241?pt=LH_DefaultDomain_3&hash=item3397e10789 (http://www.ebay.com/itm/12-I-O-USB-Controller-PIC18F14K50-USB-GPIO12-/221591439241?pt=LH_DefaultDomain_3&hash=item3397e10789)


Thanks,


Eugene
Title: Re: Homegenie + Raspberry Pi + Arduino + NanPy
Post by: Wibo on March 30, 2015, 08:54:57 PM
Hi Eugene,

took a quick look at the link you've posted...

Seems like a PIC controller with an USB interface and some inputs and outputs.
Didn't bother to find out if you need special USB drivers.

Can tell you that GPIO in HG is dedicated to the general purpose input output of the RPi CPU.
The hgx part could be adapted pretty easy, but the underlying library doesn't know anything about a PIC controller or its USB interface.

Therefore the support for this device needs to be written from scratch I'm afraid.

Best regards,
Wibo.
Title: Re: Homegenie + Raspberry Pi + Arduino + NanPy
Post by: rikisphinx on June 28, 2015, 12:03:12 AM
Hi all,
    I've been looking everywhere to find a comprehensive tutorial explaining the way to interconnect the pi with the arduino using the HG interface... what i want to do is to be able to turn a chain of LEDs connected thru the arduino from the HG interface. I also need to monitor my generator fuel live from the HG interface and i already have this setup in my arduino, i just need to represent it in the HG interface. I have seen viedeos where people have a sketch blinking but this is not exactly what i want to achieve since i need to control the LEDS from a button in the HG interface. Hopefully one of you can help me out with it...  (I have read all the info in these posts but find them a little bit hard to follow...) i really need help from the start i.e. connections (pi to arduino) to the HG interface. I do have  working sketch for what i need to achieve from the arduino side).
 
Title: Re: Homegenie + Raspberry Pi + Arduino + NanPy
Post by: bkenobi on June 29, 2015, 05:50:16 PM
I was able to link an Arduino Pro Mini to the RPi and program/control it via HG.  There is a thread here from ~6 months ago that discusses it including comments about my progress.  If you can't find it, I can look around and post the link.
Title: Re: Homegenie + Raspberry Pi + Arduino + NanPy
Post by: rikisphinx on July 01, 2015, 07:21:06 PM
hi bkenobi,
   Thank you for your reply, I looked around and didn't find the link you mentioned... If you still have it could you please share the link? There are some infos that i found on this forum but they are really hard for me to follow since they don't really tackle the issues from the beginning...  I really need that thing to work and if you are willing to help me with it i would really appreciate.
Title: Re: Homegenie + Raspberry Pi + Arduino + NanPy
Post by: bkenobi on July 01, 2015, 07:47:14 PM
I followed guides and it took a few tries.  I did not try using USB communication.  If you want to connect via USB, I can't help.  But, if you use a Pro Mini or any other board that can use serial communication, then the method I used (from a guide) will work.

This is the thread I was working through the issues in:
http://www.homegenie.it/forum/index.php?topic=835 (http://www.homegenie.it/forum/index.php?topic=835)