Pi to Moteino Serial [vs I2C]

Started by loseymark, May 12, 2016, 12:43:01 PM

loseymark

I have a moteinoUSB connected to a Raspberry PI TX to RX and RX to TX and ground to ground. I am running a weather node sketch with the SI7021 logic removed and I've added a handleSerialInput() method similar to what is in the mightyhat sketch. The Moteino USB is connected and powered through a USB connection to my MAC running serial monitor.

On both the PI and the serial monitor, I successfully read DEBUGln() output and the gateway sees the moteino.

I can not send data from either the PI or the serial monitor.

Any suggestions on what I might check?

Warning I'm a PI enthusiast with little to no electronics training or experience. I have several weathershield nodes running and a functioning gateway environment.

Felix

Sounds like the MoteinoUSB's serial port is connected in 2 places, you can only connect that serial to 1 host, either the PI or your MAC. The pins are broken out on the side header, but if you're plugged into USB you should not use those pins, since the USB already emulates the atmega328 serial through the USB host.

loseymark

There's a youtube post showing this setup, but he was using a regular moteino with an FTDI adapter instead of moteino usb. I'll try connecting the moteinousb to the pi via USB. Thanks for the reply.

loseymark

Tried moteinoUSB connection to PI via USB - PI doesn't receive serial from moteino. Tried pin connections between moteino and PI. PI receives from moteino, but PI can't transmit to moteino - same as before.

I'm going to try PI to PI with pin connections, and also a simple serial connection and sketch to light up an LED on Moteino via commands from the PI.

Felix

If It's a MoteinoUSB just plug it over the Pi's USB, that will give you a new serial port like /dev/ttyUSBx
Then you have to ensure the baud rate is the same on both ends and it should just work. Use minicom on the pi to send data to your Moteino, and see what's coming back.

loseymark

I needed to do logic level shifting to use serial on the pins. I decided to go with I2C. I have it working although it's error prone - IOError 5. There may also be a conflict with the serial traffic. It works OK with retry logic.

I'm using the PI to read my Garage Door status from my existing sensors. I want to add other PI "sensors" like an SMS interface to my home security system status.

My idea is to have one PI with several Moteino USBs, one per sensor. I2C works pretty well for this because I can have the PI master communicate with several Moteino slaves and this will keep the logic a lot cleaner.

I was considering having just one Moteino, but then I would have to change the address when sending to the gateway and there would be a lot of extra code to handle multiple "sensors".

Felix

Cool, I never tried i2c as comm, mainly because I think the "baud rate" would be much less. But whatever works if it suits your needs. There's not a rule that's set in stone, serial usually is a very typical comm interface and very easy to use.

steveww

I run the Moteino as a slave I2C device and my Pi talks to it just fine this way.
The code is pretty simple to implement on the Arduino and you can use regular I2C get/set commands to pass the data.

I will post the code to my github in the near future...


Felix

Thanks!
A side thought - not having used i2c extensively, I wonder if there will ever be a conflict of address with other devices.

loseymark

After working with I2C for a while, I decided to give serial with moteinoUSB another try.

With I2c whenever the raspberry pi i2c interface was stopped, I had to completely unplug the moteinos to restart I2C on the slaves. I also had to implement retry logic because it took up to 10 or more retries to get a successful response back to the raspberry pi. I didn't have any issues with conflicts among multiple slaves. That part worked well.

I discovered that I wasn't formatting the messages correctly (used printf instead of sprintf). I also had an issue using Pyro - python remote objects. Pyro is multi threaded so I have to connect and disconnect serial in each Pyro event or else the main thread grabs the serial port and subsequent threads won't send.

I now have my garage doors, my security system, and a slew of RF controlled outlets on the gateway dashboard running through a single moteinoUSB controlled programatically from a dedicated raspberry pi that I call pimote.

Since my surveilance cameras are built using raspberry pis, I can now turn the cameras on and off remotely and securely from the gateway dashboard. I customized the gateway adding my own page to turn outlets on and off.

Felix

Quote from: loseymark on July 24, 2016, 12:48:17 PM
I now have my garage doors, my security system, and a slew of RF controlled outlets on the gateway dashboard running through a single moteinoUSB controlled programatically from a dedicated raspberry pi that I call pimote.

Since my surveilance cameras are built using raspberry pis, I can now turn the cameras on and off remotely and securely from the gateway dashboard. I customized the gateway adding my own page to turn outlets on and off.

Good to know, so far serial has been very stable and no major issues.
I'd love to see more of how you've integrated everything, that's of course if you feel like sharing. Also nice to hear that more and more folks are customizing the stock gateway app to add their own things to it.

loseymark

I don't mind sharing. Should I post something to the gateway thread or the projects thread?

I'm not a seasoned developer, so I don't have anything on git hub.

Felix

Since this is pi-gateway centered i would keep it in this forum, there are others who've done the same. The Projects forum is more for general purpose/moteino/other type stuff.