Skip navigation
2014

corset.jpg

Are you addicted to social sites? Then you may want to steer clear of the ‘x.pose’ corset (via Behance)


Smart clothing is fast becoming the new trend in the fashion world. There are shoes that are able to charge mobile devices as you walk, LED dresses that changes colors as body temperatures rise and intelligent T-shirts that can remotely monitor the wearer’s vitals. Now we have a piece of clothing that becomes transparent, the more time you spend online, which may or may not be a bad thing depending on how you look at it, and look at it they will. Designed by Xuedi Chen and Pedro G.C. Oliveira, the aptly named 3D printed ‘x.pose’ corset with 20 individual hand-cut reactive displays that change opacity depending on how much data is used online.


corset 2.jpg

Mesh design (via Behance)


An integrated Arduino unit that accesses the mobile device via Bluetooth connection controls those 20 displays and an accompanying app monitors the data flow. As strange as it may sound, the corset is actually a political fashion statement meant to raise awareness on domestic spying as Google, Microsoft and every cellular company known to man has funneled personal information to the NSA. The premise is that those alphabet agencies know every facet of what we do online and are rendered ‘naked’ with nothing to hide. The corset itself is meant to represent a town and each reactive display represents a neighborhood in that town.


Once the location software identifies the area the wearer is, the corresponding display will begin pulsating and gradually lose opacity the more the wearer sends data. While the x.pose is indeed unique (in more ways than one), its unknown if the corset will ever be available for purchase. Still, it would definitely make a statement at any political demonstration or protest.


C

See more news at:

http://twitter.com/Cabe_Atwell


728x90__arduino_tre.jpg

Link back to main menu Fast Track to Arduino Programming

 

link to lesson 4a incase you missed it : Fast Track to Arduino Programming - Lesson 4a, Ethernet input and response test console

 

In lesson 4a we reviewed the HTML based console that was to be used throughout lesson 4, this was so you are prepared to follow through the lesson without worrying about how other none Arduino parts work, now I will present the main video that will walk you through the sketch, identifying the changes from the previous lesson and explaining the operation of the added code.

 

this is a long video, close to an hour but I wanted to be thorough and not miss out key parts.

 

 

The sketch and HTML page are provided in lesson 4a here: Fast Track to Arduino Programming - Lesson 4a, Ethernet input and response test console

 

and to follow up with how to change the settings of the web page and a brief description as to how it works, see this

Link back to main menu Fast Track to Arduino Programming

 

Sorry this one was so long in coming, it has taken a while to work through getting the web page up and running without being complicated and also to figure the best pins to use while not compromising the next few lessons as I want to build upon this lesson in future tutorials, the video should be up in the next couple of days (by 23rd June 2014)

 

So in preparation for the video I am going to preview this one with what the output is going to look like

lesson4.png

 

Yes this is the output of the this tutorial, it is a fully functional html page that actually talks to your Arduino over tcp/ip (Ethernet) and controls and retrieves data for the various I/O pins of the Arduino UNO

 

If you think about it, this tutorial is about adding an Ethernet shield to the UNO, so how are we going to test it, there are plenty of Android or IOS clients that can be configured to work but we need something we can all use and run on a basic PC, the best way to do this is provide the client... Please welcome my test client  or  control console, depending on how you look at it . A simple web page that will drive the UNO from anywhere on your home network and you can modify it to suit your own projects later

 

You can turn on and off three digital pins (Pin 2, 3 and 5)

You can read two input pins (Actually all of them but only two with buttons) (Pins 7 and 8)

You can change the PWM output of two channels with a simple slide of the mouse (Pin 6 and 9)

and it automatically reads the Analog inputs of 4 channels every second and displays the results on those pretty Gauge's... sweet (Pins A0, 1, 2 and 3)

oh and lastly it will retrieve the current Mills() value and show you the up time of the board

 

Oh and while it is doing all of this it is writing debug info to the serial port and responding o commands from the serial port too

 

The video is over an hour long, it needs to be edited and should be up tomorrow (Later today, its 2:39am so ill do it later), code for sketch it posted now so enjoy

 

If you think this looks scary and beyond your abilities, I don't blame you, but believe me it is not, this is tested on IE, it has issues with Chrome, it is not the Arduino's fault but I am not a pro WEB developer so I am not sure why, I have not yet tested on other browsers. I will post the HLML page now and if there is a web developer out there that can tell me why it fails in chrome, that would be nice, correct the file and return it to me would be appreciated too, I will give you the credit for the fix in this blog

 

The WEB page is pure browser side, it uses HTML 5, Canvas and CSS but everything is contained in the one file attached. The is room for improvement and optimization but this is an Arduino tutorial, not a WEB one. The java script uses ajax and json formatted data returned from the UNO.

 

The code on the UNO will not look much different from lesson 3B but of course with an Ethernet reader which you will see is almost identical to the serial reader we have already reviewed.

 

The process to doCommand() in lesson 3 is the same with the exception of adjustments for the change in pins and available I/O and adding even more commands (The process is the same) but you will learn about recursion

 

Lesson 4_bb.pngLesson 4_schem.png

 

A quick explanation as to why I have eliminated eight pins from the available I/O

 

5 Pins are used by SPI

MOSI - 11

MISO - 12

SCK - 13

Ethernet Chip Select - 10

SD Card Chip Select - 4

 

2 pins for I2C

SCL - A4

SDA - A5

 

2 Pins used by the serial port to talk to your PC via the USB

TX - 0

RX - 1

 

Future lessons are going to use these pins (Lesson 4 is already using the SPI pins and all previous ones are using TX and RX) so I figured it is better to eliminate them now to save confusion later and allow me to keep things consistent as possible

 

You may think this seriously inhibits the capability of the UNO, it does not, with the addition of a single chip I can extend digital IO by 8 pins, add 16 PWM channels or even an LCD display without loosing any more pins and by the time these lessons are over we will have done all of this.

 

in order for things to work you will need to edit the top of the htm page, you can use any text editor for this, set the ip address to suit your environment and match the IP address you use in the sketch

 

<!DOCTYPE html>

<html><head>

  <title>www.TheBreadBoard.ca - Arduino Fast Track - Lesson 4</title>

  <script>

   var myIPaddress = "http://192.168.1.247/";

   var analogAlljson = "analogAlljson";

   var digitalAlljson = "digitalAlljson";
  
   var analog0 = 0;

   var analog1 = 0;

   var analog2 = 0;

   var analog3 = 0;
  
   var Gauge = function (b) {


DayofMaking_logo-2.png


Congrats to Tomas Polisensky who was chosen to win the Arduino Starter Kit !



Kickstart your Project and start making with an Arduino Starter Kit! Enter the contest and win!


starter-kit.png


Share your Arduino project idea that you will create in 10 words or fewer with your original created pictures/diagrams/etc between June 18th and June 20th 2014!


Don't be afraid to be specific! (It's better if you are).


What's in the kit ?


  • Arduino Uno R3 and project book
  • Temperature / Tilt Sensors
  • LCDs and LEDs
  • Cables and resistors
  • Motors and potentiometers
  • Diodes and capacitors
  • Breadboard and octocouplers
  • And more!


