Tuesday, June 18, 2013

Got working Arduino Pro Mini for Home Automation work - 1

For my home automation projects, I have been doing lots of R&D on various factors like:

  • Low cost MCU and MCU related board (commercially available)
  • Low power consumption in deep sleep (may not be the best , but reasonable low current consumption, so that MCU can withstand power outages)
    • Lots of cheap boards are there. For the time being I have chosen following Arduino boards
  • Cheap availability of wireless connectivity solutions
    • Bluetooth 4.0
      • In coming future, I would be using BLE-Soc chips likeNordic nrf51822 and TI's cc2540 & cc2541 -- as we have cheap assembled boards at various internet shops (like alibaba, dealsextreme, ebay, etc) .These boards typically come for 6 to 12$ 
    • Zigbee
      • I tried initially, but their board's cost is high very high  even at above shops and difficult solder because of QFN-soldering, wireless antenna's design, etc.
    • Proprietary wireless protocol
      • I found Nordic radio transceiver NRF24L01+ at 2.4GHz spectrum at following site for around 1$ per board
  • Free compiler, open source libraries & knowledge base in net.  If not free some trial based compiler for doing R&D (like cc254x chips).
Arduino fits the bill, but their overall solution costs more than 15 to 20$ before an year back (with my research at that point of time). So I dropped Arduino idea and looking for other solutions. Recently I casually browsed Alibaba site and found that I can get a reasonably powered Ardunio for less than 5$ and wireless connectivity for another 1$. So brought these items and finally started doing first helloworld on this boards. 

Here are pictures for  this board
This is for connecting this board with typically USB-to-Serial-Dongle(Prolific based) and correpsonding RS232 TTL convertor



This is showing minimal connections needed for powering and burning the program to Arduino. These yellow wires do connect to above USB-RS232-Dongle (RX & TX appropriately)


Board view from top view with an empty board on side


Connections from Arduino Board to RS232

Please ensure that you connect serial port cross-connection like following:

  • Board-Longer-Side RXI to RS232 TX
  • Board-Longer-Side TXD to RS232 RX

Arduino IDE Options

  • Select proper Serial port
  • Select  board as either of these boards. For my both voltages have worked out
    • 'Arduino Prop or Pro Mini (5V, 16MHz) w/ Atmega328'
    • 'Arduino Prop or Pro Mini (3.3 V, 8MHz) w/ Atmega328'
  • Select Programmer as 'Arduino as ISP'

Actions need to be taken while pressing Upload from IDE

  • As current setup does not use DTR/RTS on RS232 and only uses RX/TX (from USB to Rs232 converter), we need to press reset button just before the flashing (i.e., when console logs shows lines something like following in verbose-burning-mode-preferences) 
 Using Port                    : /dev/ttyUSB0
         Using Programmer              : arduino
         Overriding Baud Rate          : 57600
avrdude: Send: 0 [30]   [20] 
avrdude: Send: 0 [30]   [20] 
avrdude: Send: 0 [30]   [20] 

Problems/Issues faced

Serial Port not detected in Linux

Run as root, then the Arduino IDE recognizes the Serial port . Select appropriate serial port from output of 'dmesg' command in linux.

Flashing Issues

  • After selecting the board as 'Arduino Prop or Pro Mini (5V, 16MHz) w/ Atmega328' and correct serial port. After trying to flash image to board has given following error messages.

Binary sketch size: 2,654 bytes (of a 30,720 byte maximum)avrdude: stk500_recv(): programmer is not responding

  • Now enable the verbose upload option via File -- Preference --'Show verbose output during'  = 'burning' .
    • After this step , I got following messages
Binary sketch size: 2,654 bytes (of a 30,720 byte maximum)
**/arduino-1.0.5/hardware/tools/avrdude -C/opt/arduino-1.0.5/hardware/tools/avrdude.conf -v -v -v -v -patmega328p -carduino -P/dev/ttyUSB0 -b57600 -D -Uflash:w:/tmp/build5308589158935848821.tmp/ASCIITable.cpp.hex:i 

avrdude: Version 5.11, compiled on Sep  9 2011 at 16:00:41
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "**/arduino-1.0.5/hardware/tools/avrdude.conf"
         User configuration file is "***/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/ttyUSB0
         Using Programmer              : arduino
         Overriding Baud Rate          : 57600
avrdude: Send: 0 [30]   [20] 
avrdude: Send: 0 [30]   [20] 
avrdude: Send: 0 [30]   [20] 
avrdude: ser_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding

