Archive for the ‘Arduino’ Category

Arduino 18 and Sanguino

August 17, 2010

Today I upgraded to Arduino 18 and none of projects were compiling when I was using a sanguino board. I kept getting this error:

/Applications/Arduino.app/Contents/Resources/Java/hardware/tools/
avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/lib/avr5/crtm644p.o: (.init9+0x0): undefined reference to `main'

The sanguino folder does not include the main.cpp file. Instead it includes an identical file called main.cxx. The easiest way to fix this problem is to copy the file and rename the new copy to main.cpp.

I added a space after the .../tools/ in the path above so that the code would look better on the page.

Arduino development with command-line tools

July 2, 2009

You may find that after your Arduino program grows to be over 1000 lines of C code that the Arduino IDE becomes increasing more annoying to use. Well, you can use TextMate, but first you need to set yourself up for command line programming. There are some instructions on the Arduino site for this, but it is a bit out of date. Specifically, the Makefile that they recommend simply does not work. (more…)

avr on mac

June 6, 2009

  1. install mac ports
  2. sudo port install avr-binutils (more…)

Battery level indicator with Arduino analog pin

April 13, 2009

The Arduino mini pro (8MHz) operates at 3.3V and has a 10-bit ADC, i.e., a read on an analog pin can return a value from 0 to 1023. Each value corresponds to 3.3/1024 volts or 3.22 mV. If you’re running Arduino on a battery, then you would want to get an idea of the remaining level of the battery. One way to do this, is to use a voltage divider (you don’t want the voltage input to the analog pin to be greater than 3.3 V, hence the need for the divider) to provide about half of the VCC as input to the analog pin. I use a 3.6V battery, and based on a voltage divider with two 1.2KΩ resistors, the voltage associated with each of the 1024 point values is 3.27 mV. This value can then be used to get a reasonably accurate estimate of the current battery voltage level. For instance, if the value of the analog pin is 544, then 544*0.00327*2 will give you the current battery level.

GM862, STAT_LED

March 21, 2009

GM862 STAT_LEDIf you’re struggling with how to connect the STAT_LED pin of the GM862 Basic 50 pin evaluation board to Arduino, so that it shows the network activity, then look no further. I found the  circuit diagram in an out of date Telit document. Click on the thumbnail to see what to do.

How to debug with Arduino

March 17, 2009

If you need to use the hardware UART of Arduino to control some other module, e.g., the Telit GM862, you may wonder how you can use the hardware UART and use Serial print for your debugging. Well you cannot. Your options are to use Software Serial. But then you should not use software serial for communicating with GM862. There are too many issues, especially if you plan to read from GM862. The default SoftwareSerial is not interrupt based and hence you may lose input. The NewSoftSerial does not support 8MHz systems, so that means you wont be able to use it with Arduino Mini Pro 8MHz. In the past I had used hardware serial for debugging and software serial for communicating with GM862. But given the issues that I just mentioned this was not a satisfactory solution.

Matthew Elias, suggested that I use a second USB TTL for debugging. This is a brilliant solution. It allows me to use hardware UART for communication with GM862 and the out of the box SoftwareSerial for debugging. Here is what you need to do:

  1. You need two USB to TTL adapters
  2. On Arduino, use two digital pins (e.g., pins 10 for RX and 11 for TX for software serial).
  3. Connect the 1st adapter to Arduino and use that to Upload your program to the board. You’ll need to add a switch to the TX line of the USB adapter. The switch must be on when you want to upload a program to Arduino, and you must turn it off when you want to run/debug the program. If you don’t add a switch then the USB voltage will interfere with the device that you’re managing, e.g., GM862.
  4. Connect the 2nd adapter with three wires to the Arduino: (a) connect adapter’s TX pin to Arduino pin 10 (software serial RX) ; (b) connect  adapter’s RX pin to Arduino pin 11 (software serial TX); (c) connect adapter’s GND pin to Arduino’s GND pin.
  5. Open the Terminal application on the Mac (or Hyper-Terminal on PC) and connect to the second USB port (due to the second adapter). 

Now you can use the Terminal application for IO with SoftwareSerial. Here is a simple program to test this setup (note that on the Mac, you need to use 2400 baud rate for the SoftwareSerial and for when you connect to the USB port via Terminal).

#include <SoftwareSerial.h>

int rxPin = 10;
int txPin = 11;

// set up a new serial port
SoftwareSerial debug = SoftwareSerial(rxPin, txPin);

void setup() {
  pinMode(rxPin, INPUT);
  pinMode(txPin, OUTPUT);

  Serial.begin(4800);
  debug.begin(2400);

  debug.println("SoftwareSerial...");

  Serial.println("hardware UART");
}

void loop() {
  int c;
  char cmd;
   if ((c = debug.read()) != -1) {
     Serial.println("I'm here");
     cmd = char(c);
     debug.println(cmd);
     if (cmd == 'a') {
       debug.println("A");
     } else if (cmd == 'b') {
       debug.println("B");
     }
   }
}

From the Terminal you can type ‘a’ and the main loop will print ‘A’ back at the Terminal. All IO from hardware UART will be directed to GM862 (or whatever module that you need to communicate with).

Thank you Matt for providing this solution.

USB Adapter for 3.3V & 5V circuits

February 20, 2009

USB BUB for 3.3V & 5V Circuits

USB BUB for 3.3V & 5V Circuits

I recently purchased a Sanguino kit and a USB Serial Programming Adapter. Both of these are designed for 5V circuits. I wanted to use the USB Serial adapter for a Arduino Mini Pro which requires 3.3V, but was not clear how to do this. I contacted the folks at wulfden.org where I had purchased the Sanguino board from and within a few minutes they provided me with detailed instructions. Here are the instructions in case someone else also wants to use the USB adapter for both 3.3V and 5V circuits.

You need a six pin connector and 5 small pieces of wires.

Use the two horizontal rows above the four vertical rows in the picture (click on the thumbnail). Put your connector into the 6 holes in the top row.

In the row below, starting with the left hand most hole (pin 6) and using the leftmost column of vertical holes (the column next to the labels)

  1. short wire from vertical column Pin 6 (labeled DTR) to horizontal row Pin 6 (red wire)
  2. short wire from vertical column Pin 5 (labeled RX) to horizontal row Pin 5 (orange wire)
  3. short wire from vertical column Pin 4 (labeled TX) to horizontal row Pin 4 (yellow wire)
  4. short wire from vertical column Pin 2 (labeled 3.3v) to horizontal row Pin 3 (blue wire)
  5. short wire from vertical column Pin 6 (labeled GND) to horizontal row Pin 1 (both are square pads) (purple wire)

You will be wiring across other wires, use insulated wires, The wires ought to be long enough to keep them from touching. With such short wires when soldering the insulation often melts. To reduce the chance of melting the insulation,  solder the wires at the back of the board.

I’ve used very short wires (as you can see from the photo), which is not recommended. But I was very careful as I was soldering from the back of the board. After doing this, the adapter works well with both my 3.3V and 5V systems.

Kudos to Brian Riley and Paul Badger for providing such wonderful service at wulfden.org. I was very pleased to get the above detailed instructions on how to do this so quickly.

Arduino, could not detect size of program error

January 15, 2009

Arduino IDE, takes a Sketch and compiles it to C++ program. This C++ program is in turn compiled by the AVR GNU C++ compiler to object code, the resulting executable is in hex format and finally, this hex version is uploaded to the Atmel chip. The outline of the generated C++ code looks like this:


#include "WProgram.h"

int main(void)
{
	init();
	setup();
	for (;;)
		loop();
	return 0;
}

I had defined a function called init and this resulted in Arduino compilation to C++ failing with the error that it could not detect the size of the program. The reason for this was really due to a function by the same name getting defined in the WProgram.h file. The resulting error message, however, did point to the temp folder where all of the generated C++ code is stored. A quick read at the files in this folder highlighted the real problem: two functions with the same name. I renamed my function from init to initialize and the program compiled without a problem.

Power Sparkfun USB Evaluation Board GM862 from Arduino

January 14, 2009

 

Power GM862 from Arduino's 5V output

Power GM862 from Arduino's 5V output

For lower current applications, e.g., sending SMS vs voice calling, it appears that you can readily power the Sparkfun’s USB GM862 module directly from the Arduino’s 5V output and ground pins. I connected Arduino’s 5V to GM862’s 3.8 V pin, Arduino’s ground to GM862 ground, Arduino digital 1 (TX) to GM862′ s TXD and finally Arduino’s digital 0 (RX) to GM862’s to RXD pin. 

Note that the 5 V output drops down to 4.91 when measured at the GM862 board. 

After you make the connections, you can control GM862 from your Arduino board without having to separately supply power to the GM862 board.

 

Crude battery power Arduino and GM862

Crude battery powered Arduino and GM862

To run fully on a battery, I had to use two batteries. One for Arduino and one high capacity/current Polymer Lithium Ion (3.7V – 860mAH) for GM862. This did the trick. The regular 9V battery didn’t seem to have enough juice to run both Arduino and GM862. There must be a single battery option, but that will have to wait for another day.

Pulse Counter

December 29, 2008

The Arduino digitalRead function appears to be non-blocking. It reads either a LOW or a HIGH. If the pin you’re reading from is not connected to anything, it will read a random value. Here is a simple pulse counter that also measure the duration of the HIGH or LOW part of the pulse.

int pulsePin = 3;
int ledPin = 13;
unsigned long highCounter = 0;
unsigned long duration = 0;
int pulse = 0;
int lastPulse = LOW;
unsigned long timeNow = 0;
unsigned long lastTime = 0;

void setup() {
   pinMode(pulsePin, INPUT);
  // enable the 20K pull-up resistor to 
  // steer the input pin to a HIGH reading.
   digitalWrite(pulsePin, HIGH);   
   Serial.begin(9600);
   Serial.println("Pulse Reader - Version 2");
}

void loop() {
  pulse = digitalRead(pulsePin);
  if (pulse != lastPulse) { // pulse has changed
    timeNow = millis();
    duration = timeNow - lastTime;
    // blink the LED
    digitalWrite(ledPin, pulse);
    Serial.print(pulse);
    Serial.print(" ,");
    Serial.println(duration);
    lastPulse = pulse;
    lastTime = timeNow;
    if (pulse == HIGH) highCounter++;
  } 
}