Category Archives: arduino

Using tinyBrd library on Arduino to connect via NRF24L01

Our tinyBrd has very simple and easy to use interface for NRF24L01 radio. This library was bundled with Nettigo tinyBrd Core, add-on for Arduino IDE to program tinyBrd. Now we have extracted it as standalone and can be used on Arduino UNO and other boards.

Changes are minor, since we need to remove name conflict with bundled Radio library. Arduino IDE library manager was taking our Radio library as library for FM chips. So let us introduce RadioNRF24 library. With library name change we have changed main object name so all old examples are valid, just use new object name:

  RadioNRF24.begin(address, 100);

There is no other changes. With UNO You have use different begin form:

  RadioNRF24.begin(address, 100, 8, 7);

On tinyBrd CSN i CE are fixed so there is no need to give them in initalizer. That is not true with UNO, so in former example 8 is CSN pin and 7 i CE pin. Exactly as it is shown on following diagram – how to connect NRF24L01 to Arduino.

Connecting nRF24L01 and Arduino

Connecting nRF24L01 and Arduino

Library is for now available only on GitHub: https://github.com/nettigo/RadioNRF24

We will prepare more easy to use form as .zip file. Also – there are some examples as  gists: https://gist.github.com/netmaniac/dfd7eb4f884d58346480. Remember – as for today library bundled in tinyBd Core is still using  Radio name, so all code on tinyBrd should use Radio.begin and similar. On UNO use RadioNRF24. In future, we will update tinyBrd Core to use RadioNRF24 name.

Arduino YUN – how to get older system images

On Arduino.cc  You can always find and download most recent Arduino YUN system image (firmware).  What to do, if You need older one?

Arduino YUNOlder firmware for Arduino YUN

First, You need to know which firmware You need. Browse all release notes on  GitHub. Knowing which one You need, insert revision number into link replacing XXX:

https://downloads.arduino.cc/openwrtyun/1/YunSysupgradeImage_vXXX.zip

So, if You need 1.4.2 link for download is:

https://downloads.arduino.cc/openwrtyun/1/YunSysupgradeImage_v1.4.2.zip

And for Release 1.3:

https://downloads.arduino.cc/openwrtyun/1/YunSysupgradeImage_v1.3.zip

 

Serial port busy for avrdude on Ubuntu with Arduino Leonardo Eth

Arduino Leonardo Eth

Doing test with new Arduino Leonardo ETH on Ubuntu (14.04) we had problem with programming this board:

avrdude: ser_open(): can't open device "/dev/ttyACM0": Device or resource busy avrdude: ser_send(): write error: Bad file descriptor Problem uploading to board. See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

On Ubuntu (or other distro with ModemManager) ModemManager tries to connect to each new serial port. MM tries if this serial port is GSM modem. This is very convenient for most users, but it keeps serial port open, and Arduino IDE can not communicate with Arduino Leonardo. There is a list of ignored devices by ModemManager, but for now most Arduinos from Arduino.org are not included.

What to do? Just add own rule telling ModemManger to ignore all USB devices from Arduino.org. Open new terminal (Ctrl+Alt+T) and issue command:

sudo echo 'ATTRS{idVendor}=="2a03", ENV{ID_MM_DEVICE_IGNORE}="1"' > /etc/udev/rules.d/77-arduino.rules

echo ‘ATTRS{idVendor}=="2a03", ENV{ID_MM_DEVICE_IGNORE}="1"‘ | sudo tee /etc/udev/rules.d/77-arduino.rules

As noted in comments, there should be other form used, first one won’t work – will not write rule into file, will return Permission denided, thus this update

next You have to reload rules:

sudo udevadm trigger

That’s all.

Debug sketch on Arduino Zero Pro with GDB and OpenOCD

Arduino is simple platform but empowers it’s users to do fantastic projects. People with experience in writing software for bigger computers can get strange feeling when they have no access to debugger. Debugger is tool for tracing program execution – You can examine/modify variables, going through code step by step and many more. In other words it let’s You know why program does not behave as expected. It is very useful tool, especially when You have to deal with more complex programs. But Arduino does not have such tool, only debugging method is to write messages via Serial class.

Arduino Zero Pro for rescue

We have Arduino Zero Pro in our offer. This board has 32-bit ARM Cortex-M0 processor. New feature is interface for debugging sketches on board. You can do it with JTAG/SWD adapter, or just connecting board to PROGRAMMING USB port. This article will show You how to access debugger feature with free and open tools.

Debug in progress

Debug in progress

 

How to start?

