Show Posts
Pages: [1] 2
1  Using Arduino / Programming Questions / Re: Connecting two Bluetooth units on: April 07, 2014, 03:25:49 am
Thanks for the council!

I tried to find the reason why this is not possible. I reset three identical HC-50 Bluetooth units to their original state. With AT commands I checked that all settings were identical, and where they were not, made them identical. Only for one parameter this did not work:  the addresses of the BT units can not be reset, they look like 14:1:251744 and are different for different units. Apparently this is what the receiving Bluetooth checks to decide if another unit is involved.
2  Using Arduino / Programming Questions / Connecting two Bluetooth units on: April 05, 2014, 05:41:24 pm
How can I connect two Arduino's each equipped with Bluetooth to the same Bluetooth channel on a laptop?

I am developing a data collection project that needs to collect 8 channels of analog data wireless to a PC as fast as possible. That can be done with a Due at a rate of ~500 Hz, perhaps even faster. But as soon as I add a fast GPS (such as the one marketed by DSS), temperature and barometric data the maximum rate goes down to ~20Hz and the data become periodically unreliable because some imperfections of Arduino's Wire library for the Due.  By using two Mega's it should be possible to collect data fast enough by using an HC-05 Bluetooth unit on each of the Mega's. The transmission cycles between the Mega's can alternate so that the data streams don't interfere. On the receiving end it would be the simplest by far if I only have to deal with one Bluetooth channel.

How is that possible? Any ideas?

Thanks and Kindest Regards!
3  Development / Other Software Development / Re: New library for BMP085 on: March 23, 2014, 10:24:59 pm
Thanks for the tip... I never thought Arduino would release the library with errors and not correct it. Searching for "Arduino due"+ " i2c problems" gave many problem listings... but a solution (unless I missed it) does not seem in sight.
4  Development / Other Software Development / New library for BMP085 on: March 22, 2014, 06:27:13 pm
The Adafruit_BMP085 library for the BMP085 barometer does not compile (IDE 1.5.6R2) on the DUE while it does on the UNO and MEGA.

Post;prev_next=prev#new is closed for a reply but it points to a sketch with a  library  which compiles and does work with the DUE but provides the wrong answers for both pressures and temperatures:
Temp(C):1145  Alt(cm):-36895  Pressure(Pa):11848
Temp(C):1145  Alt(cm):-36823  Pressure(Pa):11852
Temp(C):1145  Alt(cm):-37110  Pressure(Pa):11835

Is there an updated BMP085 library around for the DUE?
5  Using Arduino / Programming Questions / Re: Arduino GPS Shield by on: March 17, 2014, 05:16:40 am
The manual for the Iteadstudio UBLOX-6M can be downloaded from It contains instructions on how to reset the unit, but I do not understand them (Thanks for the suggestion Doc!).

How can I reset the Itead GPS unit to produce GPS data at 5 Hz?
6  Using Arduino / Programming Questions / Re: Arduino GPS Shield by on: March 15, 2014, 05:12:58 pm
How can I set the Iteadstudio GPS shield to a frequency of 5Hz?

I have tried the following code compiled with the IDE 1.5.6-r2 (modified after reply 56):
void setup() {
                      // Use prescribed Baud rate for GPS unit:
  Serial.begin(115200);   // This is the port the Mega use to communicate with you computer
  Serial1.begin(38400);  // This is where your GPS is connected to the Mega at a default speed.
  Serial1.write("$PMTK220,200*2C"); //ATTEMPT to write data at 5 Hz.

void loop() {
  // read from GPS, send to IDE Serial Monitor:
  if (Serial1.available()) {
    int inByte =;
  // read from IDE Serial Monitor, send to GPS:
  if (Serial.available()) {
    int inByte =;

It works at 1 Hz on a Mega, but not 5 Hz. Any suggestions?
7  Using Arduino / Programming Questions / Re: Autostart on: March 11, 2014, 03:21:36 pm
Thanks for the suggestions. I took them as home work and I got results.

In addition to a barometer, the final project should have bluetooth and a GPS unit attached that require start up time. Because of that I may not have seen the last of that problem. I have taken your response, numbered the suggestions and inserted my actions, results (or the lack of it) into the text as appropriate:

1) Is the sketch running at all? (How would you know?)
The only way I could think of is to insert “Blink” code. Are there better or more effective ways?

2) Has it hung or failed trying to access one of the devices?
Other than inserting “Blink” code, I do not know how to determine if a device is hung. What is a good way to determine if code is hung?

3) It may be that you need to enable the brownout detector so the processor doesn't run until the voltage is high enough. I ran the sketch listed in the forum in the section “Detecting low voltage”.

void setup(void)
void loop(void)
  Serial.println (getBandgap ());

const long InternalReferenceVoltage = 1062;  // Adjust this value to your board's specific internal BG voltage
// Code courtesy of "Coding Badly" and "Retrolefty" from the Arduino forum
// results are Vcc * 100
// So for example, 5V would be 500.
int getBandgap ()
  // REFS0 : Selects AVcc external reference
  // MUX3 MUX2 MUX1 : Selects 1.1V (VBG) 
   ADMUX = _BV (REFS0) | _BV (MUX3) | _BV (MUX2) | _BV (MUX1);
   ADCSRA |= _BV( ADSC );  // start conversion
   while (ADCSRA & _BV (ADSC))
     { }  // wait for conversion to complete
   int results = (((InternalReferenceVoltage * 1024) / ADC) + 5) / 10;
   return results;
  } // end of getBandgap

