ARDUINO plugin discussion

Posted on
Mon May 18, 2015 5:45 pm
kw123 offline
User avatar
Posts: 8366
Joined: May 12, 2013
Location: Dallas, TX

Re: ARDUINO plugin discussion

what should be the next project:

- include I2C sensors/ output devices (temp barometers, more complicated things, multiple digital devices..).
- use the ESP8266 on MEGA, then UNO then mini Pro.. MEGA is easier to program with 2 serial ports.

any votes?

for i2c: the data schema would be:
command: i2
pin: X0 for write
values: 1. address; 2. byte; 3 ... byte to send to i2c device, if "-" use as delay in secs
pin: X1 for read
Values: 1. address, 2. # of bytes to read
the ARDUINO sketch would point the X0,X1 to the proper pins, i.e. UNO=A4/5 MEGA=D20,D21.. with a #ifdefined MEGA .. I2C X0=D21 ...

example:
curl http://192.168.1.x/"?i2:X0=122,17,23,-33,20&?" would write to address 122 two bytes: 17 and 23 and then delay 33 msecs and then write one byte 20
curl http://192.168.1.x/"?i2:X1=122,2&?" would read 2 bytes from i2c device# 122

that should cover any simple device like temp, pressure etc, but likely not displays or something like that .. but as a first step.. should be cool.


Other things we could do: scan i2c bus for device #s ; set device numbers .. but that is phase 3..

Karl

Posted on
Tue May 19, 2015 7:29 am
DomoPat offline
User avatar
Posts: 210
Joined: Jul 17, 2010
Location: Toulouse, France

Re: ARDUINO plugin discussion

You would need to add a web server to your mac. That's possible actually very simple. But you still need to listen to something somewhere. ... Either in indigo, on the mac or on the network ....


I was thinking the plugin is a good place for receiving the communication from the board.. :-)

Anyway my experience is that the overhead is very small. I am pulling 3 arduinos every second. The network traffic is <3 kbit/ second per ARDUINO. Just to compare on the Ethernet I have about 1 mbit continuously due to the cameras.


So what is the fastest you could poll one single board ? 0.5 second ? less ?

Patrick

Posted on
Tue May 19, 2015 11:44 pm
kw123 offline
User avatar
Posts: 8366
Joined: May 12, 2013
Location: Dallas, TX

Re: ARDUINO plugin discussion

with this setup the response time to read a single pin
- on ethernet is 0.05 secs
- on wifi 0.2 seconds.

but anyway oneway or the other you have to poll:

There are 2 things you can do: read and write

(a) if the arduino is the server the mac need to poll for read= get pin values to the mac and send for write= set pin values
(b) if the mac is the server the arduino would need to poll for the write

installing both i.e. client AND server on the arduino is I believe not possible. you would need MUCH more ram cpu ...


Karl

Posted on
Wed May 20, 2015 12:06 am
kw123 offline
User avatar
Posts: 8366
Joined: May 12, 2013
Location: Dallas, TX

Re: ARDUINO plugin discussion

just got the esp8266 dev board ($15) to work:
http://www.amazon.com/Diymalllua-Nodemcu-Network-Development-Esp8266/dp/B00UY8C3N0/ref=zg_bsnr_537316_1
as a standard standalone arduino board with 10 i/o pins. Wifi works and I can run my arduino apps on it.
The pins are different etc, but thats just config.

BUT it was a long way to get there. Here the basics:

1. download and install the USB driver http://raysfiles.com/drivers/ch341ser_mac.zip and http://www.codenuke.net/2015/01/nodemcu-install-ch340-usb-to-serial-for-yosemite.htmland http://blog.squix.ch/2015/02/esp8266-nodemcu-dev-kit-review.htmlyou need to follow exactly the procedures
2. install the ESP8266 arduino models, downloads from adafruithttps://learn.adafruit.com/adafruit-huzzah-esp8266-breakout/using-arduino-ide

THEN USE an USB outlet with enough power > 400mA!!

and then it works .. took me 3 + days... don't know if it is stable .. like running for > 1 year ..

unfortunately I will leave tomorrow and the thing has to wait till I am back..

Karl