It's Simple to Join:


  • Register or log on to the element14 Community.
  • Select "Add Your Comment" at the bottom of this post to submit your idea (only appears when you're logged in!)

 

What Happens Next?


  • The element14 Team will choose an entry after the 20th of June when the competition closes
  • One winner will be announced on the 24th of June

 

Important Note:


By submitting an entry you will automatically start receiving notifications of other responses to this post. If you do not wish to receive notifications, select "Unfollow" at the top right of this page. If you have any questions, please let us know in our Feedback & Support area.

 

Only submit one idea, if you submit more than one, it is at the discretion of the element14 Team to ignore or disqualify your entry/entries.

 

The element14 Team will have a preference for ideas which include diagrams/schematics/pictures of the proposed project idea(s); images containing wording that appears to extend the 10 word limit will be disqualified. This decision is at the discretion of the element14 Team.

 

If you are selected, you will be contacted via instant message on the element14 Community site to confirm your details.

 

Detailed Prizing Info:

 

The winner will be sent an Arduino Starter KitArduino Starter Kit. Entrants who post up to 10 words describing their project and post pictures/photographs/diagrams/schematics planning their project will be favoured to win the competition.

 

See the full Terms & Conditions: "There can only be one, let's start with 10! Kickstart your Arduino Project!"


Timeline:


During the period from 9am BST (United Kingdom British Summer Time) on June 18th 2014 until 5pm BST (United Kingdom British Summer Time) on the 20th of June 2014, any registered community member can participate in the competition.

 

whitehousebgNJ.gif

Learn More about Arduino with the New Jersey Makerspace Association!

smart hoodie.jpg

Alina Balean and Rucha Patwardhan’s Smart Hoodie- The wearable text messenger.


The ubiquitous hoodie, typically worn by today’s youth, athletes and thug engineers everywhere. We usually don’t associate them with technology, however you will often find that those who ‘sport’ the garment often keep their cellphone in the front pocket. Since pocket space is very limited and therefore valuable, it only makes sense that two New York University graduate students would incorporate the cellphone into the hoodie itself.


That’s right, wearable computing in all of its glory. Alina Balean and Rucha Patwardhan designed their Smart Hoodie around an Arduino microcontroller combined with an Arduino GSM shield, which processes inputs from sensors sewn into the hoodies sleeves. The setup does not actually incorporate a cellphone into the mix but rather uses the Arduino to interpret gestures into pre-programmed text messages that are then sent wirelessly through the GSM shield. For example, if the wearer rolls up the left sleeve, it sends a text notification to a pre-programmed recipient. The same can be done for simply putting on the garment or rolling up the right sleeve as well.

 

While that might seem unremarkable for all intents and purposes, it is an ingenious first step in wearable computing that has a purpose other than being flashy (LED dresses anyone?). Sure sending text messages is mundane when using your thumbs but think of the ‘covert’ potential this has. Students could send pre-programmed answers to tests by incorporating a vibrational motor into the garment for multiple choice answers (first buzz the number then the letter).

 

Users could also alert family and friends of potential threats without the assailant knowing what’s going on. Soldiers could relay coded messages without giving away their location and backwater adventurers could alert first responders without the need of using their hands (they could be broken!). The possibilities are endless and users have the extra-added bonus of more pocket space to boot!

 

C

See more news at:

http://twitter.com/Cabe_Atwell

back to intro and main menu Fast Track to Arduino Programming

 

In part 1 of this lesson, you where presented with a fully working Arduino sketch that can read from analog inputs, output PWM and output to the digital lines, please review the code there before going through this as I will be assuming ou have done so

you can find it here Fast Track to Arduino Programming - Lesson 3 pt 1, Improved Parsing and memory usage (Fully working programs)

 

this sketch compiled to 8434 bytes and had only 693 bytes of RAM left, yet we have not added any more buffers, just more code?, in this lesson video I will take you through the changes I did to the sketch to recover nearly 1K of the RAM and nearly the same for the program space, all without loosing any commands / functionality (Compiled to 7942 byes and had 1619 bytes of ram left). These techniques will be essential once we get to more advanced libraries and simply adding the library can consume 500bytes of RAM before you even use it (Example is the SD card library).

 

I will be introducing the use of PROGMEM which is used to hold  is limited to 2K on the Arduino UNO, I will also be re-arranging the sketch in order to make use of function calls rather than repeating code over and over.

 

Video 1 (Pre Optimization), please watch first., video 2 the Optimized approach, using PROGMEM, Case menu system etc

 

The attached sketch is the optimized one and has a couple of corrections included to allow for toggling the digital outputs and also handling the second parameter better, also the IsNumeric function has been updated to allow a + or - as the first character of a number

 

/*
Title: Lesson 3b. Improved parsing and reduced SRAM consumption - "Case" Statements

Description:  Reading a line of text from the Serial Port and sending to a command process function.
the processing function performs a real IO function for this lesson
This sketch also demonstrates the use of compiler directives to turn on and off blocks of functionality
Date created: 11th June 2014
Created By: Peter Oakes
Additional Comments:
Feel free to use and abuse as you wish, I imply NO Warranty
NOTE: defines take no program space untill used so use instead of ints etc when it will never change
Lessons Available
lesson 0. How big is an Empty Sketch anyway
Lesson 1. Reading the Serial input a line at time
Lesson 2. Parsing the line using  "if else if" statements and == or strcmp
Lesson 3a. Preperation for Improved parsing and reduced SRAM consumption - "Case" Statements
Lesson 3b. Improved parsing and reduced Flash usage, significantly less SRAM consumption and uses "Case" Statements
*/
/* Include needed Lbraries */
#include <avr/pgmspace.h>
/* End include libraries */
// Bunch of constants in the form of definitions
// 1 = output debug to serial port, 0 = no debug
#define debug 1 
// define the buffer size... 
#define serialbufferSize 50 
#define commandDelimeters "|,. " // '-' removed as it is needed as a value leader
#define progMemBuffer 128
// Define some Digital pins
// Dont use the PWM capable ones
#define D0 0
#define D1 1
#define D2 2
#define D3 4
#define D4 7
#define D5 8
#define D6 12
#define D7 13
// define the PWM Pins
#define PWM0 3
#define PWM1 5
#define PWM2 6
#define PWM3 9
#define PWM4 10
#define PWM5 11
#define MAXPWM 255
#define MINPWM 0
#define analogToVolts 5/1023 // Volts per step in ADC 
// End of Constants
// Now the real varibles
char inputBuffer[serialbufferSize]   ; 
int serialIndex = 0; // keep track of where we are in the buffer
// End of real variables
// Strings to be stored into Program space
//enumeration to make accessing the strings easier
enum {welcomeText0, welcomeText1, welcomeText2, webText0, webText1, webText2, errorText, helloReply, 
goodbyReply, dosomethingReply, invalidValue
#if debug 
, isnumericParam, notNumericParam
#endif
};
//welcome text
PROGMEM prog_char welcomeTxt_0[]  = "Hello, please ask me something\ntype \"Hello\", \"Goodby\", \"web\" or \"dosomething\"\n";
PROGMEM prog_char welcomeTxt_1[]  = "or \"pwmx where x is from 0 to 5\"\nor \"analogx where x is from 0 to 5\"\n";
PROGMEM prog_char welcomeTxt_2[]  = "or \"digitalx where x is from 0 to 7\"\nor make up your own command\n";
// end of welcome text
PROGMEM prog_char webTxt_0[]  = "HTTP/1.1 200 OK\nContent-Type: text/html\nConnection: close\n";
PROGMEM prog_char webTxt_1[]  = "<!DOCTYPE html><html><head><title>Hello from www.thebreadboard.ca</title></head><body>";
PROGMEM prog_char webTxt_2[]  = "</body></html>\n";
// error text
PROGMEM prog_char errorTxt_0[]  = "I dont understand you \nYou said: ";
PROGMEM prog_char helloRepTxt_0[]  = "Hello back at you ";
PROGMEM prog_char goodbyRepTxt_0[]  = "Goodby back at you ";
PROGMEM prog_char dosomethingRepTxt_0[]  = "what would you like me to do?";
PROGMEM prog_char invalidValueRepTxt_0[]  = "Invalid Value, setting unchanged";
#if debug // yes you can even use compiler directives here
PROGMEM prog_char paramIsNumeric_0[]  = "Remaining Param is numeric and = ";
PROGMEM prog_char paramIsNotNumeric_0[]  = "Remaining Param is not numeric or invalid, value = ";
#endif
//array of pointers to the above message strings
PROGMEM const char* Txt_table[] =
{welcomeTxt_0,  welcomeTxt_1,  welcomeTxt_2,  webTxt_0,  webTxt_1,  webTxt_2, errorTxt_0, 
helloRepTxt_0,goodbyRepTxt_0,dosomethingRepTxt_0, invalidValueRepTxt_0, 
#if debug // yes you can even use compiler directives here 
paramIsNumeric_0,paramIsNotNumeric_0
#endif
};
//enumeration to make accessing the command strings easier
enum {hello, goodby, dosomething, web1, web2, web3, web4, web5, analog0, analog1, analog2
, analog3, analog4, analog5, digital0, digital1, digital2, digital3, digital4
, digital5, digital6, digital7, pwm0, pwm1, pwm2, pwm3, pwm4, pwm5};
//Command Strings
PROGMEM prog_char helloCmd[]     = "Hello";
PROGMEM prog_char goodbyCmd[]    = "Goodby";
PROGMEM prog_char dosomethingCmd[]      = "dosomething";
PROGMEM prog_char web1Cmd[]      = "web1";
PROGMEM prog_char web2Cmd[]      = "web2";
PROGMEM prog_char web3Cmd[]      = "web3";
PROGMEM prog_char web4Cmd[]      = "web4";
PROGMEM prog_char web5Cmd[]      = "web5";
PROGMEM prog_char analog0Cmd[]   = "analog0";
PROGMEM prog_char analog1Cmd[]   = "analog1";
PROGMEM prog_char analog2Cmd[]   = "analog2";
PROGMEM prog_char analog3Cmd[]   = "analog3";
PROGMEM prog_char analog4Cmd[]   = "analog4";
PROGMEM prog_char analog5Cmd[]   = "analog5";
PROGMEM prog_char digital0Cmd[]   = "digital0";
PROGMEM prog_char digital1Cmd[]   = "digital1";
PROGMEM prog_char digital2Cmd[]   = "digital2";
PROGMEM prog_char digital3Cmd[]   = "digital3";
PROGMEM prog_char digital4Cmd[]   = "digital4";
PROGMEM prog_char digital5Cmd[]   = "digital5";
PROGMEM prog_char digital6Cmd[]   = "digital6";
PROGMEM prog_char digital7Cmd[]   = "digital7";
PROGMEM prog_char pwm0Cmd[]       = "pwm0";
PROGMEM prog_char pwm1Cmd[]       = "pwm1";
PROGMEM prog_char pwm2Cmd[]       = "pwm2";
PROGMEM prog_char pwm3Cmd[]       = "pwm3";
PROGMEM prog_char pwm4Cmd[]       = "pwm4";
PROGMEM prog_char pwm5Cmd[]       = "pwm5";
//array of pointers to the above command strings
PROGMEM const char* Cmd_table[] =
{helloCmd,goodbyCmd,dosomethingCmd,web1Cmd,web2Cmd,web3Cmd,web4Cmd,web5Cmd,
analog0Cmd,analog1Cmd,analog2Cmd,analog3Cmd,analog4Cmd,analog5Cmd,
digital0Cmd,digital1Cmd,digital2Cmd,digital3Cmd,digital4Cmd,digital5Cmd,digital6Cmd,digital7Cmd,
pwm0Cmd,pwm1Cmd,pwm2Cmd,pwm3Cmd,pwm4Cmd,pwm5Cmd};
int cmdCount = sizeof(Cmd_table) / sizeof(Cmd_table[0]);
// Function that finds the string in prog mem arrays and gets it into usable space
char* getStringfromProgMem(const char* Table[], int i)
{
char buffer[progMemBuffer];
strcpy_P(buffer, (char*)pgm_read_word(&(Table[i])));
return buffer;
};
// Search through the comands untill we find one or run out
int findCommand(char* searchText)
{
  int startCount = 0;
  int foundIndex = -1; // -1 = not found
  while (startCount < cmdCount)
  {
    if(strcmp(searchText,getStringfromProgMem(Cmd_table,startCount))==0)
    {
     foundIndex = startCount;
     break;
    }
    startCount++;
  }
  return foundIndex;
}
void setup() 
{ 
  // initialise all the digital outputs
  pinMode(D0, OUTPUT);      
  pinMode(D1, OUTPUT);      
  pinMode(D2, OUTPUT);      
  pinMode(D3, OUTPUT);      
  pinMode(D4, OUTPUT);      
  pinMode(D5, OUTPUT);      
  pinMode(D6, OUTPUT);      
  pinMode(D7, OUTPUT);   
  // initialise all the PWM outputs
  pinMode(PWM0, OUTPUT);      
  pinMode(PWM1, OUTPUT);      
  pinMode(PWM2, OUTPUT);      
  pinMode(PWM3, OUTPUT);      
  pinMode(PWM4, OUTPUT);      
  pinMode(PWM5, OUTPUT);      
  
  // initialize serial:
  Serial.begin(9600);
  delay(200);
  // do other setup here as needed
  
  // Print some pretty instructions
  Serial.print(getStringfromProgMem(Txt_table,welcomeText0));
  Serial.print(getStringfromProgMem(Txt_table,welcomeText1));
  Serial.print(getStringfromProgMem(Txt_table,welcomeText2));
}
void loop() 
{
  // Notice how the main loop is very simple and the functions 
  // seperate the logic into easily manageable parts
  if (CheckSerial()) DoCommand(inputBuffer); 
  // Do other stuff
}
// Enhanced Command Processor using strtok to strip out command from multi parameter string
boolean DoCommand(char * commandBuffer)
{
  char* Command; // Command Parameter
  char* Parameter; // Additional Parameter
  int analogVal = 0; // additional parameter converted to analog if possible
  
  // Get the command from the input string
  Command = strtok(commandBuffer,commandDelimeters); // get the command
  Parameter = strtok(NULL, commandDelimeters); // get the parameter if any
  //if there are more than one parameter they will be ignored for now
  // Make sure we have an analog value if we are to allow PWM output
  int outparameter = isNumeric (Parameter);
  //if it is a number then convert it
  if (outparameter) 
  {
    analogVal = atoi(Parameter);
  }
  
  // Switch / Case way to handle commands
  int cmdID = findCommand(Command);
  switch( cmdID)
  {
   case  hello :           Serial.println(getStringfromProgMem(Txt_table,helloReply));break;
   case  goodby :          Serial.println(getStringfromProgMem(Txt_table,goodbyReply)); break;
   case  dosomething :     Serial.println(getStringfromProgMem(Txt_table,dosomethingReply)); break;
   case  web1 :            processWebCmd("<H1>Test1</H1>");break;
   case  web2 :            processWebCmd("<H1>Test2</H1>");break;
   case  web3 :            processWebCmd("<H1>Test3</H1>");break;
   case  web4 :            processWebCmd("<H1>Test4</H1>");break;
   case  web5 :            processWebCmd("<H1>Test5</H1>");break;
   case  analog0 :         getAnalog(A0); break;
   case  analog1 :         getAnalog(A1); break;
   case  analog2 :         getAnalog(A2); break;
   case  analog3 :         getAnalog(A3); break;
   case  analog4 :         getAnalog(A4); break;
   case  analog5 :         getAnalog(A5); break;
   case  digital0 :        getsetDigital(D0, analogVal);break;
   case  digital1 :        getsetDigital(D1, analogVal);break;
   case  digital2 :        getsetDigital(D2, analogVal);break;
   case  digital3 :        getsetDigital(D3, analogVal);break;
   case  digital4 :        getsetDigital(D4, analogVal);break;
   case  digital5 :        getsetDigital(D5, analogVal);break;
   case  digital6 :        getsetDigital(D6, analogVal);break;
   case  digital7 :        getsetDigital(D7, analogVal);break;
   case  pwm0 :            setPWM(PWM0, analogVal, outparameter);break;
   case  pwm1 :            setPWM(PWM1, analogVal, outparameter);break;
   case  pwm2 :            setPWM(PWM2, analogVal, outparameter);break;
   case  pwm3 :            setPWM(PWM3, analogVal, outparameter);break;
   case  pwm4 :            setPWM(PWM4, analogVal, outparameter);break;
   case  pwm5 :            setPWM(PWM5, analogVal, outparameter);break;
   default :             {
                           Serial.print(getStringfromProgMem(Txt_table,errorText));
                           Serial.println(commandBuffer);
                           break;
                         }
  }
// debug code after here
#if debug  
if (Parameter != '\0'){
  Serial.print((outparameter)? getStringfromProgMem(Txt_table,isnumericParam) : getStringfromProgMem(Txt_table,notNumericParam) );
  Serial.println(Parameter);  
}
  Serial.print("Free Ram = "); Serial.println(freeRam(), DEC);
#endif  
return true;
}
/*
Checks the serial input for a string, returns true once a '\n' is seen
users can always look at the global variable "serialIndex" to see if characters have been received already
*/
boolean CheckSerial()
{
  boolean lineFound = false;
  // if there's any serial available, read it:
  while (Serial.available() > 0) {
    //Read a character as it comes in:
    //currently this will throw away anything after the buffer is full or the \n is detected
    char charBuffer = Serial.read(); 
      if (charBuffer == '\n') {
           inputBuffer[serialIndex] = 0; // terminate the string
           lineFound = (serialIndex > 0); // only good if we sent more than an empty line
           serialIndex=0; // reset for next line of data
         }
         else if(charBuffer == '\r') {
           // Just ignore the Carrage return, were only interested in new line
         }
         else if(serialIndex < serialbufferSize && lineFound == false) {
           /*Place the character in the string buffer:*/
           inputBuffer[serialIndex++] = charBuffer; // auto increment index
         }
  }// End of While
  return lineFound;
}// End of CheckSerial()
// check to see if value is nomeric.. only dealing with signed integers
int isNumeric (const char * s)
{
  if (s == NULL || *s == '\0' || isspace(*s)) return 0; // extra protection
  if (*s == '-' || *s == '+') s++; // allow a + or - in the first char space
  while(*s)
  {
    if(!isdigit(*s))
      return 0;
    s++;
  }
  return 1;
}
// end of check is numeric
#if debug
// check free ram
int freeRam () 
{
  extern int __heap_start, *__brkval; 
  int v; 
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); 
}
#endif
// output to PWM Channels
void setPWM(int pin, int value, int IsValid)
{
      // check the analog value is in the correct range if not then make isvalid false
    if (((value < MINPWM )|| (value > MAXPWM)) && IsValid) IsValid = false;
      Serial.print("pwm "); Serial.print(pin); Serial.print(" = ");
      Serial.println(value);    // read the input pin "A1" is already defined
      // dont change value if invalid
      if(IsValid) analogWrite(pin, value); else Serial.println(getStringfromProgMem(Txt_table,invalidValue));
}
// get analog Channels
void getAnalog(int pin)
{
      int readValue = analogRead(pin);
      Serial.print("Analog "); Serial.print(pin); Serial.print(" = ");
      Serial.print(readValue);    // read the input pin "Ax" is already defined
      Serial.print(" Volts = ");
      Serial.println(double(readValue)*analogToVolts);    // read the input pin "Ax"
}
// get Digital Channels
void getsetDigital(int pin, int value)
{
      Serial.print("Digital "); Serial.print(pin); Serial.print(" was = "); Serial.println(digitalRead(pin));
      if(value == -1)digitalWrite(pin, !digitalRead(pin)); // invert value
      else if(value == 0)digitalWrite(pin, LOW); // set value low
      else if(value == 1)digitalWrite(pin, HIGH); // set value high
      else Serial.println(getStringfromProgMem(Txt_table,invalidValue));
}
// get Digital Channels
void processWebCmd(char* webText)
{
    Serial.print(getStringfromProgMem(Txt_table,webText0));
    Serial.print(getStringfromProgMem(Txt_table,webText1));
    Serial.print(webText);    
    Serial.print(getStringfromProgMem(Txt_table,webText2));
}



