Show Posts
Pages: [1]
1  Using Arduino / Networking, Protocols, and Devices / Re: Look for an RS485 tutorial on: May 02, 2013, 01:04:30 pm
I know this thread is a year old but the USART discussion sounded really interesting. Did anyone get anywhere with that?


2  Topics / Home Automation and Networked Objects / Re: Wireless network of many Arduinos on: August 29, 2012, 11:20:21 am

The serial protocol itself isn't so much of a problem, it's more about choosing hardware that would enable all the nodes to connect to the same master. So if each Arduino was equipped with a Bluetooth module would it be possible for them all to listen to the same transmission? Would they all pair with the same serial port on the master device or would they each require they're own COM port? Managing 50 virtual serial ports sounds like it could cause problems and be slow to initialise. I'm imagining the connectivity would be different with other technologies...

I think all the nodes will be within a 10-20 meter radius.


3  Topics / Home Automation and Networked Objects / Wireless network of many Arduinos on: August 29, 2012, 06:35:23 am
Hi Everyone,

I'm trying to work out the logistics of networking a large number of Arduinos via a wireless method that would ideally approximate something like RS485 (i.e. addressing lots of individual nodes based on IDs). I've got quite a bit of wired networking experience but have only ever wirelessly interfaced between with one arduino and a laptop over a bluetooth serial connection (which worked very nicely).

Ideally I would like to have around 50 nodes on the network, though if this is impossible I would consider lower numbers. All of which should be able to receive and possibly send serial data. The bandwidth can be pretty low, updating maybe only at 1-10Hz. I'm really not sure if this is possible with bluetooth, or if it is, if it would be painfully slow to initialise all those virutal serial ports and might make comms really sluggish. I'm initially envisioning a latop as the master, though it would be great to replace this later with some embedded hardware.

I'd love to hear your suggestions on this problem and am totally open to ideas regarding other wireless technologies than Bluetooth (Wifi, Xbee etc.)

Many Thanks,

4  Using Arduino / Interfacing w/ Software on the Computer / Re: Arduino SerialClass / Windows TCP/IP Socket Clash on: March 27, 2012, 11:46:49 am
Okay, so someone on CodeProject helped me figure it out. I'm putting the solution up here incase anyone else has the same problem.
You need to use precompiled headers with "stdafx.h", this already contains "afxwin.h". Also you need "ws2_32.lib" in the Linker->Additional dependancies.

Here's a link to the full discussion:
5  Using Arduino / Interfacing w/ Software on the Computer / Arduino SerialClass / Windows TCP/IP Socket Clash on: March 21, 2012, 01:09:10 pm
Hey Guys,

This may not be the most appropriate place to ask this question as it relates more to C++ than Arduino, but I thought someone else may have already solved this problem.

I've just used the SerialClass posted in the Arduino Playground ( to interface the serial output of an Arduino with a C++ console application via Microsoft Visual Studio. That works great and I can see the data from the attached sensor in the console.

I'm now trying to integrate that functionality with windows TCP/IP sockets, so that I can broadcast the sensor data to a server program. I've been using code to do that which uses the following headers to enable the socket functionality.

#include <Afxwin.h>
#include <winsock2.h>

The problem is that including these headers messes up the SerialClass, as it #includes windows.h. I get the following error:
fatal error C1189: #error :  WINDOWS.H already included.  MFC apps must not #include <windows.h>.

If I remove windows.h then I get a 81 errors just from the SerialClass (as expected), such as missing ';'s, when they clearly exist.

I tried moving the use of MFC to standard windows libraries and including #define _AFXDLL as prompted but that gives me the same error as above.

So the Arduino SerialClass needs windows.h, and sockets need winsock2.h, which can't be used in conjuction with windows.h

Any ideas how to get around this? Any help appreciated. As you can tell, I'm not too hot on C++!


6  Using Arduino / Programming Questions / Re: char array to string array problem [solved] on: February 11, 2012, 07:06:53 pm
Thanks for the prompt replies. Some very helpful comments in there that made me decide
1. To ditch the Strings (interesting post dc42)
2. To re-evaluate the necessity of storing the separate char instructions at all for later parsing, it looked like a waste of memory and seemed to be the cause of my dissappearing data issues.

