more G-Labs products

Author Topic: Homegenie + Raspberry Pi + Arduino + NanPy  (Read 8459 times)

October 28, 2014, 11:03:29 AM
Read 8459 times

ram

  • *
  • Information
  • Newbie
  • Posts: 13
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).

October 29, 2014, 01:22:32 AM
Reply #1

haitch

  • *
  • Information
  • Newbie
  • Posts: 6
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.

October 29, 2014, 06:24:27 AM
Reply #2

ram

  • *
  • Information
  • Newbie
  • Posts: 13
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

October 29, 2014, 01:30:50 PM
Reply #3

haitch

  • *
  • Information
  • Newbie
  • Posts: 6
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)

October 29, 2014, 01:42:13 PM
Reply #4

ram

  • *
  • Information
  • Newbie
  • Posts: 13
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

October 29, 2014, 02:52:31 PM
Reply #5

haitch

  • *
  • Information
  • Newbie
  • Posts: 6
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

October 29, 2014, 03:09:12 PM
Reply #6

ram

  • *
  • Information
  • Newbie
  • Posts: 13
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.

October 29, 2014, 04:00:09 PM
Reply #7

haitch

  • *
  • Information
  • Newbie
  • Posts: 6
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".

October 30, 2014, 02:09:19 AM
Reply #8

ram

  • *
  • Information
  • Newbie
  • Posts: 13
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.

October 30, 2014, 04:13:46 AM
Reply #9

ram

  • *
  • Information
  • Newbie
  • Posts: 13
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

October 30, 2014, 04:15:47 AM
Reply #10

ram

  • *
  • Information
  • Newbie
  • Posts: 13
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);
}

October 30, 2014, 04:52:15 AM
Reply #11

haitch

  • *
  • Information
  • Newbie
  • Posts: 6
Maybe someone else can help then... I know nothing of C#. 

October 30, 2014, 04:57:59 AM
Reply #12

ram

  • *
  • Information
  • Newbie
  • Posts: 13
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.

October 30, 2014, 09:38:42 AM
Reply #13

ram

  • *
  • Information
  • Newbie
  • Posts: 13
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

March 30, 2015, 05:01:20 PM
Reply #14

Bitcraze

  • ***
  • Information
  • Full Member
  • Posts: 73
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


Thanks,


Eugene