In a glorious 8 colours. I couldn't believe this when I saw the video footage, but there's even a shot of the circuitry after it and the guy is giving away how he did it along with the code.

 

It isn't even overclocked!

 

 

Article Source: 640×480 VGA On An Arduino

Back to the main intro to the lessons Fast Track to Arduino Programming

 

Below is the intro code for Lesson 3, in order to not make the blog entry too long, part two of lesson three can be found here:

Fast Track to Arduino Programming - Lesson 3 pt 2, Improved Parsing and memory usage (Optimized)

 

The third part in this series is to improve the way we parse the input from the console and make use of SRAM. this initial program is the starting program for this lesson and is presented first to allow you to test and become familiar with its operation.

It is fully working and will read digital inputs, set up PWM outputs and read Analog Inputs, compensating the values to a 0-5V range. There should be nothing new here, I am assuming you will have already run the standard blinky program and know a bit about the analogue capability of the Arduino

The Pins are assigned as follows

 

All command parsing are changeed to use the previously described strcmp() string comparison function, if you do not understand this, please watch the previous video lesson

 

Digital Output pin assignments

          Program Name     Pin Number

#define      D0                     0

#define      D1                     1

#define      D2                     2

#define      D3                     4

#define      D4                     7

#define      D5                     8

#define      D6                     12

#define      D7                     13

 

// define the PWM Pins, Maximum value accepted is 1023

#define      PWM0                3

#define      PWM1                5

#define      PWM2                6

#define      PWM3                9

#define      PWM4                10

#define      PWM5                11

 

The Analogue Inputs are all default. A0 - A5

 

Digital outputs will simply toggle as long as any second parameter is provided, If no second parameter is provided it will return the current state, example command "D0" or "DO 1"

PWM output commands are like this : "PWM 0" to "PWM 1023", if you provide a none numeric second parameter it will not accept it

Analog inputs are simply "A0" through "A5"

 

There are more commands than that listed above, read to program to discover them. A video and second part will be posted in a few days.

 

Now the starting program

/*
Title: Lesson 3. Improved parsing and reduced SRAM consumption - "Case" Statements

Description:  Reading a line of text from the Serial Port and sending to a command process function.
the processing function only echos back to the console for this lesson
This sketch also demonstrates the use of compiler directives to turn on and off blocks of functionality


Date created: 5th June 2014
Created By: Peter Oakes


Additional Comments:


Feel free to use and abuse as you wish, I imply NO Warranty


NOTE: defines take no program space untill used so use instead of ints etc when it will never change


Lessons Available
lesson 0. How big is an Empty Sketch anyway
Lesson 1. Reading the Serial input a line at time
Lesson 2. Parsing the line using  "if else if" statements and == or strcmp
Lesson 3a. Preperation for Improved parsing and reduced SRAM consumption - "Case" Statements


*/
/* Include needed Lbraries */


/* End include libraries */


// Bunch of constants in the form of definitions
// 1 = output debug to serial port, 0 = no debug
#define debug 1
// define the buffer size...
#define serialbufferSize 50
#define commandDelimeters "|,.- "


// Define some Digital pins
// Dont use the PWM capable ones
#define D0 0
#define D1 1
#define D2 2
#define D3 4
#define D4 7
#define D5 8
#define D6 12
#define D7 13


// define the PWM Pins
#define PWM0 3
#define PWM1 5
#define PWM2 6
#define PWM3 9
#define PWM4 10
#define PWM5 11
#define MAXPWM 1023
#define MINPWM 0


#define analogToVolts 5/1023 // Volts per step in ADC
// End of Constants


// Now the real varibles
char inputBuffer[serialbufferSize]   ;
int serialIndex = 0; // keep track of where we are in the buffer
// End of real variables


void setup()
{
  // initialise all the digital outputs
  pinMode(D0, OUTPUT);  
  pinMode(D1, OUTPUT);  
  pinMode(D2, OUTPUT);  
  pinMode(D3, OUTPUT);  
  pinMode(D4, OUTPUT);  
  pinMode(D5, OUTPUT);  
  pinMode(D6, OUTPUT);  
  pinMode(D7, OUTPUT);  


  // initialise all the PWM outputs
  pinMode(PWM0, OUTPUT);  
  pinMode(PWM1, OUTPUT);  
  pinMode(PWM2, OUTPUT);  
  pinMode(PWM3, OUTPUT);  
  pinMode(PWM4, OUTPUT);  
  pinMode(PWM5, OUTPUT);  

  // initialize serial:
  Serial.begin(9600);
  // do other setup here as needed

  // Print some pretty instructions
  Serial.println(" Hello, please ask me something");
  Serial.println("type \"Hello\", \"Goodby\", \"web\" or \"dosomething\"" );
  Serial.println("or \"pwmx where x is from 0 to 5\"" );
  Serial.println("or \"analogx where x is from 0 to 5\"" );
  Serial.println("or \"digitalx where x is from 0 to 7\"" );
  Serial.println("or make up your own command");
  Serial.println();
}


void loop()
{
  // Notice how the main loop is very simple and the functions
  // seperate the logic into easily manageable parts
  if (CheckSerial()) DoCommand(inputBuffer);
  // Do other stuff
}