avrdude done.  Thank you.
    • Another error which slightly different at end
         Using Port                    : /dev/ttyUSB0
         Using Programmer              : arduino
         Overriding Baud Rate          : 57600
avrdude: Send: 0 [30]   [20] 
avrdude: Send: 0 [30]   [20] 
avrdude: Send: 0 [30]   [20] 
avrdude: Recv: . [00] 
avrdude: stk500_getsync(): not in sync: resp=0x00

avrdude done.  Thank you.
  • As this not typical USB based driver (which is available in little costlier Arduino boards) and I am using hard coded RS232 wiring, I tried to flash the image by pressing the reset button on the board. This made the flashing to occur successfully. Actually if we reset the board, MCU waits for flashing-data from RX/TX pins few seconds. If no  recognized flashing data comes to RX/TX pins, MCU will boot with previous programm that is there in flash. One has to find appropriate time to press reset button -- this timing can be assisted by putting verbose-burning-option.
  • So successful flash sequence is shown as:
Binary sketch size: 2,654 bytes (of a 30,720 byte maximum)
***/arduino-1.0.5/hardware/tools/avrdude -C***/arduino-1.0.5/hardware/tools/avrdude.conf -v -v -v -v -patmega328p -carduino -P/dev/ttyUSB0 -b57600 -D -Uflash:w:/tmp/build5308589158935848821.tmp/ASCIITable.cpp.hex:i 

avrdude: Version 5.11, compiled on Sep  9 2011 at 16:00:41
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "***/arduino-1.0.5/hardware/tools/avrdude.conf"
         User configuration file is "***/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/ttyUSB0
         Using Programmer              : arduino
         Overriding Baud Rate          : 57600
avrdude: Send: 0 [30]   [20] 
avrdude: Send: 0 [30]   [20] 
avrdude: Send: 0 [30]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [10] 
         AVR Part                      : ATMEGA328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  3600  3600 0xff 0xff
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : Arduino
         Description     : Arduino
avrdude: Send: A [41] . [80]   [20] 
.....
         Hardware Version: 2
         Firmware Version: 1.16
avrdude: Send: A [41] . [84]   [20] 
..............
avrdude: Recv: . [10] 
         Vtarget         : 0.0 V
         Varef           : 0.0 V
         Oscillator      : Off
         SCK period      : 0.1 us

avrdude: Send: A [41] . [81]   [20] 
.......
avrdude: Recv: . [14] 
avrdude: Recv: . [10] 
avrdude: AVR device initialized and ready to accept instructions

Reading | avrdude: Send: u [75]   [20] 
avrdude: Recv: . [14] . [1e] . [95] . [0f] . [10] 
################################################## | 100% 0.00s

avrdude: Device signature = 0x1e950f
.................
.................
avrdude: Recv: . [10] 
###avrdude: Send: U [55] . [00] . [05]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [10] 
avrdude: Send: t [74] . [00] ^ [5e] F [46]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [ee] . [0f] . [ff] . [1f] . [05] . [90] . [f4] . [91] . [e0] - [2d] . [09] . [94] . [f8] . [94] . [ff] . [cf] A [41] S [53] C [43] I [49] I [49]   [20] T [54] a [61] b [62] l [6c] e [65]   [20] ~ [7e]   [20] C [43] h [68] a [61] r [72] a [61] c [63] t [74] e [65] r [72]   [20] M [4d] a [61] p [70] . [00] , [2c]   [20] d [64] e [65] c [63] : [3a]   [20] . [00] , [2c]   [20] h [68] e [65] x [78] : [3a]   [20] . [00] , [2c]   [20] o [6f] c [63] t [74] : [3a]   [20] . [00] , [2c]   [20] b [62] i [69] n [6e] : [3a]   [20] . [00] ! [21] . [00] . [00] . [00] . [00] . [00] . [95] . [03] . [c8] . [00] + [2b] . [03] \ [5c] . [03] < [3c] . [03] . [85] . [03] 
avrdude: Recv: . [10] 
## | 100% 0.59s

avrdude: verifying ...
avrdude: 2654 bytes of flash verified
avrdude: Send: Q [51]   [20] 
avrdude: Recv: . [14] 
avrdude: Recv: . [10] 

avrdude done.  Thank you.




So with minimal booting is done with this board, next step is to connect Nordic Wireless chips and try wireless connectivity.