Although the sketch compiles and runs on the Mega, no credible answers result, such as 0, -22323, 21750 etc. The sketch is obviously not intended for the Mega. But it seems to me the best way to see if power levels are OK.  Would you know of similar code suitable for the Mega?

4) or delay the startup code long enough for the devices to finish initialising,
I introduced a delay in the setup routine:

void setup() {
  if (!bmp.begin()) {
Serial.println("Could not find a valid BMP085 sensor, check wiring!");
while (1) {}

This effort failed, it did not cause the Mega to start after battery power was connected.

5) or remove code that is waiting for the serial port to be opened -
I took out all the statements that relate to the serial port, I inserted on-board LED blinks in those spots where appropriate and tried again.

#include <Wire.h>
#include <Adafruit_BMP085.h>

// Pin 13 has an LED connected on most Arduino boards.
// give it a name:
int led = 13;

Adafruit_BMP085 bmp;
void setup() {
  if (!bmp.begin()) {
//Serial.println("Could not find a valid BMP085 sensor, check wiring!");
while (1) {}
    // initialize the digital pin as an output.
  pinMode(led, OUTPUT);
void loop() {
  float x=bmp.readTemperature();
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(100);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(100);               // wait for a second
It now starts up also on battery power, witness the blinking LED.
The Serial.* was the apparent problem.
Thanks for the suggestions!

6) I suggest you narrow down what it's actually doing when the problem occurs. Even a simple LED diagnostic light can give you a valuable insight into what's happening.

Do you mean probing with an LED probe?

Again, THANKS for the suggestions!

8  Using Arduino / Programming Questions / Autostart on: March 10, 2014, 08:29:09 am
A Mega 2560 was equipped with an Adafruit barometer BMP180. I would like the sketch to start automatically on power-up to a battery so the data can be logged to an on-board SD card later. But... on power-up by a battery or a USB cable no pressures are measured, witnessing the absence of a blinking LED on the Mega (the one close to the USB connection). The sketch (which works properly but does not autostart at power-up) is:
#include <Wire.h>
#include <Adafruit_BMP085.h>

  This is based on an example for the BMP085 Barometric Pressure & Temp Sensor by Adafruit

Adafruit_BMP085 bmp;
void setup() {
  if (!bmp.begin()) {
Serial.println("Could not find a valid BMP085 sensor, check wiring!");
while (1) {}
void loop() {
  long Time=millis();
    Serial.print("T = ");
    Serial.print(" *C,\t");
    Serial.print("B = ");
    Serial.print(" Pa,\t  ");

    Serial.print(" dt=");Serial.print(millis()-Time);Serial.print(" mSec.");

    delay(65);//This delay makes it easy to see the LED blink   

Any suggestions?  Thanks.
9  Using Arduino / Programming Questions / Re: SPI between 2 Arduinos one as master and one as slave on: February 10, 2014, 06:34:17 pm
Nick, Thanks for trying to help!

I tried lower transmission speeds between the two Mega's down to   SPI.setClockDivider(SPI_CLOCK_DIV128); the result was the same. Then I tried faster transmission speeds, the fasted that worked (with the same problems) was   SPI.setClockDivider(SPI_CLOCK_DIV4).

Then I tried to transmit 75 characters. That worked a few times with similar problems and then the receiver simply stopped working.

Have you heard if anyone has similar SPI problems for Arduino to Arduino communications (I could not find other examples)? Given the pedigree of the original programs, could it perhaps be possible that there are problems with the Mega SPI library?
10  Using Arduino / Programming Questions / Re: SPI between 2 Arduinos one as master and one as slave on: February 08, 2014, 04:34:57 pm
I used sketches attributed mainly to Nick Gammon (with a special THANKS to him for his contributions here!) to work on two Arduino Mega’s using IDE 1.5.5. It worked, with problems. I tried the correction listed in the last part of Reply #7 by Nick Gammon above, but because I do not understand where the correction should go it is not included. I have added  the sample output where it is obvious that  the “Hello world“ lines print more than once on a single line on the monitor and some letters come out wrong.

The master program I used is:

/* SPI Master Send - Hello World (derived from Nick Gammon's samples)

Copied and modified from Reply #6 by Rofarley:
Arduino Mega is acting as an SPI Master for
a corresponding Arduino Mega board

 SS_PIN: pin 53
 MISO: pin 50
 MOSI: pin 51
 SCK: pin 52


#include <SPI.h>

long int count = 1;
byte config = B01010000;
#define SCK_PIN  52
#define MISO_PIN 50
#define MOSI_PIN 51
#define SS_PIN   53
uint8_t buffer[128];

void setup()
  digitalWrite(SS_PIN, HIGH);  // Ensure SS stays high for now

void loop()
 char c;

 // enable Slave Select 
 digitalWrite(SS_PIN, LOW);
 // Send test string
 for (const char *p="Hello, world!\n";c=*p;p++)

 // Disable slave select
 digitalWrite(SS_PIN, HIGH);
 // 0.1 second delay

The Slave program I used is:


// Written by Nick Gammon
// February 2011
 * Send arbitrary number of bits at whatever clock rate (tested at 500 KHZ and 500 HZ).
 * This script will capture the SPI bytes, when a '\n' is recieved it will then output
 * the captured byte stream via the serial.
#include <SPI.h>
char buf [100];
volatile byte pos;
volatile boolean process_it;
void setup (void)
  Serial.begin (115200);   // debugging
  // have to send on master in, *slave out*
  pinMode(MISO, OUTPUT);
  // turn on SPI in slave mode
  SPCR |= _BV(SPE);
  // get ready for an interrupt
  pos = 0;   // buffer empty
  process_it = false;
  // now turn on interrupts
}  // end of setup
// SPI interrupt routine
ISR (SPI_STC_vect)
byte c = SPDR;  // grab byte from SPI Data Register
  // add to buffer if room
  if (pos < sizeof buf)
    buf [pos++] = c;
    // example: newline means time to process buffer
    if (c == '\n')
      process_it = true;
    }  // end of room available
}  // end of interrupt routine SPI_STC_vect
// main loop - wait for flag set in interrupt routine
void loop (void)
  if (process_it)
    buf [pos] = 0; 
    Serial.println (buf);
    pos = 0;
    process_it = false;
    }  // end of flag set
}  // end of loop

The output irregularities occur irregularly and fairly frequently. A sample of these is depicted below:
Hello, world!

Hello, world!

Hello, world!Hello, world!

Hello, world!

Hello, world!

Hello, world!

Hello, wo&ÆBHello, world!

Hello, world!

Hello, world!Hello, world!

Hello, worBHello, world!

Hello, world!

Hello, world!

Question 1: Could anyone please sprinkle some wisdom on these sketches to make them print correctly?

The Master program compiles properly on the Arduino Due, but the slave program simply does not compile.

Question 2:  What changes to the Slave program should I make to make the Slave sketch work with the DUE?

Thanks for giving this attention!
11  Using Arduino / Programming Questions / Re: Arduino GPS Shield by on: February 07, 2014, 12:34:07 pm
Could anyone sprinkle some wisdom on how to get the GPS shield to produce positions at 10 Hz?

12  Products / Arduino Due / Variable A/D Sampling frequency with ChibiOS20130710 on: January 09, 2014, 06:26:56 pm
I am using the chFifoDataLogger.ino (IDE1.5.5) released as ChibiOS20130710. The interval between points in units of 1024 usec is controlled by the number of "intervalTicks", specified in line 10 of the sketch:
// Data logger based on a FIFO to decouple SD write latency from data
// acquisition timing.
// The FIFO uses two semaphores to synchronize between tasks.

#include <ChibiOS_ARM.h>
#include <SdFat.h>
// interval between points in units of 1024 usec
const uint16_t intervalTicks = 1;
// SD file definitions
const uint8_t sdChipSelect = SS;
SdFat sd;
SdFile file;
// Fifo definitions

// size of fifo in records
const size_t FIFO_SIZE = 200;

// count of data records in fifo
SEMAPHORE_DECL(fifoData, 0);

// count of free buffers in fifo

// data type for fifo item
struct FifoItem_t {
  uint32_t usec; 
  int value;
  int error;
// array of data items
FifoItem_t fifoArray[FIFO_SIZE];
// 64 byte stack beyond task switch and interrupt needs
static WORKING_AREA(waThread1, 32);

static msg_t Thread1(void *arg) {
  // index of record to be filled
  size_t fifoHead = 0;

  // count of overrun errors
  int error = 0;

  // dummy data
  int count = 0;

  while (1) {
    // get a buffer
    if (chSemWaitTimeout(&fifoSpace, TIME_IMMEDIATE) != RDY_OK) {
      // fifo full indicate missed point
    FifoItem_t* p = &fifoArray[fifoHead];
    p->usec = micros();

    // replace next line with data read from sensor such as
    // p->value = analogRead(0);
    p->value = count++;

    p->error = error;
    error = 0;

    // signal new data
    // advance FIFO index
    fifoHead = fifoHead < (FIFO_SIZE - 1) ? fifoHead + 1 : 0;
  return 0;
void setup() {
  // wait for USB Serial
  while (!Serial) {}
  Serial.println(F("type any character to begin"));
  // open file
  if (!sd.begin(sdChipSelect)
    || !"DATA.CSV", O_CREAT | O_WRITE | O_TRUNC)) {
    Serial.println(F("SD problem"));
  // throw away input
  while (Serial.available()) {;
  Serial.println(F("type any character to end"));
  // start kernel
// main thread runs at NORMALPRIO
void mainThread() {
  // FIFO index for record to be written
  size_t fifoTail = 0;

  // time in micros of last point
  uint32_t last = 0;

  // remember errors
  bool overrunError = false;

  // start producer thread
  chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO + 1, Thread1, NULL); 

  // start SD write loop
  while (!Serial.available()) {
    // wait for next data point

    FifoItem_t* p = &fifoArray[fifoTail];
    if (fifoTail >= FIFO_SIZE) fifoTail = 0;

    // print interval between points
    if (last) {
      file.print(p->usec - last);
    } else {
    last = p->usec;

    // remember error
    if (p->error) overrunError = true;

    // release record
    // advance FIFO index
    fifoTail = fifoTail < (FIFO_SIZE - 1) ? fifoTail + 1 : 0;
  // close file, print stats and stop
  Serial.print(F("Thread1 unused stack: "));
  Serial.println(chUnusedStack(waThread1, sizeof(waThread1)));
  Serial.print(F("Heap/Main unused: "));
  if (overrunError) {
    Serial.println(F("** overrun errors **"));
void loop() {
  // not used

A value of 1 for "intervalTicks" gives a sampling rate of 1000, 2 gives 500 etc. For 900Hz I tried:
const float intervalTicks = 1.111111; but that did not work.

What sketch or library modifications do I need to make to get a sampling rate of 900 Hz, corresponding to a sampling cycle of 1,111 usec?

13  Using Arduino / Project Guidance / Re: File Time Stamp from GPS on: November 30, 2013, 05:22:58 pm
I am using the DUE IED 154R2 that comes with a wire.h library (which I include, although I am told there are serious problems with this wire library).

The GPS unit from produces the date and time as long numbers without the use of any library such as TinyGPS and such or any transformation. The reason is that the unit has its own processor that can spit out any GPS parameter as needed on request.

Hope this clarifies your questions.
Kindest Regards,

14  Using Arduino / Project Guidance / Re: File Time Stamp from GPS on: November 25, 2013, 06:59:42 am
I have not been able to implement your suggestion. My date and time come from a GPS shield called I2C GPS Shield Rev2 from DSS Cirquits for a Due such as:
long          utcTime    = 111503.3;
long          date       = 251113;

uint16_t* utcTimeX=utcTime;
uint16_t* dateX= date;


The problem is apparently in the conversion from long to an uint16_t. I was unable to get TinyGPS or the RTC library to work here.

Would you have any suggestions?

Kindest Regards,
15  Using Arduino / Project Guidance / Re: File Time Stamp from GPS on: November 18, 2013, 11:22:23 am
Thanks. I got as far as the TinyGPS, but could not find any example in the SD or SDFat library to add the file time stamp to the file. Would you have any specific reference in mind?
Pages: [1] 2