Galaxynik
Posts: 43
Joined: Mon Jan 02, 2012 2:55 pm

Looking for some advice about which arduino to choose

Sun Sep 29, 2013 10:15 pm

Hi
I am looking to interface one of my Pi's to an arduino, hopefully they will communicate by usb(serial) but having looked at arduinos there seems to be a multitude of them if you include clones etc. I dont know very much about them and would like to keep it as cheap as possible,

Currently the Pi has an 8 bus 1 wire board on top and a rtc on top of that all comunicationg via i2c - mainly measuring temperature but also 2 single switch outputs and 2 dual switch outputs (FOC as samples from maxim (thank you maxim). I also have some homeeasy 433Mz switched sockets. What i want to do is to bring all this together so I can control the lights and standby power and 1wire switches from my phone - via a weboage or the homeeasy remote (it has 4 groups of 4 buttons + a switch all function).

The jobs the arduino needs to do..
transmit 433Mhz signals to control the homeeasy sockets (I have the transmitter)
receive 433Mhz from the homeasy remote to be passed back to the pi to control the 1wire switches (I have the reciever)
control an lcd display
probably monitor a couple of analogue sensors and pass the info back to the pi (where the data will be stored, graphed and published on a webserver)
Maybe control some leds using PWM (not sure about this yet)

At the moment most of the Pi side software is written in PERL with some graph generating functions as bash scripts. I have some perl/cgi-webpages which allow me to switch on leds via the 1 wire as a proof of concept (much to my 11 year olds amazement - he can turn the leds on from school or his mums house using his phone LOL)

Am I asking too much from the arduino? would it have enough memory to write a 'sketch' checking on the serial port for commands from the PI, the Rx for commands from the Homeeasy remote, most of the processing would be done on the pi I reckon. If is suitable which arduani/clone would be suitable??

Ta

btidey
Posts: 1636
Joined: Sun Feb 17, 2013 6:51 pm

Re: Looking for some advice about which arduino to choose

Mon Sep 30, 2013 8:07 am

The low level interfacing as described sounds very do-able using an arduino. You probably want to make good use of interrupts to do quite a bit of the i/o and leave the foreground task to communicating with the Pi and running the display. I don't think there will be much problem with either program memory or data memory from what you describe.

As to the choice of arduino there is quite a large variety now. It would be best to use one based on 328p or 32u4 chips as they have a decent amount of memory and performance whilst remaining economical. The 32u4 has a little bit more data memory but what is attractive for general use is that the usb interface is much more flexible and can emulate many usb devices other than pure serial comms.

The form factor will be one of the main determining factors here. If you don't intend to use any extra arduino shields then you could use one of the mini, micro or nano varieties which can be got very cheaply and and are very compact. In the past I have used 328p based nanos but my personal favourite at the moment is the 32u4 based Pro Micro which is a small form factor Leonardo like device originally designed by Sparkfun https://www.sparkfun.com/products/11098 and clones of this are available on eBay from about UKP 8.

pontis
Posts: 3
Joined: Mon Sep 09, 2013 7:30 pm

Re: Looking for some advice about which arduino to choose

Mon Sep 30, 2013 7:15 pm

You can look at the JeeNodes made by Jean-Claude Wippler - http://jeelabs.net/projects/hardware/wiki.
Jeenode is basically Atmel controller (same as in Arduino) coupled with the 433/868/915 MHz radio transceiver (RFM12B).
He does have an Arduino library for working with the radio, although it uses its own protocol. But it would probably be a good start for you to get it to work with the RC stuff that you are referring to.
The JeeNodes are small and not expensive - I think cheaper than Arduinos and are built to be used as wireless sensors etc. The library has also been very well optimized for low power applications and provides ways of going in low power "sleep" modes. I think he has a node running on a CR2032 battery for couple years now that "blips" once a minute, that is sends out a beacon signal :)
I use these in a couple of projects that I built and am about to build.

Galaxynik
Posts: 43
Joined: Mon Jan 02, 2012 2:55 pm

Re: Looking for some advice about which arduino to choose

Tue Oct 01, 2013 6:25 pm

Thank you both for your detailed responses :)
Its an awful long time since I've written any code that runs under interupts (remember the amstrad pcw :o ) so that may be a challenge - will read up a bit about that. I was hoping initially just to run the main loop, do the conversions for analogue sensors and store the values until requested from the pi, check for the remote activation and check for any serial commands from the pi (the pi will request data already stored from the analogue conversions - I dont envisage these to be time critical, send message to be output on he lcd or send a code via the 433 Mhz tx.

I think I will look at getting a 'Arduino compatible Pro Micro' which looks good, I'm not overly fussed about the form factor, just want to run it a reasonable distance from the pi (using usb cable so that I can move the aerial for the 433MHz transmitter around and to ensure that whatever I bought would be able to do the job.

Had a look at the JEEnode usb but it seems a little expensive at 32 euros compared to £9 on ebay for an Arduino compatible Pro Micro.

btidey
Posts: 1636
Joined: Sun Feb 17, 2013 6:51 pm