ps.
another wifi solution for arduino is :http://store.cutedigi.com/wifi-shield-wishield-v2-0-for-arduino/ $20
Attachments
Screen Shot 2015-05-20 at 12.55.07 AM.png
Screen Shot 2015-05-20 at 12.55.07 AM.png (158.21 KiB) Viewed 6724 times

Posted on
Thu May 28, 2015 6:12 am
DrLove offline
Posts: 260
Joined: Dec 12, 2014
Location: Sweden

Re: ARDUINO plugin discussion

mattggarland wrote:
Using an Atmel ATMega pretending to be an Uno - code should work with all though.

I am using the hardware serial ports (0,1) for the wifi card - software serial isn't fast enough for the high baud rate of the card so hardware serial is necessary, or you could change the baud rate of the esp8266 - can't remember how but google knows all!.

My code to send to indigo is:


Code: Select all
void indigoSend(String TextToSend){
  Serial.print("AT+CIPSEND=" + String(TextToSend.length() + 3, DEC) + "\r\n");
  delay(10);
  Serial.print(TextToSend + "\n");
  delay(1);
  Serial.print("\r\n");
  serialFind('K',5000);
};

sends the code followed by a newline (kinda standard).
Matt


I would like to test this, could you comment the lines in the code? What do "serialFind('K',5000);" do for example? (I'm a esp8266 noob)

Is the Arduino server or client? Looking at the Cynical Network plugin I think using Indigo as client w/ auto connect enabled and Arduino as server would be the safest way. If connection goes down the Indigo plugin will try to reestablish the connection. The Arduino as client wont I guess?

Do you have some code for the initiation of the esp8266 you could share, server (or client) setup and so on. I would love that!

Best regards, L

Love Kull (yes it's my name)
Blog (in Swedish)
Sweden

Posted on
Thu May 28, 2015 1:18 pm
kw123 offline
User avatar
Posts: 8366
Joined: May 12, 2013
Location: Dallas, TX

Re: ARDUINO plugin discussion

I know of Serial.find() but not serialFind("stringtofind",nn)

http://www.arduino.cc/en/Serial/Find

Posted on
Thu May 28, 2015 2:13 pm
mattggarland offline
Posts: 49
Joined: Jan 06, 2013

Re: ARDUINO plugin discussion

Okay, guys you should really go off and read the datasheet for the esp8266 commands, it's really handy!

I have indigo as server using cynical Network and arduino as client. Allows the ESP8266 to be given an IP address with DHCP (and access to indigo over 3G while the esp8266 is tethered to my phone :-p) so I would recommend doing it that way round.

The ESP8266 uses a system called AT commands, so you print to its serial port:
AT+RST
And it will reset,
AT+CWJAP is a command to connect to a wifi network, you need to give it your SSID and Wap Key - the details for the exact protocol are in the datasheet.
AT+CIPSTART allows connection to a TCP server, so it has variables too (once again the syntax is in the datasheet).

Once these three commands have been executed, you have an open TCP connection between indigo and the esp8266.

So you can use an action in indigo to send an indigo variable to the esp8266. The module receives it and prints it, but with an AT-style wrapper. It's something like AT+DATAIN 6, HELLO

Where 6 is the number of bits received (the letters of 'Hello' and the newline)

Just hook the esp8266 up to pins 0 and 1 on the arduino. You need to make a voltage level convertor for the tx pin on the arduino (2 resistors, connected like

Arduino TX - Resistor -Esp8266 RX - Resistor - Ground

With the resistors being 1k and 2k respectively

And remember to run off 3V.

I have some connection code but it's a bit sketchy, fails some times, esp8266 crashes if I don't leave a big gap between connect to wifi ad connect to indigo.


Sent from my iPhone using Tapatalk

Posted on
Thu May 28, 2015 2:58 pm
kw123 offline
User avatar
Posts: 8366
Joined: May 12, 2013
Location: Dallas, TX

Re: ARDUINO plugin discussion

Serial.find is pure arduino not esp8266.

The 8266 comes in different form factors and different interfaces. Amongst others there are: sent AT commands via eg rxtx pins on an arduino , one is an arduino ide "native" interface and then there is the arduino esp mode In addition there is the Lula mode. ...


Sent from my iPhone using Tapatalk

Posted on
Sat May 30, 2015 12:18 pm
mattggarland offline
Posts: 49
Joined: Jan 06, 2013

ARDUINO plugin discussion

Thought we were talking about the 8 pinned £2 /$3 option off eBay, being interfaced with an arduino ...
This fella...
Image

... I think writing code for the actual esp8266 isn't hugely useful for most folks around here and seems to be pretty limited (pin/power wise)

Posted on
Sat May 30, 2015 11:34 pm
kw123 offline
User avatar
Posts: 8366
Joined: May 12, 2013
Location: Dallas, TX

Re: ARDUINO plugin discussion

The full pin out board ($15) has 10+ io pins and can be programmed directly with the arduino ide Ada fruit now has a download that makes it fully compatible the wifi calls look identical. But yes adding this one to an existing arduino will be included too.


Sent from my iPhone using Tapatalk

Posted on
Tue Jun 09, 2015 12:38 pm
DrLove offline
Posts: 260
Joined: Dec 12, 2014
Location: Sweden

Re: ARDUINO plugin discussion

Finally I found time to play w/ the ESP8266-1 + Mega and I think I got a few more grey hair from it.... The SoftSerial + UNO way almost made me give up.

Long story short:

IM140905002pic1.jpg
IM140905002pic1.jpg (38.87 KiB) Viewed 6583 times


VCC -> 3.3v (NOT 5v)
CH_PD -> 3.3v (NOT 5v)
(GPIO -> GND @ Flash ONLY)
URXD -> Voltage divider -> Mega TX2 (330ohm and 180 ohm OK, 20k and 10k did not work well for me)
UTXD -> Mega RX2
GND -> GND

Updated to AT v.0.22, the latest ( .25) killed my ESP after a few resets, strange.
I used the "one bin" from here: http://esp8266.ru/esp8266-iot-sdk-v1-0-0-at-v0-22/, use google translate.

Used a USB-serial adapter directly to the ESP to begin with and:

Code: Select all
AT+CIPSTAMAC_DEF="<ESP-MAC-Address>" (at flash the MAC is reset to ff:ff:... or something, I had to give it a "real" MAC)

AT+RST (Reset)

AT+CWMODE_DEF=1 (Client mode burned in to memory)

AT+RST (Reset)

AT+CWJAP_DEF="<SSID>","<PSW>" (Burns the SSID and PSW to ESP-memory)


With this version you can program the SSID/PSW in to the ESP and you don't have to do the connection part from the arduino!
If you don't get an IP from the router check the DHCP settings of the ESP.

Setup Cynical Network as TCP-server w/ "New Line" as ending.

Used the WeeESP8266 library from: http://docs.iteadstudio.com/ITEADLIB_Arduino_WeeESP8266/index.html
I have tested allot of library's and also only using AT+... but this library works great.

This is my code for a simple setup:

Code: Select all
#include "ESP8266.h"

#define HOST_NAME   "192.168.123.12" //Indigo IP
#define HOST_PORT   (8090) //Cynical Network port

bool sendON = true;
bool sendOFF = true;


ESP8266 wifi(Serial2);

void setup(void) {
  pinMode(53, INPUT_PULLUP);
  Serial.begin(115200);
  Serial.println();
  Serial.print("RST: ");
  if (wifi.restart()) {
    Serial.println("OK");
  }
  delay(5000); //Wait for WiFi to connect, have not found a way to monitor the progress of connection, in AT v0.25 you get a message when connected but .25 did bug out for me..

  if (wifi.disableMUX()) {        //Single connection mode
    Serial.println("SINGLE CONNECTION OK");
  } else {
    Serial.println("SINGLE CONNECTION ERROR");
  }
   
  if (wifi.createTCP(HOST_NAME, HOST_PORT)) {  //Connect to Indigo
    Serial.println("CONNECTED TO INDIGO");
  } else {
    Serial.println("ERROR CONNECTING TO INDIGO");
  } 
   
  Serial.println("SETUP END");
 
}

void loop() {
  int sensorVal = digitalRead(53); //Checks the status of pin 53
  if (sensorVal == HIGH) { 
    if (sendOFF) {
      char *outText = "OFF\n";
      wifi.send((const uint8_t*)outText, strlen(outText)); //Put OFF in variable in Indigo if pin 53 is not grounded
      sendOFF = false;
      sendON = true;
    } 
  } else {
    if (sendON) {
      char *outText = "ON\n";
      wifi.send((const uint8_t*)outText, strlen(outText)); //Put ON in variable in Indigo if pin 53 is grounded
      sendON = false;
      sendOFF = true;
    }
  }
 
  uint8_t buffer[128] = {0};
   
  uint32_t len = wifi.recv(buffer, sizeof(buffer), 100);
  if (len > 0) {
    for(uint32_t i = 0; i < len; i++) {
      Serial.print((char)buffer[i]); //Prints out the message from Indigo to the serial monitor
    }
  }
  delay(50);
}

Love Kull (yes it's my name)
Blog (in Swedish)
Sweden

Posted on
Thu Jun 11, 2015 2:23 pm
DrLove offline
Posts: 260
Joined: Dec 12, 2014
Location: Sweden

Re: ARDUINO plugin discussion

PS.

I have noticed that I can't send data to Indigo before Indigo have sent a message to the Arduino first, after a reboot of the Arduino. I don't know if it's a cynical network or Arduino problem. Anyone recognize this?

L

Love Kull (yes it's my name)
Blog (in Swedish)
Sweden

Posted on
Thu Jun 11, 2015 7:30 pm
mclass offline
Posts: 315
Joined: May 13, 2015
Location: Melbourne, Australia

Re: ARDUINO plugin discussion

I am a "refugee" from the Fibaro HC2 and now have two Indigo systems in service. I continue to be amazed by the flexibility and versatility of Indigo, and wonder why didn't I find Indigo much earlier in my home automation journey?

Thanks for this great Arduino plugin.

I have been successfully using it over ethernet, but am now wrestling with the possibilities of wifi using my recently acquired ESP-01 module and Freetronics ESP1 shield (see http://www.freetronics.com.au/products/esp-01-wifi-module-shield#.VXo0L-fkn1I).

I have read (and re-read!) this forum several times, and have become more confused each time. Hardware is not an issue, but I am struggling to successfully modify the plugin's Arduino sketch to utilise the ESP-01, as my experience is more in the hardware area.

Rather than the "snippets" that have been posted to date, would it be possible for those more knowledgeable and experienced in things Arduino to post a step by step "how-to" on the modifications required to the sketch to allow the use of the ESP-01? Or better still a new version of the complete sketch to allow "plug 'n play" for Arduino-neophytes like me? :roll:

Thanks in anticipation and regards,

Mclass

Posted on
Mon Jun 29, 2015 9:14 pm
mclass offline
Posts: 315
Joined: May 13, 2015
Location: Melbourne, Australia

Re: ARDUINO plugin discussion

Continuing to find applications for this plugin!

Have successfully implemented digital outputs using Freetronics EtherTen board (UNO compatible)

But the digital and analog inputs have got me bluffed! The change of state and values are appearing in the event log window with debugging turned on. However these are NOT reflected in the Arduino device's "Custom State" window in the device view, nor is this view being updated at regular intervals.

With reference to the attached screen shot, D5 is configured as an output, and operates as expected, including updating-the "Custom States" window when the state is changed by an Action Group command.

Pins A3 and D8 are configured as inputs, but when the value of these inputs is changed, the Custom State window is NOT updated, nor are any triggers recognised. The changed values are appearing correctly in the Event Log, when logging is activated (see screen shot).

Have exhausted all obvious (to me!) options such as reloading plugin, etc, and am now at a total loss :shock:

Any suggestions welcome!
Attachments
Untitled.tiff
Untitled.tiff (188.84 KiB) Viewed 6375 times
Indigo_150630.jpg
Indigo_150630.jpg (41.06 KiB) Viewed 6378 times

Posted on
Mon Jun 29, 2015 9:28 pm
kw123 offline
User avatar
Posts: 8366
Joined: May 12, 2013
Location: Dallas, TX

Re: ARDUINO plugin discussion

will look into it later today or tomorrow

was busy with writing python code for my son's twitter analysis project ... YES at my old age I am still needed!! :P :P :P

Who is online

Users browsing this forum: No registered users and 3 guests