Rob - thanks so much for the parser example. I modified it to fit my requirements and now have the following, which parses my data very robustly (let's hope the machine elves continue allowing it to do so tomorrow morning!). The switch statements in the main loop are necessary for the bigger picture this fits into into. It's actually going to take awhile to process each command (via fairly large physical actuators) so I need to do the processing independantly of the communications, hence storing the data.

// Data parser, based on the Arduino Forum example from Rob Tillaart
// 11-Feb-12 - Ad

char line[64];                   // contains one single line from >  to ;  with instructions to be processed, increase if needed.
int  commandCount = 0;
char *command[10];         // 10 pointers to commands -- increase 10 if needed.

boolean last_line = false;

int X1array[20];    // store instuctions in tables of XY co-ordinates
int Y1array[20];
int X2array[20];
int Y2array[20];
int Pen[20];

int local_index = 0;    // position in data arrays (refreshes on new transmission sets)

int Mode = 0;  // defines which mode we are in

void setup()

void loop()
    case 0:                         // receiving data
      if (lineAvailable())          // if a line has been identified in the serial data
        commandCount = splitLine();

        // convert string segments into elements in int arrays
//      int index;  // instruction number (from text file)
//      index = atoi(command[0]);  // don't need this data right now but might later
        X1array[local_index] = atoi(command[1]);
        Y1array[local_index] = atoi(command[2]);
        X2array[local_index] = atoi(command[3]);
        Y2array[local_index] = atoi(command[4]);
        Pen[local_index] = atoi(command[5])/100;
        local_index++;              // this will be used to overwrite the old data
        if (last_line == true){
          Mode = 1;
        } // if last_line = true
      }  // if lineAvailable()
   case 1:
         Serial.write("number of instructions = ");
         Serial.println(local_index);  // to account for zero index
         // print the contents of the arrays
         last_line = false;  // reset last_line flag
         local_index = 0;    // reset local index (instuction count)
         Mode = 0;           // go back to listening