Re: Looking for some advice about which arduino to choose

Tue Oct 01, 2013 9:35 pm

If you can separate out the functions and they don't have to overlap or be time sensitive then you could do it all from a foreground loop.

Using interrupts, on the Arduino is not that hard, however. The libraries support attaching service routines very easily and it is all still done in c code. There are lots of examples around to base stuff on and plenty of help in the various forums. The main concept to get right is the common data structures between the foreground loop and the various service routines. The big benefit is that each piece of i/o is neatly isolated and can be developed independently even in separate libraries. Plus everything can happen effectively carry on in parallel. So for example, if the foreground wants to send a 433MHz message then it just posts the message into the transmit structure. The TX interrupt service routine is then responsible for transmitting the message 1 bit at a time and getting the timing right. As it can be desirable to repeat the TX message several times to ensure it is received OK that might take several seconds. I use both RX and TX simultaneously and that would be impossible to do in a foreground loop as you have no control over when RX messages can arrive. With interrupts the foreground can be getting on keeping everything else going and means things like responding to Pi commands and updating the display don't suffer from any lags.

pontis
Posts: 3
Joined: Mon Sep 09, 2013 7:30 pm

Re: Looking for some advice about which arduino to choose

Wed Oct 02, 2013 3:15 am

Looks like you found the most expensive part that Jeelabs has - the USB one :)
I was more thinking of a regular Jeenode which has a UART (serial) which is hooked to Pi's UART. I think iis about 17eur and has a 433Mhz transceiver so you can send/receive your homeasy signals. You could probably even build your own remote using say Jeenode micro.
But since you seem to have receiver and transmitter, you might be better off with the Micro clone, I am waiting for a couple bought on ebay from China myself.
In any case, the library that is used for Jeenodes might be something you can use for communication with your homeasy devices unless there is already something out there for arduino that talks whatever protocol is used by those.

Keep us posted on your progress!

Galaxynik
Posts: 43
Joined: Mon Jan 02, 2012 2:55 pm

Re: Looking for some advice about which arduino to choose

Fri Oct 04, 2013 3:24 pm

hi btidey I have just bought one of the pro micro boards you recomended :-) wont be able to get much done for a couple of days but a couple of questions spring to mind, are you programming it on a windows machine or using the arduino ide on the Pi? if on the pi how do you get the the ide to recognise the board?

Galaxynik
Posts: 43
Joined: Mon Jan 02, 2012 2:55 pm

Re: Looking for some advice about which arduino to choose

Fri Oct 04, 2013 6:33 pm

When I got in the board had arrived and despite being snowed under I couldn't resist having a 30 min play :D - I have never used an arduino before and I'm very much a linux noob :D
I installed tightvnc on the Pi and on my windows pc since I tend to run both my pi's headless, and the arduino ide on the Pi - all that went smoothly enough - although the responsiveness of the arduino ide over the tight vnc connection is poor ;)

So first problem - no compatible board to select, so I had a look on hobbycomponents website and sure enough there is a link to sparkfun website with some stuff to download and extract ... for windows :x . So I downloaded and had a look at it, ummm all text stuff so I guess it will be the same for linux but where to put it all?????. About 10 mins of searching for the correct directory found the /usr/share/arduino/... directory tree and some of the files were duplicated there ( I should have done .. "find / -name boards.txt " would have saved 10 minutes of my life.

I had look at the structure of the boards file and decided to copy in the section for the promicro (its the only board I have - so I could probably could just replace the file), restarted arduino ide and lo and behold I could select the board . . . ah ha progress, had another search around sparkfuns website and found an example sketch for their pro-micro - I copied that in and tried to compile it. Got an error about pins-arduino.h missing. Had another look in the zip file and sure enough in the variants folder I found it, I went back to the Pi and had a look at the structure of the variants directory and guessed that it need the whole 'promicro' subdirectory copying in there which I did. Whilst doing that I looked at the bootloader section which ahd someething about an improved 'caterina' bootloader but it looks like that is buildable for windows only so I left that . Drivers subdirectory was full of *.inf files which I assumed was windows so I ignored that too. Examining the Cores/arduino subdirectory I found some files which already exist in the same directory on the pi so I left those for the time being.

Without much optimism I compiled the sketch again and that completed ok so I uploaded it ... works fine - been flashing the tx and rx serial leds at me and been sending 'Hello world well done nik' to the pi for the last hour now so I was quite pleased :D :D :D

Now what to do with the 'cores' subdirectory ??? any ideas you arduino gurus :D

btidey
Posts: 1636
Joined: Sun Feb 17, 2013 6:51 pm

Re: Looking for some advice about which arduino to choose

Sat Oct 05, 2013 6:57 am

Sounds like you progressed to a working environment pretty quickly.

I use pi arduino ide with vnc like you. It is a little slow on first compile but still fairly usable. I tend to do source creation and major edits on PC.

The boards.txt is the key to how board is treated as you found for the uploader. It also controls what core library subfolder to use (build.core) and which variant sub folder (build.variant) to use during builds. I stuck with defaults as some people commented on problems with sparkfun versions and later ide versions. I may do a diff to see what the changes are but I haven't noticed any problems.

Actually I think I probably used the Leonardo ones as I think I selected that as the board type rather than the specific Sparkfun one. I am away from my dev env at the moment but will check when I'm back.

Galaxynik
Posts: 43
Joined: Mon Jan 02, 2012 2:55 pm

Re: Looking for some advice about which arduino to choose

Sat Oct 05, 2013 4:12 pm

hmmm I am sure I tried with leonardo first but sketch didnt appear to upload, there isnt much difference between the 2 sections - unfortunately I dont really know what each section does

the differences ... (apart from the names .. :) )
promicro16.bootloader.file=Caterina-promicro16.hex
leonardo.bootloader.file=Caterina-Leonardo.hex

