more G-Labs products

Author Topic: Homegenie For Dummies  (Read 1111 times)

June 09, 2016, 07:43:57 AM
Read 1111 times

clivek

  • *
  • Information
  • Newbie
  • Posts: 4
Hi,
I am new to Homegenie, Raspberry PI and Arduino. I have just started with this and my goal is to do home automation for myself. (If I don't give up first)

I have some VB and basic programming skills and some DIY electronics experience.

Here's my scenario:

I have a Raspberry Pi 3 running raspbian and Homegenie. - Working
I have an Arduino mega2560 connected to the RPI via USB - Working - can upload sketches.
I have a sketch that I can turn on a LED connected to pin 13 on the Arduino - Working
I have added a button on Homegenie to turn the led on and off - Toggle if you will.

I am unable to get the led to toggle via the button on homegenie.

What I require is a very basic tutorial/instruction to get the button to turn on and off via homegenie.

Once I understand the flow, I am sure I will be able to progress.

I have spent 4 days searching and reading forums but I'm lost.

Any help would be greatly appreciated.
My apologies for the stupid question.


 

June 09, 2016, 12:08:32 PM
Reply #1

clivek

  • *
  • Information
  • Newbie
  • Posts: 4
I think my problem might be that I do not have the GPIO's for Arduino added to HG.

How do I add the GPIO for the Arduino to HG?



June 09, 2016, 04:35:20 PM
Reply #2

bkenobi

  • *****
  • Information
  • Global Moderator
  • Posts: 1525
It's been some time since I worked with Arduino on my RPi through HG, but as I recall you don't need to have a separate app installed to make the Arduino GPIO's available.  The RPi GPIO's aren't available unless you install an app, but to connect the Arduino to the RPi uses SPI so you should be fine.  I believe Gene uploaded a video that shows how to do some basic stuff with an Arduino.  I'd suggest looking in the video/tutorial section to see if that helps.

June 09, 2016, 05:39:50 PM
Reply #3

clivek

  • *
  • Information
  • Newbie
  • Posts: 4
Thank you. I looked at the video he posted about "PROGRAMMING ARDUINO WITH HOMEGENIE".

I am able to replicate what he did. I get the light to blink if i go to run in the sketch.

My problem is getting a button on the dashboard to execute/run the sketch.

I just want a normal on/off switch to turn led on or off. This is where i'm stuck.

June 09, 2016, 07:48:03 PM
Reply #4

Gene

  • *****
  • Information
  • Administrator
  • Posts: 1472
  • Tangible is the future!
    • Yet Another Programmer
You've to find a way of making HG communicate with the Arduino.
As an example you can have a look at these files:

https://sourceforge.net/projects/homegenie/files/testing/EdenV2_Firmware_1_1.zip/download
https://sourceforge.net/projects/homegenie/files/testing/EdenV2_Module_1_1.hgx/download
http://www.homegenie.it/docs/diy/eden_v2.php

the first file is a firmware for arduino that basically control an OLED display, a temperature sensor and a luminance sensor.
You probably don't need this, but you can take the SPI code that is used to make HG communicate with the arduino.
The second file in an hg program that use SPI to control the arduino counter part.
Another way is to use the serial port if this is available.
Also searching the forum could give you some more infos.


June 12, 2016, 03:55:44 PM
Reply #5

clivek

  • *
  • Information
  • Newbie
  • Posts: 4
I have so far done the following:

Installed ardulink and configured as /dev/ttyS80
Installed sketch on arduino to recognize and process serial commands.
if i send "echo "digital7|1" > /dev/ttyS80" from terminal window on RPI the command is understood and processed by arduino, Led Turns on.
if i send "echo "digital7|0" > /dev/ttyS80" from terminal window on RPI the command is understood and processed by arduino, Led Turns off.
if i send "echo "digital7|-1" > /dev/ttyS80" from terminal window on RPI the command is understood and processed by arduino, Led reverses state.

I have looked at the serial i/o test and cannot figure out how to send "digital7|1" to /dev/ttyS80

what am i missing? There is definately comms between RPI and Arduino serial port.

I butchered the code and can send data to Arduino.

var 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 raw byte message
  //byte[] message = { 0x00, 0x00, 0x00, 0x00, 0x00 };

// this is what i changed 
 SerialPort.SendMessage("digital7|-1");

  // pause 5 seconds
  Pause(1);
  // send a text message
  //SerialPort.SendMessage("Hello Things!");
  // pause 10 seconds and repeat again
  //Pause(10);
  break;
}

Arduino responds using this code.

where would i go next to link it to a switch and to accept change on and off - set variables ?





« Last Edit: June 12, 2016, 04:38:36 PM by clivek »