// Enhanced Command Processor using strtok to strip out command from multi parameter string
boolean DoCommand(char * commandBuffer)
{
  char* Command; // Command Parameter
  char* Parameter; // Additional Parameter
  int analogVal = 0; // additional parameter converted to analog if possible



  // Get the command from the input string
  Command = strtok(commandBuffer,commandDelimeters); // get the command
  Parameter = strtok(NULL, commandDelimeters); // get the parameter if any
  //if there are more than one parameter they will be ignored for now


  // Make sure we have an analog value if we are to allow PWM output
  int outparameter = isNumeric (Parameter);


  //if it is a number then convert it
  if (outparameter)
  {
    analogVal = atoi(Parameter);
    // check the analog value is in the correct range
    if (analogVal < MINPWM || analogVal > MAXPWM) outparameter = false;
  }
  // Standard way to handle commands
  if (strcmp(Command,"Hello")==0){
    Serial.println("Hello back at you ");
    //    Do some other work here
    //    and here
    //    and here
  }
  else if (strcmp(Command,"Goodby")==0){
    Serial.println("Goodby back at you ");
    //    Do some other work here
    //    and here
    //    and here
  }
  else if (strcmp(Command, "dosomething")==0){
    Serial.println("Like what ?? ");
    //    Do some other work here
    //    and here
    //    and here
  }
  else if (strcmp(Command ,"web1")==0){
    Serial.println("HTTP/1.1 200 OK");
    Serial.println("Content-Type: text/html");
    Serial.println("Connection: close");
    Serial.println();
    Serial.println("<!DOCTYPE html>");
    Serial.println("<html><head><title>Hello from www.thebreadboard.ca</title></head>");
    Serial.println("<body><h1>test 1</h1></body>");
    Serial.println("</html>");
    //    Do some other work here
    //    and here
    //    and here
  }
   else if (strcmp(Command, "web2")==0){
    Serial.println("HTTP/1.1 200 OK");
    Serial.println("Content-Type: text/html");
    Serial.println("Connection: close");
    Serial.println();
    Serial.println("<!DOCTYPE html>");
    Serial.println("<html><head><title>Hello from www.thebreadboard.ca</title></head>");
    Serial.println("<body><h1>test 2</h1></body>");
    Serial.println("</html>");
    //    Do some other work here
    //    and here
    //    and here
  }
  else if (strcmp(Command , "web3")==0){
    Serial.println("HTTP/1.1 200 OK");
    Serial.println("Content-Type: text/html");
    Serial.println("Connection: close");
    Serial.println();
    Serial.println("<!DOCTYPE html>");
    Serial.println("<html><head><title>Hello from www.thebreadboard.ca</title></head>");
    Serial.println("<body><h1>test 3</h1></body>");
    Serial.println("</html>");
    //    Do some other work here
    //    and here
    //    and here
  }
   else if (strcmp(Command ,"web4")==0){
    Serial.println("HTTP/1.1 200 OK");
    Serial.println("Content-Type: text/html");
    Serial.println("Connection: close");
    Serial.println();
    Serial.println("<!DOCTYPE html>");
    Serial.println("<html><head><title>Hello from www.thebreadboard.ca</title></head>");
    Serial.println("<body><h1>test 4</h1></body>");
    Serial.println("</html>");
    //    Do some other work here
    //    and here
    //    and here
  }
  else if (strcmp(Command , "web5")==0){
    Serial.println("HTTP/1.1 200 OK");
    Serial.println("Content-Type: text/html");
    Serial.println("Connection: close");
    Serial.println();
    Serial.println("<!DOCTYPE html>");
    Serial.println("<html><head><title>Hello from www.thebreadboard.ca</title></head>");
    Serial.println("<body><h1>test 5</h1></body>");
    Serial.println("</html>");
    //    Do some other work here
    //    and here
    //    and here
  }
// Now some anlog Read Samples
  else if (strcmp(Command, "analog0")==0){
    Serial.print("Analog Raw = ");
    Serial.print(analogRead(A0));    // read the input pin "A0" is already defined
    Serial.print(" Volts = ");
    Serial.println(double(analogRead(A0))*analogToVolts);    // read the input pin "A0" is already defined
  }
  else if (strcmp(Command, "analog1")==0){
    Serial.print("Analog Raw = ");
    Serial.print(analogRead(A1));    // read the input pin "A0" is already defined
    Serial.print(" Volts = ");
    Serial.println(double(analogRead(A1))*analogToVolts);    // read the input pin "A0" is already defined
  }
  else if (strcmp(Command, "analog2")==0){
    Serial.print("Analog Raw = ");
    Serial.print(analogRead(A2));    // read the input pin "A0" is already defined
    Serial.print(" Volts = ");
    Serial.println(double(analogRead(A2))*analogToVolts);    // read the input pin "A0" is already defined
  }
  else if (strcmp(Command, "analog3")==0){
    Serial.print("Analog Raw = ");
    Serial.print(analogRead(A3));    // read the input pin "A0" is already defined
    Serial.print(" Volts = ");
    Serial.println(double(analogRead(A3))*analogToVolts);    // read the input pin "A0" is already defined
  }
  else if (strcmp(Command, "analog4")==0){
    Serial.print("Analog Raw = ");
    Serial.print(analogRead(A4));    // read the input pin "A0" is already defined
    Serial.print(" Volts = ");
    Serial.println(double(analogRead(A4))*analogToVolts);    // read the input pin "A0" is already defined
  }
  else if (strcmp(Command, "analog5")==0){
    Serial.print("Analog Raw = ");
    Serial.print(analogRead(A5));    // read the input pin "A0" is already defined
    Serial.print(" Volts = ");
    Serial.println(double(analogRead(A5))*analogToVolts);    // read the input pin "A0" is already defined
  }
  //And a few Digitals
  else if (strcmp(Command, "digital0")==0){
    if (outparameter) digitalWrite(D0, !digitalRead(D0));
    Serial.print("Digital 0 = ");
    Serial.println(digitalRead(D0));
  }
  else if (strcmp(Command, "digital1")==0){
    if (outparameter) digitalWrite(D1, !digitalRead(D1));
    Serial.print("Digital 1 = ");
    Serial.println(digitalRead(D1));
  }
  else if (strcmp(Command, "digital2")==0){
    if (outparameter) digitalWrite(D2, !digitalRead(D2));
    Serial.print("Digital 2 = ");
    Serial.println(digitalRead(D2));
  }
  else if (strcmp(Command, "digital3")==0){
   if (outparameter) digitalWrite(D3, !digitalRead(D3));
   Serial.print("Digital 3 = ");
    Serial.println(digitalRead(D3));
  }
  else if (strcmp(Command, "digital4")==0){
    if (outparameter) digitalWrite(D4, !digitalRead(D4));
    Serial.print("Digital 4 = ");
    Serial.println(digitalRead(D4));
  }
  else if (strcmp(Command, "digital5")==0){
    if (outparameter) digitalWrite(D5, !digitalRead(D5));
    Serial.print("Analog 5 = ");
    Serial.println(digitalRead(D5));
  }
  else if (strcmp(Command, "digital6")==0){
    if (outparameter) digitalWrite(D6, !digitalRead(D6));
    Serial.print("Digital 6 = ");
    Serial.println(digitalRead(D6));
  }
  else if (strcmp(Command, "digital7")==0){
    if (outparameter) digitalWrite(D7, !digitalRead(D7));
    Serial.print("Digital 7 = ");
    Serial.println(digitalRead(D7));
  }
  // now allow the PWM Outputs if we have a valid analog parameter
  else if (strcmp(Command, "pwm0")==0  && outparameter ){
      Serial.print("pwm 0 = ");
      Serial.println(analogVal);    // read the input pin "A1" is already defined
      analogWrite(PWM0,analogVal);    // Set the PWM 0 output
    }
    // now the PWM Outputs
      else if (strcmp(Command, "pwm1")==0  && outparameter ){
      Serial.print("pwm 1 = ");
      Serial.println(analogVal);    // read the input pin "A1" is already defined
      analogWrite(PWM1, analogVal);    // Set the PWM 0 output
    }
    // now the PWM Outputs
      else if (strcmp(Command, "pwm2")==0  && outparameter ){
      Serial.print("pwm 2 = ");
      Serial.println(analogVal);    // read the input pin "A1" is already defined
      analogWrite(PWM2, analogVal);    // Set the PWM 0 output
    }
    // now the PWM Outputs
      else if (strcmp(Command, "pwm3")==0  && outparameter ){
      Serial.print("pwm 3 = ");
      Serial.println(analogVal);    // read the input pin "A1" is already defined
      analogWrite(PWM3, analogVal);    // Set the PWM 0 output
    }
    // now the PWM Outputs
      else if (strcmp(Command, "pwm4")==0  && outparameter ){
      Serial.print("pwm 4 = ");
      Serial.println(analogVal);    // read the input pin "A1" is already defined
      analogWrite(PWM4, analogVal);    // Set the PWM 0 output
    }
    // now the PWM Outputs
      else if (strcmp(Command, "pwm5")==0  && outparameter ){
      Serial.print("pwm 5 = ");
      Serial.println(analogVal);    // read the input pin "A1" is already defined
      analogWrite(PWM5, analogVal);    // Set the PWM 0 output
    }
  // Catch All
  else {
    Serial.print("I dont understand you \nYou said: ");
    Serial.println(commandBuffer);
    //    Do some other work here
    //    and here
    //    and here
  }
// debug code after here
#if debug
if (Parameter != '\0'){
  Serial.print((outparameter)? "Remaining Param is numeric and = " : "Remaining Param is none numeric and = " );
  Serial.println(Parameter);
}
  Serial.print("Free Ram = "); Serial.println(freeRam(), DEC);
#endif
return true;
}


/*
Checks the serial input for a string, returns true once a '\n' is seen
users can always look at the global variable "serialIndex" to see if characters have been received already
*/
boolean CheckSerial()
{
  boolean lineFound = false;
  // if there's any serial available, read it:
  while (Serial.available() > 0) {
    //Read a character as it comes in:
    //currently this will throw away anything after the buffer is full or the \n is detected
    char charBuffer = Serial.read();
      if (charBuffer == '\n') {
           inputBuffer[serialIndex] = 0; // terminate the string
           lineFound = (serialIndex > 0); // only good if we sent more than an empty line
           serialIndex=0; // reset for next line of data
         }
         else if(charBuffer == '\r') {
           // Just ignore the Carrage return, were only interested in new line
         }
         else if(serialIndex < serialbufferSize && lineFound == false) {
           /*Place the character in the string buffer:*/
           inputBuffer[serialIndex++] = charBuffer; // auto increment index
         }
  }// End of While
  return lineFound;
}// End of CheckSerial()


int isNumeric (const char * s)
{
  while(*s)
  {
    if(!isdigit(*s)) return 0;
    s++;
  }
  return 1;
}