leonardo.build.pid=0x8036
promicro16.build.pid=0x9206

leonardo.build.vid=0x2341
promicro16.build.vid=0x1B4F

leonardo.build.variant=leonardo
promicro16.build.variant=promicro

anybody shed any light on the entries in the boards txt or do we just use them - as I said I'm a complete arduino Noob

might give Leonardo another try :P

btidey
Posts: 1636
Joined: Sun Feb 17, 2013 6:51 pm

Re: Looking for some advice about which arduino to choose

Sun Oct 06, 2013 6:20 am

The vid and pid are the USB identifiers which are used in a Windows environment which I think is why Sparkfun has different Windows drivers. This should not matter in Linux.

http://www.akafugu.jp/posts/blog/2012_0 ... -Leonardo/

btidey
Posts: 1636
Joined: Sun Feb 17, 2013 6:51 pm

Re: Looking for some advice about which arduino to choose

Mon Oct 07, 2013 9:33 am

I checked and I am using just the standard Leonardo board to upload from the Raspberry IDE to the Pro Micro and it worked fine.

However, the Pro Micros I am using were eBay £5 clones and when I check the PID and VID they register when plugging into Windows then they are VID 2341 and PID 8036 which are Leonardo originals. This implies they are loaded with the standard Leonardo bootloader and not the Sparkfun variant. In principle, this shouldn't make any difference when running from the Raspberry Linux environment.

Looking at differences between the original Caterina bootloader and the Sparkfun version, there is some code optimisation in the Sparkfun version particularly in the initialisation and reset timeouts are a bit different but the main code is the same. The USB identities are set in the Make file and that is what makes them different for the Sparkfun version.

The Sparkfun and Leonardo variants folders seem to be identical. The cores folder differs in a few files but the differences look pretty minor, e.g. allowing a 3,3V 8MHz version.

I have had some boards arrive with no bootloader. These were nanos not micros. The method I use to program or update a new bootloader is to set up the IDE to use the Gertboard style Raspberry Pi SPI method which then appears as an option in the IDE. To avoid interface hassles I then run the Arduino at 3.3V by disconnecting the USB and connecting 3.3V supply to Arduino Vcc (+5v). This means I can then directly connect the SPI pins and reset pins between the Raspberry Pi. I then select board type, programmer type and run the and burn the bootloader from the IDE. OK the Arduino is running at 16MHz at 3.3V which is overclocking it a bit, but I have never had difficulties with this.

Galaxynik
Posts: 43
Joined: Mon Jan 02, 2012 2:55 pm

Re: Looking for some advice about which arduino to choose

Tue Oct 08, 2013 6:09 pm

Thanks for your detailed answer.

I read about the problems with the sparkfun board but they seem to be on arduino versions 3 and above mine is 1.01 - I wonder is there a later version or the source that i can compile?

I had a go uploading using the leonardo board and it worked so I'm not sure what happened the first time. I am getting some odd behaviour - at the moment I am playing around getting serial to work reliably which it does when its working :D sometimes though it seems to find ACM0 as the serial port other times it wants to use ACM1 !! - this is in the arduino ide - I cant work out a pattern to this behaviour although it usually happens after I have uploaded a sketch and I try and open serial monitor - restarting the ide invariably sorts it but its a little frustrating as the arduino ide is painfully slow over tightvnc but I would rather keep in all in the pi.

I'm sure I have read of a command line utility to compile and upload the .ino file - I am going to investigate that I think ....

BTW interesting link about PID and VID thnks

Galaxynik
Posts: 43
Joined: Mon Jan 02, 2012 2:55 pm

Re: Looking for some advice about which arduino to choose

Tue Oct 08, 2013 7:09 pm

well that was quick - installed pip, and picocom and then asked pip to install ino - worked like a dream - fast command line build and upload - no more tightvnc :D I know the pi has a lovely graphics chip which is not being used but its low cost and I cant afford a monitor ( or the space) atm lol

btidey
Posts: 1636
Joined: Sun Feb 17, 2013 6:51 pm

Re: Looking for some advice about which arduino to choose

Wed Oct 09, 2013 12:23 pm

Yes, the ino tool works well. For command line usage there is also the Tim Marston makefile approach which I like.

http://ed.am/dev/make/arduino-mk

Return to “Automation, sensing and robotics”