void PrintData(){
// print current array contents
   for(int n = 0; n<local_index;n++){
      Serial.print(n);              // print the local index
      Serial.print(X1array[n]);     // print X instruction
      Serial.print(Y1array[n]);     // print Y instruction
      Serial.print(X2array[n]);     // print X2 instruction
      Serial.print(Y2array[n]);    // print Y2 instruction
      Serial.println(Pen[n]);         // print Pen instruction

// reads chars from serial until it has a <...> line, then it returns true.
// Note: not 100% fool proof
boolean lineAvailable()
  // statics are only iniitialized once
  static bool avail = false;  // available
  static int idx=0;           // index

  if (idx == 0) // to reset after last line complete
    avail = false;

  if (Serial.available() > 0)
    int c =;
    case '\n':  // ignore linebreaks
    case '>' :  // start of new line
      idx = 0;
    case '<' :  // start of last line
      last_line = true;  // set flag high
      idx = 0;
    case ';':   // end of line
      avail = true;
      idx = 0;
    default:    // all other characters
      line[idx++] = c; 
      line[idx] = '\0';
  return avail;

// assumes the elements are separated by ,
int splitLine() 
  int idx = 0;
  int i = 0;
  command[idx] = &line[0];

  while (line[i] != '\0')
    if (line[i] == ',')  // separator found
      line[i] = '\0';
      command[++idx] = &line[i];
  return idx+1;

PaulS, this code snippet looks interesting, but I want to make sure I understand it correctly (for use in future projects)
char *line[30];

line[n] = strdup(buf); // Make a copy of what's in buf.

So line is a 30 element char array, but using strdup() effectively creates a new 30 element char array with index n? After these elements are created is it as easy as using regular arrays to access and modify the elements of line?

Thanks all,

Ad  smiley
7  Using Arduino / Programming Questions / char array to string array problem on: February 11, 2012, 10:10:49 am
Hey guys,

I'm writing a data parser that is converting and transmitting a large text files of comma-separated instructions (100-10,000 instructions per file) to an Arduino for execution on phsyical hardware. The instructions each occupy a line in the text file, ending with a '\n' but also starting and ending with special characters. FYI they look like this '<4,4294,8269,4181,9150,0,;'

I've written a Processing program that segments the file into chunks of 4-10 instructions which are transmitted over Serial and interterpreted by the Arduino. The processing part is going fine but I'm running into some issues in Arduino.

Essentially, I do my parsing by reading Serial data into a char array buffer while using the start and end characters of each instruction to copy the contents into entries in a string array, this action resets the buffer. This is convienient as I can later split and execute the contents of each array entry in another section of the code and can keep the buffer relatively small in the case that I need to transmit a bunch of instructions in one go.

This sounds like it should work but when I try and print the string array out of the arduino serial buffer I just get empty lines. I know that the data is being received as the buffer shows the correct contents and the arduino is counting the number of instructions correctly.

I'm wondering if there are some issues copying from the char array to a string (i.e., I can't use strcpy()) and was considering using a 2 dimensional char arrays (a list of arrays is what I'm after), but couldn't seem to get the syntax correct (or find an example) for copying the data in the form.

char c2dArray[30][200];
char buf[200] = "<4,4294,8269,4181,9150,0,;";
c2dArray[1][1:200] = buf;   // copy buffer contents to entry one, using all the characters necessary

Any help and suggestions appreciated. This is driving me nuts! smiley-eek

Here's my parsing function:

String lines[30];            // array of instructions from incoming serial data
char buf[200];             // a place to store incoming data

    case 0:              // waiting for data / recieving data mode   
      while (Serial.available()>0 && i < 200)  {    // if there is data and we're not exceeding the index
        char incomingByte =;        // read the first byte of the message

         // store the incoming char in buffer
         buf[i] = incomingByte; 
         buf[i+1] = '\0';  // keeps the string null terminated       
         if (incomingByte == '>'){      // start of normal instructions
             num_commands++;            // increment number of instructions
         if (incomingByte == '<'){     // start of last instuction in group
            num_commands++;            // increment number of instructions
            last_line = true;          // set last line flag as high
         if (incomingByte == ';'){     // last character of each line           
            lines[num_commands-1] = buf;  // store buffer in string array
            i = -1;                       // reset position at start of buf array
            // if end of last line in current instruction block reached
            if (last_line == true){
                 Serial.write("\n num_commands = ");
                 Serial.println(buf);  // print current buffer contents
                 // repeat contents of string array
                 for (int j=0; j<num_commands;j++){
                   Serial.println(lines[j]);                   // returns empty strings over serial
                 Mode = 1;    // change to data splitting mode
          } // incomingByte = ';'
8  Using Arduino / Programming Questions / Re: Servos Patterns and Serial Comms - suggestions please on: May 13, 2011, 07:20:24 am
Hi Korman, so you'd suggest doing the whole thing inside the same loop, but splitting the steps of the motion up? That seems to make sense, especially due to the buffer, which wildbill mentioned. I'll give it a shot and let you know how it goes...
9  Using Arduino / Programming Questions / Re: Servos Patterns and Serial Comms - suggestions please on: May 13, 2011, 06:48:34 am
Hi Korman,

Thanks for your reply but I'm not sure if I described my problem clearly.

Each of the 4 servos connected to one of the unos will be continuously moving autonomously (going through some pattern), while at the same time I'll be recieving and checking the serial packets, which arrive every 10-100ms I think (I don't have the code with me right now).

So my program will have to set 4 new servo positions at every time step while also listening for messages on the serial port. If a message arrives while I'm in the middle of sending the sevo commands, I'll miss it. This is the problem.

What I need is a way to make sure that I don't miss messages while maintaining nice servo messages. It's almost like both of these things need to be on their own loop. If this was a computer program I would use multi-threading.

I wonder if there is a solution using Interrupts? I've use these for managing digital outputs but not checking the serial port?
10  Using Arduino / Programming Questions / Servos Patterns and Serial Comms - suggestions please on: May 13, 2011, 06:11:30 am
Hey Guys,

I've written a simple RS232 protocol that uses an Mega to communicate several integer values to multiple Unos. It works fine, robust and quick. To make sure I don't miss important data changes (for whatever reason, e.g. noise) I send the data packets continuously.

The Unos are going to continually move 2-4 servos each, going through preset motion patterns. When data from the mega changes the servos will either switch into a different motion pattern, or modify the variables in the existing one (e.g. the servos maybe sweeping between two angles, the new message might change these angles). The changes need to be instant and smooth on receipt of the new message.

At the moment I'm not sure what the best way to approach this is. I don't want glitchy servo motion from slow position updates as a result of checking serial messages, and I don't really want to implement a state machine where message checking is done infrequently and important packets may be missed.

I'd love to hear your suggestions of a nice way to get these two functions to work together as seamlessly as possible. I've tried searching the forum but most question of this nature relate to quite simple digital functions, I'm worried that using serial and the servo library might complicate things. Also, many people use a serial packet to move a servo, which is quite easy as you just update the position when the message arrives. I need the servo to be going through its motions all the time.

Many Thanks,

11  Forum 2005-2010 (read only) / Exhibition / Re: House Lights 2010 (400 RGBs) - Just in time on: December 21, 2010, 06:15:28 am
Wow! Very nice 8-)
12  Forum 2005-2010 (read only) / Exhibition / Re: Pitch black theatre navigation device on: December 21, 2010, 10:47:20 am
Thanks for the positive comments guys.

One of the goals of the project was to strip the boundaries between blind and sighted people. So, for example, nobody could find the targets (islands of infra-red transmitted sound) in the pitch black environment without the Lotus (which used IR in a different way), regardless of whether they were blind or sighted. It was more about swapping the senses around than trying to simulate blindness.

But yes, being in a pitch black room for 30 minutes, while relying on technology to guide you, is quite an odd experience! By the end of the project I was almost getting used to it!
13  Forum 2005-2010 (read only) / Exhibition / Pitch black theatre navigation device on: December 21, 2010, 06:37:59 am
Hey guys,

Over the summer I made an unusual navigation system for a temporary pitch black theatre installation in London. This was in collaboration with a visually impaired theatre company. The audience wore Infrared headphones and held the moving navigation device, which was controlled by Arduino. Jump to 0:19 and 0:42 in the video to see them the device, which we called the Haptic Lotus:


I used about 50 Pro Minis for this project! Such a great platform  smiley

More info on the project can be found at and on my blog:


14  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Are clone boards reliable? on: December 21, 2010, 11:55:40 am
If it a serial LCD for example, you can completely screw it up by having it connected when uploading code.

Good call, I didn't know that. I just had some IR leds and recievers connected.
15  Forum 2005-2010 (read only) / Frequently-Asked Questions / Re: Are clone boards reliable? on: December 21, 2010, 10:54:50 am
If I were buying that item, I would remove the switch and bridge the connection closed. I am not even sure what the point is

The switch is handy if you've got something connected to the TX / RX pins and want to upload new code. Press the switch when the upload starts and you won't have to disconnect whatever is on TX/RX.

I'm not even sure if this is an official function, just a tip I got from a friend that has saved me lots of time.

Pages: [1]