#if debug
// check free ram
int freeRam ()
{
  extern int __heap_start, *__brkval;
  int v;
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}
#endif




 

Back to Intro Blog

Now we have seen how to read the serial port we will now expand the capability to include examining the content of the data and comparing to pre-defined strings in order to take different actions based on what was sent

In this tutorial we only send back message to the console, not performing actual IO to any of the built in hardware (That will be in the next lesson). this lesson focuses on simply building up a program capable of making decisions as commanded from the console. The syntax used in this lesson sticks to the commonly used approach of "If, then, Else". It also explores the 3 main comparison functions "==". "strstr" and "strcmp", why one works, one does not and well one kind of works.

 

/*
Title: Lesson 2. Parsing the line using  "if else if" statements and == or strcmp
 
Description:  Reading a line of text from the Serial Port and sending to a command process function.
the processing function only echos back to the console for this lesson
This sketch also demonstrates the use of compiler directives to turn on and off blocks of functionality
Date created: 27 May 2014
Created By: Peter Oakes
Additional Comments:
Feel free to use and abuse as you wish, I imply NO Warranty
NOTE: defines take no program space untill used so use instead of ints etc when it will never change
Lessons Available
lesson 0. How big is an Empty Sketch anyway
Lesson 1. Reading the Serial input a line at time
Lesson 2. Parsing the line using  "if else if" statements and == or strcmp
Lesson 3. Improved parsing and reduced SRAM consumption - "Case" Statements
lesson 4. Reading the Ethernet input a line at time (WEB Query)
lesson 5. Combining Serial and Ehernet into a common sketch
lesson 6. Advanced parsing of commands without "If" or "Case" statements
lesson 7. Adding input buttons to the command control

*/

// Bunch of constants in the form of definitions
// 1 = output debug to serial port, 0 = no debug
#define debug 1 
// define the buffer size... 
#define serialbufferSize 50 
// End of Constants
// Now the real varibles
char inputBuffer[serialbufferSize]   ; 
int serialIndex = 0; // keep track of where we are in the buffer
// End of real variables
void setup() 
{ 
  // initialize serial:
  Serial.begin(9600);
  // do other setup here as needed
  
  // Print some pretty instructions
  Serial.println("Hello, please ask me something");
  Serial.println("type \"Hello\", \"Goodby\", \"web\" or \"dosomething\" or make up your own command");
  Serial.println();
}
void loop() 
{
  // Notice how the main loop is very simple and the functions 
  // seperate the logic into easily manageable parts
  if (CheckSerial()) DoCommand(inputBuffer); 
  // Do other stuff
}
boolean DoCommand(char * commandBuffer)
{
  // Standard way to handle commands
  if (strstr(commandBuffer, "Hello")){
    Serial.println("Hello back at you ");
    //    Do some other work here
    //    and here
    //    and here
  }  
  else if (commandBuffer == "Goodby"){
    Serial.println("Hello back at you ");
    //    Do some other work here
    //    and here
    //    and here
  }
  else if (strcmp(commandBuffer , "dosomething")==0){
    Serial.println("Like what ?? ");
    //    Do some other work here
    //    and here
    //    and here
  }
  else if (strstr(commandBuffer , "web")){
    Serial.println("HTTP/1.1 200 OK");
    Serial.println("Content-Type: text/html");
    Serial.println("Connection: close");
    Serial.println();
    Serial.println("<!DOCTYPE html>");
    Serial.println("<html><head><title>TEST</title></head>");
    Serial.println("<body><h1>Hello from www.thebreadboard.ca</h1></body>");
    Serial.println("</html>");
    //    Do some other work here
    //    and here
    //    and here
  }
  else {
    Serial.print("I dont understand you \nYou said: ");
    Serial.println(commandBuffer);
    //    Do some other work here
    //    and here
    //    and here
  }
  
  
  // debug code after here
#if debug
  Serial.print("Free Ram = "); Serial.println(freeRam(), DEC);
#endif  
return true;
}
/*
Checks the serial input for a string, returns true once a '\n' is seen
users can always look at the global variable "serialIndex" to see if characters have been received already
*/
boolean CheckSerial()
{
  boolean lineFound = false;
  // if there's any serial available, read it:
  while (Serial.available() > 0) {
    //Read a character as it comes in:
    //currently this will throw away anything after the buffer is full or the \n is detected
    char charBuffer = Serial.read(); 
      if (charBuffer == '\n') {
           inputBuffer[serialIndex] = 0; // terminate the string
           lineFound = (serialIndex > 0); // only good if we sent more than an empty line
           serialIndex=0; // reset for next line of data
         }
         else if(charBuffer == '\r') {
           // Just ignore the Carrage return, were only interested in new line
         }
         else if(serialIndex < serialbufferSize && lineFound == false) {
           /*Place the character in the string buffer:*/
           inputBuffer[serialIndex++] = charBuffer; // auto increment index
         }
  }// End of While
  return lineFound;
}// End of CheckSerial()
#if debug
// check free ram
int freeRam () 
{
  extern int __heap_start, *__brkval; 
  int v; 
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); 
}
#endif




 

 

Back to Menu/Intro Page Fast Track to Arduino Programming

In this the first main lesson we look at how to simply read from the serial port and return what is read back out the port to the console, creating a buffer for the input data and correctly handling the input from the console

 

In the following code the CheckSerial() function has been corrected after the video was recorded. It will now be less dependent on the settings of your terminal program like Putty or the Serial Monitor of the IDE. this is due to the program now ignoring the '0D' or "\r" character often included in the data stream. All the sample code moving forward will be coded with this change

/*
Title: Lesson 1. Reading the Serial input a line at time

Description:  Reading a line of text from the Serial Port and sending to a command process function.
the processing function only echos back to the console for this lesson
This sketch also demonstrates the use of compiler directives to turn on and off blocks of functionality
Date created: 27 May 2014
Created By: Peter Oakes
Additional Comments:
Feel free to use and abuse as you wish, I imply NO Warranty
NOTE: defines take no program space untill used so use instead of ints etc when it will never change
Lessons Available
lesson 0. How big is an Empty Sketch anyway
Lesson 1. Reading the Serial input a line at time
Lesson 2. Parsing the line using  "if else if" statements
Lesson 3. Improved parsing and reduced SRAM consumption - "Case" Statements
lesson 4. Reading the Ethernet input a line at time (WEB Query)
lesson 5. Combining Serial and Ehernet into a common sketch
lesson 6. Advanced parsing of commands without "If" or "Case" statements
lesson 7. Adding input buttons to the command control
*/
// Bunch of constants in the form of definitions
// 1 = output debug to serial port, 0 = no debug
#define debug 1 
// define the buffer size... 
#define serialbufferSize 50 
// End of Constants
// Now the real varibles
char inputBuffer[serialbufferSize]   ; 
int serialIndex = 0; // keep track of where we are in the buffer
// End of real variables
void setup() 
{ 
  // initialize serial:
  Serial.begin(9600);
  // do other setup here as needed
}
void loop() 
{
  // Notice how the main loop is very simple and the functions 
  // seperate the logic into easily manageable parts
  if (CheckSerial()) DoCommand(inputBuffer); 
  // Do other stuff
}
boolean DoCommand(char * commandBuffer)
{
  Serial.println(commandBuffer);
#if debug
  Serial.print("Free Ram = "); Serial.println(freeRam(), DEC);
#endif  
return true;
}
/*
Checks the serial input for a string, returns true once a '\n' is seen
users can always look at the global variable "serialIndex" to see if characters have been received already
*/
boolean CheckSerial()
{
  boolean lineFound = false;
  // if there's any serial available, read it:
  while (Serial.available() > 0) {
    //Read a character as it comes in:
    //currently this will throw away anything after the buffer is full or the \n is detected
    char charBuffer = Serial.read(); 
      if (charBuffer == '\n') {
           inputBuffer[serialIndex] = 0; // terminate the string
           lineFound = (serialIndex > 0); // only good if we sent more than an empty line
           serialIndex=0; // reset for next line of data
         }
         else if(charBuffer == '\r') {
           // Just ignore the Carrage return, were only interested in new line
         }
         else if(serialIndex < serialbufferSize && lineFound == false) {
           /*Place the character in the string buffer:*/
           inputBuffer[serialIndex++] = charBuffer; // auto increment index
         }
  }// End of While
  return lineFound;
}// End of CheckSerial()
#if debug
// check free ram
int freeRam () 
{
  extern int __heap_start, *__brkval; 
  int v; 
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); 
}
#endif


 

 

Back to Menu/Intro Page Fast Track to Arduino Programming

In this first intro lesson I describe the basic sketch and concept of limited memory and that even an empty sketch uses up valuable system resources

 

/*
Title: Lesson 0. how big is an empty Sketch anyway

Description:  Reading a line of text from the Serial Port and sending to a command process function.
Date created: 27 May 2014
Created By: Peter Oakes
Additional Comments:
Feel free to use and abuse as you wish, I imply NO Warranty
NOTE: defines take no program space untill used so use instead of ints etc when it will never change
Lessons Available
lesson 0. How big is an Empty Sketch anyway
Lesson 1. Reading the Serial input a line at time
Lesson 2. Parsing the line using  "if else if" statements
Lesson 3. Improved parsing and reduced SRAM consumption - "Case" Statements
lesson 4. Reading the Ethernet input a line at time (WEB Query)
lesson 5. Combining Serial and Ehernet into a common sketch
lesson 6. Advanced parsing of commands without "If" or "Case" statements
lesson 7. Adding input buttons to the command control

*/
// Bunch of constants in the form of definitions
// 1 = output debug to serial port, 0 = no debug
#define debug 1 
// define the buffer size... 
#define serialbufferSize 50 
// End of Constants

// Now the real varibles
//char inputBuffer[serialbufferSize]   ; 
//int serialIndex = 0; // keep track of where we are in the buffer
// End of real variables
void setup() 
{ 
  // initialize serial:
//  Serial.begin(9600);
  // do other setup here as needed
}
void loop() 
{
  // Notice how the main loop is very simple and the functions 
  // seperate the logic into easily manageable parts
//  if (CheckSerial()) DoCommand(inputBuffer);
}
//boolean DoCommand(char * commandBuffer)
//{
//  
//#if debug
//  Serial.println(commandBuffer);
//  Serial.print("Free Ram = "); Serial.println(freeRam(), DEC);
//#endif  
//return true;
//}
//
///*
//Checks the serial input for a string, returns true once a '\n' is seen
//users can always look at the global variable "serialIndex" to see if characters have been received already
//*/
//boolean CheckSerial()
//{
//  boolean lineFound = false;
//  // if there's any serial available, read it:
//  while (Serial.available() > 0) {
//    //Read a character as it comes in:
//    //currently this will throw away anything after the buffer is full or the \n is detected
//    char charBuffer = Serial.read(); 
//      if (charBuffer == '\n') {
//           inputBuffer[serialIndex] = 0; // terminate the string
//           lineFound = (serialIndex > 0); // only good if we sent more than an empty line
//           serialIndex=0; // reset for next line of data
//         }
//         else if(serialIndex < serialbufferSize && lineFound == false) {
//           /*Place the character in the string buffer:*/
//           inputBuffer[serialIndex++] = charBuffer; // auto increment index
//         }
//  }// End of While
//  return lineFound;
//}// End of CheckSerial()
//
//#if debug
//// check free ram and return as an integer
//int freeRam () 
//{
//  extern int __heap_start, *__brkval; 
//  int v; 
//  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval); 
//}
//#endif

 