Test were done with computer running Linux, but all required software is bundled with Arduino IDE, so this tutorial should work also on Windows and MacOS without any significant changes.

Arduino ORG

It is important to note, that we will need Arduino IDE from Arduino.org not from Arduino.cc. At this moment (Apr/May 2015) only IDE on Arduino.org has support for Arduino Zero Pro.

We need to download and install Arduino IDE 1.7.3 or newer. Next step is to increase number of messages given by IDE during sketch compilation. Open preferences (Ctrl+,) and near  Show verbose option during mark compilation.

For our first debug target we will use Blink. Open it  (menu Files/Examples/01. Basic/Blink), connect Arduino Zero to computer using PROGRAMMING port, in IDE select also Arduino Zero Pro (Programming) and upload sketch to board (Ctrl+U).

OpenOCD

ARM consortium has agreed on communication standard for Cortex-M0 processors. It is called CMSIS (more details about – link) and there is open software supporting this standard.

Let me introduce You – OpenOCD. OpenOCD binary files are bundled with Arduino IDE and You don’t have to install anything more.

Starting OpenOCD

Having our Blink sketch on board, we go to directory where is Arduino IDE and we start OpenOCD using this command:

./hardware/tools/OpenOCD-0.9.0-dev-arduino/bin/openocd -s hardware/tools/OpenOCD-0.9.0-dev-arduino/share/openocd/scripts/ -f hardware/arduino/samd/variants/arduino_zero/openocd_scripts/arduino_zero.cfg

Argument after -s defines folder where are configuration files for OpenOCD, and after -f switch there is configuration file defining Arduino Zero Pro capabilities.Result for running this command should be similar to this:

Open On-Chip Debugger 0.9.0-dev-g1deebff (2015-02-06-13:06)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.sourceforge.net/doc/doxygen/bugs.html
Info : only one transport option; autoselect 'cmsis-dap'
adapter speed: 500 kHz
adapter_nsrst_delay: 100
cortex_m reset_config sysresetreq
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: JTAG Supported
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : CMSIS-DAP: FW Version = 01.1F.0118
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 1 TDO = 1 nTRST = 0 nRESET = 1
Info : DAP_SWJ Sequence (reset: 50+ '1' followed by 0)
Info : CMSIS-DAP: Interface ready
Info : clock speed 500 kHz
Info : IDCODE 0x0bc11477
Info : at91samd21g18.cpu: hardware has 4 breakpoints, 2 watchpoints

GDB

OpenOCD is ready to work. It listens on ports  4444 and 3333. On first port there is telnet server and second one hosts GDB server.

GDB is open source software for debugging programs. It is also bundled with Arduino IDE. It is important to have GDB with support for ARM architecture, so use binaries attached to Arduino IDE.

To proceed we need file with compiled program in  ELF format and with included informations required to properly debug code. Such file is prepared by Arduino IDE during compilation and is stored in temporary directory. To know where this file is we compile Blink again, this time without uploading to board. Just press Ctrl+R and examine output in IDE console window. In one of last lines You will see path and filename with .elf extension. See by Yourself, but note that console window is scrolled to the right, to see this file path:

Where to find ELF file location in Arduino IDE

Where to find ELF file location in Arduino IDE

 

We are ready to run GDB. In folder with Arduino IDE issue command:

./hardware/tools/gcc-arm-none-eabi-4.8.3-2014q1/bin/arm-none-eabi-gdb -d examples/01.Basics/Blink/

Folder given after -d switch is place where GDB can find source files for our program. This is required by GDB to display it later to You when You will step through Your program. After issuing this command You should see GDB command line:

GNU gdb (GNU Tools for ARM Embedded Processors (Arduino build)) 7.6.0.20140228-cvs
Copyright (C) 2013 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later 
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "--host=x86_64-linux-gnu --target=arm-none-eabi".
For bug reporting instructions, please see:
.
(gdb) 

In this article I show You only basic steps to get debugger features, for more detailed info about how to use GDB dig by Yourself. In future we may prepare more detailed info about GBD.

First we have tell GDB where to find file with program and debug information:

(gdb) file /tmp/build4557814640826011475.tmp/Blink.cpp.elf
Reading symbols from /tmp/build4557814640826011475.tmp/Blink.cpp.elf...done.
(gdb) 

Command file is used to supply path and filename to program, just insert here path copied from Arduino IDE few steps earlier.

Now we need to inform GDB where it can find our live program:

(gdb) target remote localhost:3333
Remote debugging using localhost:3333
0x00000000 in ?? ()
(gdb) 