Back to Menu/Intro Page Fast Track to Arduino Programming

lesson4small.png

 

What I am presenting in the following set of videos and tutorials is a means to an end. Over the last many months I have answered many times the same questions and seen similar mistakes in programming

 

I am not necessarily implying what I am going to present will be perfect, it wont. But it will be tested and re-usable and can be taken and applied to your project if you want.

 

At a minimal I hope it will allow you to learn rapidly some techniques and practices that will allow you to focus on your project and not on the basics of how to do basic house keeping.

 

By basics I am referring to the following

     0. An Empty Sketch and how even it takes valuable resources Fast Track to Arduino Programming - Lesson 0, An Empty Sketch

     1. How to read and write from and to the serial port Fast Track to Arduino Programming - Lesson 1, Reading from the Serial Port

     2. How to Parse the data sent over the serial port in order to execute commands from a user Fast Track to Arduino Programming - Lesson 2, parsing the serial input into usable commands

     3a. Advance command processing + How to use Digital Analog and PWM outputs  Fast Track to Arduino Programming - Lesson 3 pt 1, Improved Parsing and memory usage (Fully working programs)

     3b.Optimized Advance command processing + How to use Digital Analog and PWM outputs  Fast Track to Arduino Programming - Lesson 3 pt 2, Improved Parsing and memory usage (Optimized)

     4a. How to read and write from the Ethernet Shield (Wiznet and ENC) - The test console Fast Track to Arduino Programming - Lesson 4a, Ethernet input and response

     4b. How to read and write from the Ethernet Shield (Wiznet and ENC) - The tutorial  Fast Track to Arduino Programming - Lesson 4b, How to read and write from the Ethernet Shield

     5. How to preserve SRAM space and make better use of program memory for message storage,

we ended up covering this in lesson 3a and b, please hope over there and have a look, thanks Fast Track to Arduino Programming - Lesson 3 pt 1, Improved Parsing and memory usage (Fully working programs)

     6. Reading and Writing from an SD card

     7. Using temperature and Humidity Sensors

     8. Using Basic and RGB LEDs (WS2812) and built in PWM for dimming

     9. Using an N channel logic FET to improve drive capability of large loads

     10. Using an NRF24L01 radio module and creating a distributed sensor grid