Now we can take control over program execution, examine this GDB session output:

(gdb) monitor reset halt
target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0x21000000 pc: 0x000028b8 msp: 0x20002c08
(gdb) monitor reset init
target state: halted
target halted due to debug-request, current mode: Thread 
xPSR: 0x21000000 pc: 0x000028b8 msp: 0x20002c08
(gdb) l loop
19    // initialize digital pin 13 as an output.
20    pinMode(13, OUTPUT);
21  }
22  
23  // the loop function runs over and over again forever
24  void loop() {
25    digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
26    delay(1000);              // wait for a second
27    digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
28    delay(1000);              // wait for a second
(gdb) b 25
Breakpoint 1 at 0x4120: file Blink.ino, line 25.
(gdb) cont
Continuing.
Note: automatically using hardware breakpoints for read-only addresses.

Breakpoint 1, loop () at Blink.ino:25
25    digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
(gdb) c
Continuing.

Breakpoint 1, loop () at Blink.ino:25
25    digitalWrite(13, HIGH);   // turn the LED on (HIGH is the voltage level)
(gdb) 

Command monitor reset halt sends to our board processor instruction to stop sketch execution, now LED on Arduino stops blinking. monitor reset init resets Arduino CPU to empty state, and it becomes ready to start over.

l loop display loop function code (that is reason why we need tell GDB where are source files). Command b 25 sets breakpoint in line 25 of current source file. cont resumes program execution (well, actually it starts from beginning since we have issued  monitor reset init ). This is reason why after cont, program gets to line 25 and before LED is lit execution is halted. Next c commands allow to run code until it returns to line 25 .

What’s next?

This is simple example to illustrate new possibilities Arduino Zero Pro opens before You. People familiar with GDB are ready now to order Arduino Zero Pro  and start exploring new ways to debug sketches. Others can see on this short video, debugging on Zero Pro is quite easy.

But, since GDB is working nothing does stop us from using some graphical interface for GDB, list of such tools is quite long. We have used DDD (this time You have to install it by Yourself)

DDD during debug session with Arduino Zero Pro

DDD during debug session with Arduino Zero Pro

To use it with Arduino You have to tell DDD where is proper GDB:

ddd --debugger "hardware/tools/gcc-arm-none-eabi-4.8.3-2014q1/bin/arm-none-eabi-gdb -d examples/01.Basics/Blink/"

Ultrasonic sensor comparison: HC-SR04, PING, Maxbotix

For many projects You will need to measure distance, let’s say You are building a robot and You don’t want to have it bouncing on the walls, aren’t You? One of the first ideas to get some orientation in surroundings is to use ultrasonic range sensor. We took three different sensors and do some basic checks to do ultrasonic sensor comparison.  Which one could be best for Your project?

Ultrasonic sensor comparison

Ultrasonic sensor comparison

We did tested: Seeedstudio SEN136B5B, HC-SR04 and MaxBotix MaxSonar EZ1 (MB1010).

How ultrasonic sensor does work? They are built from sound source and receiver – both can be separate devices or single one. Maxbotix has both integrated into one case, while two other sensor have separate sound source and receiver. Sound source emits sound impulse in ultrasonic range (usually 32 kHz) and receivers listens for echo. Knowing how fast sound is in air, from time we get an echo we can calculate how far from sensor object is located.

Continue reading

nRF24L01+ wireless modem

There are many options how to connect Your Arduinos wireless. One of options available is – nRF24L01+. It costs only 6zł (1.5 EUR) per node and it allows you to connect many devices without using a single wire. nRF24L01 uses radio waves (in 2.4 GHz band) to contact with other modules.

nrf24L01+ module

nrf24L01+ module

Modem works on 2.4GHz frequency and has 100m range (at best). You can communicate with different baud rates: 250 kbps, 1 or 2 Mbps. High baud rate allows users even to send video material in 720p resolution (very similar to Youtube). During operation modem uses less power that single LED. During receive power consumption is around 12mA and during transmission 11mA. According to datasheet users can set automatic power saving modes. During this states module consume only 320 µA (when data is waiting for transmission), 26 µA (when there is nothing to send), 0.9 µA (in shutdown).

nRF can operate on voltages between 1.9 and 3.6V. The input pins tolerate the 5V logic, so without any problems this module can be connected to the most popular development boards like Arduino. You don’t have to use any logic level converters when connecting this module to Arduino working in 5V logic. Most models of Arduino (UNO, Mega, Leonardo and more) are working with this logic levels.

Operating bandwidth is divided on 125 channels (separate frequencies). Thanks to this, you can create a network of 125 independently working modems in one place. Every channels has its own address. Well, to be honest it can have up to 6 addresses. This addresses are numbers and they represent specific device connected to network which will receive data. Length of the address can be from 3 to 5 bytes. This gives us the addresses from 24 to 40 bits. With the lowest value of the address it is 17 million combinations. Longer address value can be used as 5 letter names (5 chars at 8 bits give us 40 bits in total).

nRF24L01 automatically creates data packets. You are only sending what you want to the specified address. Modem creates a data packet, which is protected from errors with a CRC. When there’s a problem with sending packet, device automatically will try to send it one more time. If sending is successful, receiving module automatically sends a confirmation to the transmitting module.

nRF24L01 uses SPI interface to communicate with the MCU. It uses 5 wires.

Pinout

nRF24L01 module is being sold on breakout board with build in antenna. The pcb only requires a connection with the development board or MCU. Size of the whole module is very small (1.55×2.9cm). From the bottom you can see two rows of communication pins.

nrf24l01+ pinout

nrf24l01+ pinout

As it was written before, module communicates with the controller via SPI interface.

Signals:

  • VCC – power – from 1.9 up to 3.3 V
  • GND – ground
  • MOSI – SPI serial data input
  • MISO – SPI serial data output
  • SCK – SPI clock
  • CSN – low state on this pin indicates that with this module the controller wants to communicate.
  • CE – signal activating receiving and transmitting. In receive mode, the high state indicates that he wants to receive. In transmit mode, pulse sends one packet of data.
  • IRQ – interrupt output. It does a low state pulse when data is waiting to receive, or when the data was properly sent.

 

Logging and converting float values to Strings on Arduino

In Arduino You can use String class, which can be used to create log messages. Often You need to add some numeric values in this messages.

It can be simple as that code:

  String cmd = "curl --data \"key="+key;
  for (int i=0;i<ARRAY_SIZE;i++) {
    cmd = cmd + "&field"+ (i+1) + "=" + value[i];
  }
  cmd = cmd + "\" http://api.thingspeak.com/update";

You may recognize that code from our previous work with Arduino YUN. After few days I have noticed one thing. All float values are converted to string with only two decimal places. For small values it can have an impact. We measure voltage on MQ5 and MQ9 sensor, and it is quite low (0.1V). Using internal 2.56 V reference will yield with ADC resolution 2.56/1023 = 0.00250. If float values are rounded to 2 decimal places You will lose some information – value will be rounded (or truncated I’m not sure if it will be floored or rounded) to two decimal points and ThingSpeak will not log accurate result.

There are two solutions – first is to log analogRead result directly (without converting it to voltage). That way You will log integers (results of analogRead calls). But this method will produce data which are hard to compare. If You change ADC reference voltage You can not compare (at least directly) new results with some older data.

Arduino: convert float to strings done better way

Second solution is to make floats convert to strings with more decimal places. You can do this directly with String(NUMBER, SCALE);, so String(3.141592,5) will create string with 3 decimal places: "3.14159". How code sending data to ThingSpeak will look after changes?

  String cmd;
  String tmp;
  cmd = "curl --data \"key=" + key;
  for (int i=0;i<ARRAY_SIZE;i++) {
    tmp = String(value[i],5);
    cmd = cmd + "&field"+(i+1) + "=" + tmp;
  }
  cmd = cmd + "\" http://api.thingspeak.com/update";

Project: Using Arduino YUN to control things remotely

Arduino YUN is very interesting product. Mixing OpenWRT and Arduino in one board is effective. OpenWRT does things related to WiFi connectivity, Arduino YUN does interact with physical world, and standard Arduino library makes connecting both parts easy. Now we need some simple project to demonstrate how You can control things remotely with Arduino YUN

Arduino YUN allow You control physical elements with smartphone or other browser.

Arduino YUN allow You control physical elements with smartphone or other browser.

To demonstrate how easy You can build something using this components we will use Arduino YUN, connect to it with browser (can be in smartphone) and You control some LED using webpage. This project was shown on Robomaticon 2014 in Warsaw to make YUN more understandable. Robomaticon is event for robotics and electronics enthusiasts, so YUN was acting as open hot spot, anybody could connect to it and using http://1.1.1.1 control LEDs. Why numerical address instead of some more userfriendly name distributed via DHCP to clients? Not all phones were accepting .local domain extension, so since whole setup was not connected to Internet we used this easy to enter public address.

Continue reading