`    11. WEB server allowing reading and controlling of sensors and outputs, already covered in part in lesson 4a, b.

     12. NETIO as a control panel for remote control over the internet

     13. Using an LCD display via SPI or I2C

     14. Using a higher level processor based board like a Raspberry PI or RIoT Board to talk to Arduino based controllers

     1x... More added as I think of them or prompted by Community input

This is my first blog post on Element14 and hopefully the first one of a long list

ACAL BFi [1] kindly offered me a free sample of an illuminated capacitive switch for evaluation.

The switch is made by Stadium IGT [2] who are coincidentally only a short drive away from where I live.

This is a great opportunity for me to share my findings with the wider community.


So What Is It?


It is an ‘off-the-shelf’ innovative module that combines a touch switch (no moving part) with a multi-colour backlight.

It is effectively a capacitive switch with built-in (Red/Green/Blue) RGB LED fitted within a thin assembly, see Figure 1.

It comes in two standard square sizes of 35mm and 20mm.

The 35mm module includes 4 built in LEDs whereas the 20mm module contains only one.

The free sample I got was the 35mm module which is the one described in this article.

switch_illustration_35mm.png

Figure 1 - 20mm and 35mm modules (courtesy of Stadium IGT)


The module is designed to be mounted behind a glass or Acrylic panel with a thickness of up to 11mm.

The touch sensitivity is preset by 2 micro switches fitted on the rear of the module.

It comes with a self adhesive patch for easy fitting. Other more robust fitting techniques should also be considered.

At time of writing, free samples are available from ACAL BFi [1].

 

switch_35mm_front_rear.jpg

Figure 2 - Front and rear of 35mm module


Under the hood


The schematic for the 35mm module is provided in the module datasheet as shown in Figure 3.

The schematic shows 4 RGB LEDs [3] in a single package, an LM2936 [4] low dropout voltage regulator and touch sensor QT100 [5].

switch_35mm_schematic.png

Figure 3 - Module Schematic (courtesy of Stadium IGT)


The height for RGB LED package is 1.2mm.

The LED forward voltage is 3.2V (Blue/Green) and 2.1V (Red) typical when a forward current of 20mA is applied.

The maximum forward current is specified as 35/50mA at constant current or 110/220mA with a current pulse width less than 10ms and duty cycle less than 10%.

The luminous intensity is quoted as 240/1100/550 mcd for Red/Green/Blue with 20mA forward current.


The LM2936 is a voltage regulator from Texas Instruments (was previously National Semi).

It provides a regulated output voltage of 3.3V to the touch sensor from the 6-24V input power supply.

The LM2936 is a linear regulator so high supply voltage will result in power wasted in the form of heat dissipated by the regulator.


The QT100 touch sensor is an integrated circuit that detects proximity or touch.

A charge transfer method senses an increase in load capacitance caused by the human body in close proximity to the “sense pad”.

The sense pad is probably built onto the switch module PCB. More information is available in Quantum Research Application Note [6].

The QT100 was originally made by Quantum Research Group which was later acquired by Atmel in 2008.

The QT100 has been replaced by the AT42QT1010 from Atmel.


Simple Interfacing with Arduino


The module was evaluated with an Arduino Leonardo board.

The connection between the Arduino board and the module is given in Figure 4.

 

basic_arduino_connection_bb.png

Figure 4 - Captured with open source Fritzing application [7]

 

The module is powered from the Arduino board 5V output power.

The module datasheet specifies a 6V to 24V supply but it operated correctly at 5 volts.

It is not clear why the supply voltage is restricted to 6 volts.


The easiest way to drive the RGB LEDs is to connect them directly to Arduino digital output pins.

The Green, Red and Blue LEDs are connected to pin 9 to 11 respectively.

These pins can be programmed to output a Pulse Width Modulation (PWM) signal, refer to the Arduino PWM tutorial [8] for details.


The microcontroller IO pins on my Arduino board can sink a maximum current of 40mA, with the total current not exceeding 80mA.

However it is recommended to limit current to around 20mA. So resistors were added to limit the current sink on pins 9 to 11 to 20mA.

Driving of higher current LED can be achieved by controlling a transistor gate, such as the commonly used PN2222 NPN bipolar transistor.


The output from the capacitive sense pad was connected to pin 8. A current limiting resistor was added inline as a precaution.


A Very Simple Example Code


The PWM signal allows us to change the output duty cycle from 0 to 100% duty cycle via an 8-bit value (0 to 255).

The 8-bit value is set using Arduino’s analogWrite() function call.

This is equivalent setting an analogue output voltage between 0 and 5 volts.

Since each LED is driven by its own PWM output pin, in theory 24-bit colours may be generated.


A simple program to drive the module is given in the code listing below.

The original code, taken from example RGB specturm [9], cycles an RGB LED through the colour spectrum using the 8-bit PWM pins.

The code was slightly modified so that the colour cycling loop waits for the capacitive switch to be pressed.

This code is for illustration purpose only as the microcontroller will be ‘stuck’ in an infinite loop, doing nothing more than waiting for a button press to update the LED colour.

 

// Original code from:
// https://gist.github.com/jamesotron/766994

const int redPin = 10;
const int greenPin = 9;
const int bluePin = 11;
const int buttonPin = 8;

// variable for reading the pushbutton status
int buttonState = 0;

void setup()
{
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT); 

  // Start off with the LED off.
  setColourRgb(0,0,0);
}

void loop()
{
  unsigned int rgbColour[3];

  // Start off with red.
  rgbColour[0] = 255;
  rgbColour[1] = 0;
  rgbColour[2] = 0;

  // Choose the colours to increment and decrement.
  for (int decColour = 0; decColour < 3; decColour += 1)
  {
    int incColour = decColour == 2 ? 0 : decColour + 1;

    // cross-fade the two colours.
    for(int i = 0; i < 255; i += 1)
    {
      rgbColour[decColour] -= 1;
      rgbColour[incColour] += 1;
      setColourRgb(rgbColour[0], rgbColour[1], rgbColour[2]);
  
      // Wait for button press before changing color
      do
      {
        delay(5);
        // read the state of the pushbutton value:
        buttonState = digitalRead(buttonPin);
      }
      while(buttonState == LOW);
    }
  }
}

void setColourRgb(unsigned int red, unsigned int green, unsigned int blue)
{
  analogWrite(redPin, 255-red);
  analogWrite(greenPin, 255-green);
  analogWrite(bluePin, 255-blue);
}





 

The example video below shows the module driven by colour cycling code.

A buzzer was connected across the touch sense output.

The buzzer sounds when the pad senses a press.





General Observations


It is not clear why the module supply voltage is specified to be 6V to 24V.

May be these are industry-standard voltages in control panels for which the module is targeted as a direct replacement?


The application note [6] mentions that switching signals from other circuits should be routed away from the sense traces and electrodes to prevent interference which may result in false detection.

So it bears the question whether the PWM signals driving the LEDs may interfere with the touch sense electro-static field?

No issue was observed during my tests.


The quote I was given for the 35mm module was around £50 (Great British Pounds) per unit for small quantities.

This may be affordable for industrial prototype designs but not so for home projects.


An alternative RGB LED is the WS2812B Intelligent Control LED also known as NeoPixel, see Figure 5.

The RGB LEDs and driver circuit are integrated onto the same chip.

The 24-bit colour is programmed via a single control line, no clock signal required.

The same control line can be used to daisy chain up to 1024 NeoPixel LEDs thus significantly simplifying hardware interfacing to multiple modules.

ws2812_B_tims_blog.png

Figure 5 - WS2812B Intelligent Control LED (Courtesy of Tim’s Blog [10])


An alternative to the QT100 is the CapSense technology from Cypress Semiconductor.

A low-cost evaluation kit [11] is available from Cypress.

This is not an ‘off-the-shelf’ product like the module from Stadium IGT.

Capsense_kit.jpg

Figure 6 - Low-cost CapSense evaluation kit from Cypress Semiconductor.



Final thought


I like the module simple integration of touch and visual feedback.

The module target market is industrial designs in sectors such as Aviation and Marine.

This off-the-self module has great potential within the maker community but its high price probably means that it is unaffordable for most hobbyist projects.

The module could possibly benefit from other technologies such as NeoPixel and CapSense technology.

 

The usual Disclaimer – I have no affiliation with this product, IGT Solutions or ACAL BFi.

The information provided in this article is given in good faith without warrantee.


References


[1] http://www.acalbfi.com/uk/p/00000013WR

[2] http://www.stadium-igt.com/interface-and-displays/standard-illuminated-capacitive-switches

[3] http://www.lumotronic.eu/files/p457-NSSM038A.pdf

[4] http://www.ti.com/lit/ds/symlink/lm2936.pdf

[5] http://www.atmel.com/devices/qt100.aspx?tab=overview

[6] http://www.atmel.com/images/an-kd02_103-touch_secrets.pdf

[7] http://fritzing.org/home/

[8] http://arduino.cc/en/Tutorial/PWM

[9] https://gist.github.com/jamesotron/766994

[10] http://cpldcpu.wordpress.com/2014/01/14/light_ws2812-library-v2-0-part-i-understanding-the-ws2812/

[11] http://www.cypress.com/capsensembr3/





Arduino_Uno.jpg

Sorting Machine - Skittles and M&Ms ?

 

I find this almost therapeutic to watch, perhaps it's a little OCPD in me but seeing an Arduino UnoArduino Uno control a machine which will sort out your sweeties by colour is great. This little video does well to demonstrate it working with the 3D printed parts, an RGB and an infra-red sensor doing the work in tune with the motors.

 

Practical wise it's a little slow and you would be forgiven for asking "why would I do this?" but for a friends birthday present, a person who loves purple sour skittles, I manually made up a whole bag of them for him from many, many large bags and this would have made it so much easier! Even though it's doing skittles and M&M I'm sure it could just as easily do smarties - and really this could be useful for maybe wedding favours or just if you have friends/children who particularly prefer a certain flavour or colour. I certainly couldn't find the ability to buy a particular colour of what I wanted from the sweet store.

 

 

You can even find a bill of materials and the 3D printed models along with instructions here.

 

$1 Photo-Theremin and more fun with reversed LEDs

 

I love this project. It's so simple yet the principle behind it isn't and I feel it shows a good understanding of electronics and how it works! Basically, an LED can work as a crude light sensor, or specifically it's a photo-diode. All this is using is a resistor an LED and an Arduino Uno - it brightens when it gets lighter and dims when it gets darker and ultimately when hooked up to a piezo buzzer - you can play a tune like a theremin!

 

 

The code, electrical diagrams and videos can be found here.

 

Plotting Time - Open Source Clock

 

There are clocks which use LEDs to tell the time, there are ones that use valves, hands, light casting and those that use e-ink. What if you could use actual ink to tell the time ? In this project, an Arduino is hooked up to a motor and mechanism where a felt pen draws out the time (though it could be anything you want) and wipes it away to correct it! I think it's a cute and out-of-the box way to show that there are always many ways to do the same task.

 

 

The original instructions for creating this project are in German, but there are links to the resources, 3D models, etc at a thingiverse page for the project.

 

MicroView: Chip-sized Arduino with built-in OLED Display!

 

It's an ATMega328PATMega328P (Arduino Uno) embedded within a small, smooth designed, display. It can standalone by itself or you can attach it to a computer or single board computer like the Raspberry PiRaspberry Pi. So you have the power of the ATMega chip and the potential of the OLED display. It's in a form factor that's really nice to play with, communicates over the USB port that's attached to it but also can plug straight into a breadboard.

7837640211ea6fb33ff3775dbfd5b50a_large.jpg

 

It began as a kickstarter and it's a product you can actually buy, there's a video and more examples on the Kickstarter page.

 

Arduino Bowel Gauge

 

This smart project I see as having medical applications, it follows one of the basic, natural needs! using the toilet! What's not to like ? You can tell if people are really telling the truth about when they've last cleaned it, if they're healthy or if the poor goldfish has gone the way of the drink.

 

 

It was actually created by request from HackaDay and more information is available from the appropriate blog post.

 

Etch-a-Sketch with Lasers

 

I didn't have an etch-a-sketch, but I had friends whom did, using it was definitely an art form and managing to do a curve was practically a nigh impossibility for a young child such as myself at the time. What was true of it though, is the inability to keep what you drew; just one shake and poof! gone! Not this time, not when the drawing field is a laser cutter!

 

 

Dom runs a company offering laser cutters to Hack/Mak(er) spaces and has more information on the blog.

 

Arduino Etch-a-Sketch Clock

 

This project is exactly what you think it is, where as we've seen an Arduino felt-tip pen clock and a laser cutter etch-a-sketch. Why not combine the two? Just shake it and draw a new time! Awesomely renewable.

 

 

Of course if you want to, you can make your own.

 

K4S, a Keyboard for Arduino to use with Scratch

 

Scratch, if you're not aware, is a programming language which I was originally introduced to with the Raspberry Pi. Scratch 4 Arduino since came along and with it, an Arduino Shield to help teach its principles - a Keyboard 4 Scratch!

 

 

Quite nicely the schematic is available!

 

Arduino Baby Robot

 

There's not a lot of information about this project that I've found. Just a thought provoking video. I think that this is a robot kit that you can get, it has been programmed to act curious and follow, be wary and I think it just acts amusingly.

 

 

Arduino Phone

 

It's old news to some, but since the Arduino GSM ShieldArduino GSM Shield came out it was inevitable that someone would convert it into a working phone. If you decide to do it yourself, make sure that you monitor or replace the tantalum capacitors else they may explode (I'm serious).

 

 

I'd be interested in seeing after following the original guide, how cheaply this could be made.

 

728x90__arduino_tre.jpg

 

Which do you like the most ? Are you working on an Arduino project?

 

If you can't see "Add Comment" below, please sign up for an account!

Penny.JPGDoorbells are the 20th century version of today's perpetually-interrupting cell phone. There you are, cooking a delicious dinner or reading a nice book when the doorbell rudely goes off in your ear. Sure, you're glad to see whoever is at the door, but interruptions that chime can be so obnoxious. Needless to say, I do not have a doorbell.

 

The problem with the knocking system is that I usually can't hear when someone knocks from my lab. I depend on Penny the Dog to alert me when someone is at the door. Except Penny sleeps most of the day. And then there are the delivery people (UPS/FEDEX) who can't be bothered to knock, even if it is a next-day-early-AM shipment of parts from element14 that I am eagerly waiting for.

 

I decided that I'd create a project that solves all of my problems: a silent LED that flashes whenever someone approaches my door. It is based on a laser tripwire and will be able to run day or night, even in the bright Denver sun. And if the blinking LED is annoying, a simple button press disables the alert and resets the trigger.

 

 

Tripwire Design:

The laser tripwire is set up to be as simple as possible. A laser is reflected off of a mirror and back to a photoresistor which is one leg of a voltage divider. The complete schematic is attached below. The varying light intensity changes the output of the voltage divider, which can be read by an A/D. To make the 'target' for the laser easier to hit, a Fresnel lens is used in front of the light sensor like one would see with a PIR sensor.

 

Transmitter.jpgWireless Link Design:

With the sensor defined, the rest of the wireless link must be considered. The XBee series 1XBee series 1 by Digi is a great solution to this problem, and there is a wonderful starter kitwonderful starter kit to get going. It is a wireless communication system that has an integrated A/D that can transmit the detected light level digitally. It is also a commonly used device and is one of the easiest ways to create a wireless link. Unfortunately, in order to use the standard XBee interface, the digital value is only presented on the receiving end by a PWM signal. This PWM signal is filtered which produces a DC amplitude level that can be read by an Arduino's A/D. While having to do an A/D conversion at the transmitter and again at the receiver is not ideal, it was a sacrifice made to prevent a custom implementation on the XBee.

To setup the XBee radios, I used their bloated-yet-functional (113MB) XCTU XBee setup utility and the XBee USB Adapter board that was included in the starter kit. Note that you may need to install some FTDI Virtual Com Port (VCP) drivers.

I followed two of Digi's examples in order to get the settings correct:

http://examples.digi.com/sensors/sensing-light-levels-with-a-photocell/

http://examples.digi.com/lights-motors-more/wireless-panel-meter/

The transmitter settings that I used were:

ATRE N/A

ATID 3001

ATMY 1

ATDH 0

ATDL 2

ATDo 2

ATIR 64

The receiver settings that I used were:

ATRE N/A

ATID 3001

ATMY 2

ATPo 2

ATIA 1

ATWR N/A

 

Receiver.jpgArduino Design:

Shields are possibly the biggest time saver that exists in the Arduino ecosystem. The XBee board is on 2mm pitch headers, and having some extra perf board to put the low pass filter and button on is super helpful. Arduino's wireless shieldArduino's wireless shield worked great for both challenges.

The filtered output from the receiving XBee is fed into an Arduino LeonardoArduino Leonardo for processing. The code is attached below, but the basic pseudo-code operation is:

Save the last sensor value

Read a new sensor value

If the new sensor value is greater than the past value by at least a threshold, detect a trip

Blink the LED and wait for a timer to expire or a button press

Loop back to the start

In order to make the tripwire system work at any light level, a simple comparator action wouldn't work. The threshold at night would need to be different from a daytime threshold. It would be possible to take an ambient light reading with a separate sensor and base the threshold on that, but a more elegant solution for this application would be to pay attention to the rate of light change. If the light changes by X amount within a very short period of time, a trip is registered. However if the light changes over a few seconds or minutes, it will not register a trip. Testing has shown this to work in pitch black as well as on a sunny day (although in the shade).

 

Mechanical Design:

With the electronics designed and code written, I had to put the transmitter in a project box to shield it from the elements. I found a simple enclosure, although I needed to remove the included metal plate. According to Digi's layout suggestions on page 9 of their manual, there are limitations on where metal can surround the area near the antenna. A hole for the lens, the laser, and the power supply were the only mechanical modifications required.

 

Problems that I encountered:

No project goes exactly to plan, so here are a few snags that I hope you'll be able to avoid:

  • The XBee software was more obnoxious than I expected for an entry level wireless protocol setup.
  • The power supply that I bought was so crappy and noisy that is was causing bad data to be sent. I had to add a 470uF electrolytic cap at the power input. A higher quality supply should be used.
  • I tried a getting started guide from parallax to try and verify that the hardware at least worked, but I found that the Arduino sketch didn't compile. I could have been missing something silly, but I don't have much patience for getting started guides that require dissection. So I decided to go to the source and follow Digi's getting started guide which isn't too far from what I needed for this project anyway. That worked great.
  • When uploading new firmware to the Arduino, the switch on the wireless XBee shield MUST be in 'USB' mode for it to work. Otherwise you'll get the following error: avrdude: stk500_getsync(): not in sync: resp=0x00
  • The unit only works in the shade, since direct sunlight washes out whatever the laser can produce.

 

And that's it! I now have a silent method of knowing when someone approaches my door. The next step will be to connect it to the cloud so I can set alerts to my phone when I'm away. Stay tuned!

 

Documentation Attached In .Zip File:

Laser Doorbell.sch: Schematic in EAGLE format

Laser Doorbell Schematic.pdf: Schematic in .pdf

Laser Doorbell BOM.xks: Bill of Materials

DY_Doorbell_Code.ino:  Source code for use with Arduino IDE

The "hello world" of the Arduino is the blink sketch. This demonstrates that your board is working by blinking an LED, typically the on-board LED attached to pin13 but it has a problem.

The code uses the "delay" function which waits the desired number of milliseconds before continuing with the next line of the code.

 

int led = 13;

void setup() {                
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);     
}

void loop() {
  digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(1000);               // wait for a second
  digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
  delay(1000);               // wait for a second
  //Code here runs once every 2 seconds
}

 

The problem with the delay function is that nothing else happens whilst the delay is running. This is not only wasteful of the limited processing power of the microcontroller but it also makes any other routines you are using potentially unresponsive. There are several approaches to this problem such as using interrupts. The approach I selected to use a class which implement the non blocking delay.

This delay is implemented with a variable and two function, the first sets the delay and the second checks if the delay has finished.

 

Here's how it is used:

#include "Delay.h"

int led = 13;
int ledstate = HIGH;
NonBlockDelay d;

void setup() {                
  pinMode(led, OUTPUT);  
}

// the loop routine runs over and over again forever:
void loop() {
  if (d.Timeout()) {
    digitalWrite(led, ledstate);
    ledstate = ledstate == LOW ? HIGH : LOW; //toggle state
    d.Delay(1000);
  } 
  //Code here runs frequently
}

 

Delay.h

#if defined(ARDUINO) && ARDUINO >= 100
#include <Arduino.h>
#else
#include <WProgram.h>
#endif
class NonBlockDelay {
    unsigned long iTimeout;
  public:
    void Delay (unsigned long);
    bool Timeout (void);
    unsigned long Time(void);
};

 

Delay.cpp

#include "Delay.h"
void NonBlockDelay::Delay (unsigned long t)
{
  iTimeout = millis() + t;
  return;
};
bool NonBlockDelay::Timeout (void)
{
  return (iTimeout < millis());
}
unsigned long NonBlockDelay::Time(void)
 {
   return iTimeout;
 }

 

My reason for wrapping the delay in a class is so that I can use it for twice for each of the steppers in my clock project and so my loop will end up as a series of non blocking calls.

 

void loop() {
     CheckInput();
     ReadClock();
     CalcHandPositions();
     SetStepperPositions();
     StepMotors();
}

This article covers hardware that is in development.

The hardware covered in this article is liable to change in features and specification.

It does not necessarily reflect the quality or build of the final product.

 

 

I hadn't heard of the Arduino Tre until a few months ago, I suspected that it might be ARM processor based, but I had no idea as to what it would look like or how it would function (obviously I had missed some clear marketing). I had heard some comment of it coming to market later in the year of 2014.

 

To my surprise I spotted that it was available to buy! However, this was a Developer Edition and there's only 50 available. You get the opportunity to get hold of pre-release hardware and optionally join in with a beta to engage conversation with the Arduino developers.

 

Buying into a Developer Edition ? Don't companies usually pay people to do the testing for them? I did not care, I wanted to support the development and get hold of a board. Over the course of the day it surprised me to see that there were still about 20 left, I assumed that the website writ this in error and that they had actually ran out of stock. I took a gamble and went to order one anyway. I had a few confusing confirmations on the order but it finally went through that it was available and on its way!

 

Living in the UK, the cost of the developer's edition ran at approximately £185 including delivery, considering it was listed as €149 + VAT that feels like quite a hike. Pretty steep in comparison to other boards on the market at the moment, though granted it is a developer version! I thought that in the post I would just get the board on its own. When it finally arrived I dashed home that day and recorded this rather over exposed video thanks to the sun finally gracing its presence within the usually overcast Britain.

 

 

Much to my surprise, the parcel didn't just contain an Arduino Tre, but I was also supplied with an 802.11n WiFi adapter and a power cable and stickers (who doesn't love stickers?) along with a 5V 5A power supply.

 

IMG_20140529_151036.jpgIMG_20140521_143246.jpg
IMG_20140529_151014.jpgIMG_20140529_150940.jpg

 

I was a little surprised that the anti-static bag wasn't used for the Arduino Tre, but the SD Card which came with it. Apparently this was a miscommunication and will be rectified for the production version. I received the standard Arduino 6 small circular stickers, though I didn't fully understand the need to include "HACKED" on the larger circular ones - it just didn't seem to fit in with any other marketing I'd seen for Arduino.

 

The box and its colour scheme has kept in line with other Arduino products and it is minimalistic. Understandably there isn't much in the way of guidance on the Arduino site for the product and there's information on the box to open a web page called TreSetup.html that is either available when you connect the board to your computer or when you boot the Arduino Tre standalone while connected to a screen.

 

Yes! this Arduino is effectively a standalone, single board computer. That's because it is a hybrid of an Arduino LeonardoArduino Leonardo (running an ATMega32u4 chip) with a BeagleBone BlackBeagleBone Black (Sitara ARM Cortex-A8) on the same board, with

IMG_20140521_154611.jpg

the addition of an audio processing chip; and to me, that is what makes it very interesting. Having come from a history of using a Sinclair Spectrum and a Commodore Amiga attached to my television, in a similar ilk to the Raspberry Pi - with

the Arduino Tre we're semi going back to that circle of possibility where you can sit in your living room with the Tre attached via HDMI to your television, use a wireless keyboard/mouse and code away. Or maybe that's just me? Probably just me.

Not long after the confirmation of dispatch of the Tre, I received an e-mail asking if I wanted to join in with the Beta feedback for the board. When I signed up, I was greeted by a resource of getting started and communications with the Arduino team. I'm thankful that I entered the beta participation for the board, because the first thing I had to do was to update the software on the SD Card.

 

To use the Arduino Tre you need to connect it to the mains. There are connectors on the board to connect battery power, there is also a USB port to communicate with the board, but this will only power the Leonardo portion along with the on-board read only storage that is similar to pretending to being a CD-Rom drive containing drivers and documentation.

 

The Arduino Tre does not have an on-board flash chip, which is helpful to an extent. It means that I don't have to spend time waiting to program the board itself and I can just replace the operating system relatively painlessly. The SD Card runs a version of Debian for ARM hard float which has repositories from Arduino added so that a simple use of the standard package manager, apt/aptitude can be used to keep the system up to date in the future. At present both SD Card images and updates are available to developers for keeping the board software maintained.

 

The board itself is potentially in development, too. When I received it there was an obvious fix made (and this was to each one of the 50 boards sent out) as a wire was post-production soldered into place. It's not clear to me as to why or what purpose it serves.

 

Once I was all up to date with the hardware, there was nothing stopping me from tinkering with it. When connected to a Windows computer it identified itself as a multitude of serial based devices, both the Sitara ARM processor and the Arduino Leonardo, the device identifies installs itself as a USB hub which then has the Sitara and Leonardo components attached to it. So it is entirely possible to communicate and upload code directly using say, the Arduino IDE to the Atmega32u4 that's on the board.

 

However it begins to get a little tricky there, because what you actually have should identify itself more as an Arduino YUN (which is an ATMega sat behind a Linux type environment). The ATMega32u4 communicates partly via the Sitara processor. So trying to code it directly as a Leonardo doesn't work. I'm reassured this will be clarified in time.

 

Regardless of trying to upload code traditionally to the Arduino Tre this is probably not how I would go ahead with working on it, more on that in a bit. There's a major part I have entirely skipped after updating the software and that is to go through the standard setup process.

 

On the back of the box there is reference to TreSetup.html - this is a web page file that directs to a website running via the Linux operating system on the board. Ideally it can be run from whichever operating system you have your Arduino Tre plugged into; but it can also be ran from the Debian installation on the Tre itself if it's running standalone. When the Tre is connected to your computer it sets up a virtual network interface over USB on the IP address of 192.168.7.2 - so if you already have a private network which uses this address space and that IP address in particular then you're going to have a conflict. Alternatively you can connect the ethernet cable to the Tre and use whichever IP address you allocate to it via DHCP.

 

setup-initial.pngsetup-initial2.png

At the time of writing the setup steps involve changing the name of the board; which cannot be "arduinotre" and setting a password to login with. This login is for the front-end of the website, not for accessing Debian on the Tre. The default login details for Debian on the Tre are:

 

User: tre      Pass: tre

User: root    Pass:

 

Root doesn't have a password set. At the moment the steps do not get to step 3 on the page, because you will have just rebooted your Tre (there are a lot of references like that at the moment and they're obviously just left in from testing).

 

001-trelogin.png002-treblink.png

 

Once logged in to the website it presents the now intended Integrated Development Environment (IDE) for the Arduino Tre. It has the usual sketch examples that the Java IDE has, plus some more which can be uploaded to the Leonardo or ran on the Sitara processor. Yes, you can code for the Sitara from the Arduino IDE and presumably the PRUSS on the chip as well; though I haven't checked that yet. As a 'hello world' the Leonardo and the Sitara have individual LEDs that you can code for to blink. The Sitara has a three colour LED(s) which you can code for as opposed to the Leonardo's singular.

 

The web integrated IDE for the board is definitely a step in the right direction, it has has the potential to be a better IDE than the Java one and already integrates simple functionality such as auto-completion for parenthesis and quotations. From this on-board website you can also keep the packages up to date for the operating system, monitor/check the settings for your network connections and save/load sketches to compile for the board along with running a terminal and serial monitor. More features are seemingly being added as they're identified and requested and just to re-iterate, this site doesn't have to be ran from only within the operating system of the Tre. Arguably that could be a security issue down the line by default for some people but it can be trivial to lock that down if you so choose as it is only running Debian after all.

 

I decided to test one of the existing Arduino motor shields and attach it to the board, it was incredibly simple and just worked with a stepper motor I had available.

 

IMG_20140523_232930.jpgIMG_20140523_232948.jpg
003-motor.png

 

Functionality of the Sitara and ATMega "sections" of the board are also independent. There is a jumper setting on the board itself that switches between the both of the boards being powered on/off at once and allowing the Leonardo to turn the Sitara processor on/off. This means that the Arduino Tre can be sat idle, monitoring or doing numerous actions with its own shields and/or XBee connectivity and then wake up the Linux counter-part and utilise the operating system and/or the additional GPIO if required.

 

I look forward to playing with the Tre more to see what I can do with it, and I'm interested in hearing any projects that people have in mind that could be done with the Tre.

 

728x90__arduino_tre.jpg

 

Let me know your ideas! What would you do if you had a Tre ?

 

If you can't see "Add Comment" below, please sign up for an account!

Filter Blog

By date: By tag: