Monday, September 29, 2014

First wearable drone camera, by Team Nixie

Team Nixie is developing the first wearable drone camera, which can be worn around your wrist. The team will be presenting their prototype for the Intel Make It Wearable Challenge Finale on November 3, 2014 in San Francisco. Learn more about Make It Wearable and follow the race to the finish line at http://makeit.intel.com.

To find out more about Team Nixie, see their work at flynixie.com or follow them on https://www.facebook.com/flynixie.

Make It Wearable Finalists | Meet Team Nixie

Friday, September 26, 2014

Esplora TFT work on Arduino Uno

The Arduino TFT screen is a backlit LCD screen with headers, designed to fit Arduino Esplora or the Arduino Robot. This module is also compatible with any AVR-based Arduino (Uno, Leonardo, etc...) or with the Arduino Due. Read Connecting to other Arduino boards for more details.

This example, TFTGraph, run on Arduino Uno board, reads the value of analog input on A0, and graphs the values on the screen.


To connect Arduino TFT to Arduino Uno board:


Run example of TFTGraph example from Arduino IDE, File > Examples > TFT > Arduino > TFTGraph.

/*

 TFT Graph

 This example for an Arduino screen reads
 the value of an analog sensor on A0, and
 graphs the values on the screen.

 This example code is in the public domain.

 Created 15 April 2013 by Scott Fitzgerald

 http://arduino.cc/en/Tutorial/TFTGraph

 */

#include <TFT.h>  // Arduino LCD library
#include <SPI.h>

// pin definition for the Uno
#define cs   10
#define dc   9
#define rst  8

// pin definition for the Leonardo
// #define cs   7
// #define dc   0
// #define rst  1

TFT TFTscreen = TFT(cs, dc, rst);

// position of the line on screen
int xPos = 0;

void setup() {
  // initialize the serial port
  Serial.begin(9600);

  // initialize the display
  TFTscreen.begin();

  // clear the screen with a pretty color
  TFTscreen.background(250, 16, 200);
}

void loop() {
  // read the sensor and map it to the screen height
  int sensor = analogRead(A0);
  int drawHeight = map(sensor, 0, 1023, 0, TFTscreen.height());

  // print out the height to the serial monitor
  Serial.println(drawHeight);

  // draw a line in a nice color
  TFTscreen.stroke(250, 180, 10);
  TFTscreen.line(xPos, TFTscreen.height() - drawHeight, xPos, TFTscreen.height());

  // if the graph has reached the screen edge
  // erase the screen and start again
  if (xPos >= 160) {
    xPos = 0;
    TFTscreen.background(250, 16, 200);
  }
  else {
    // increment the horizontal position:
    xPos++;
  }

  delay(16);
}


Wednesday, September 24, 2014

Communication between Android and Arduino Uno in USB Host Mode

It's Bi-directional communication between Android and Arduino in USB Host Mode.

Example 1:
Single byte is sent between Android and Arduino to control LED on Arduino Uno borad and set SeekBar on Android screen according to potentiometer on Arduino. ~ http://android-er.blogspot.com/2014/09/bi-directional-communication-between.html



Example 2:
Communication sent as commands form, to set Arduino LED, and send string of text from Android to Arduino LCD, and echo back. ~ http://android-er.blogspot.com/2014/09/bi-directional-communication-between_24.html


Saturday, September 20, 2014

Firmata + Python/pyFirmata, control Arduino from Raspberry Pi

This post show steps to install pyFirmata, and also python-serial, on Raspberry Pi. Such that we can program Arduino Uno (with StandardFirmata sketch) using Python.

- Make sure you have Arduino IDE installed on Raspberry Pi.

- Install pyFirmata and python-serial, enter the command in Terminal.
$ sudo apt-get install python-pip python-serial
$ sudo pip install pyfirmata


To test your setup:

- Upload StandardFirmata sketch to your Arduino.
In Arduino IDE, click File > Examples > Firmata > StandardFirmata
Compile and upload the sketch to Arduino Uno.

- Try on Python IDLE
Start icon > Programming > IDLE to start Python
Enter the code:
>>> from pyfirmata import Arduino, util
>>> board = Arduino('/dev/ttyACM0')
>>> board.digital[13].write(1)
>>> board.digital[13].write(0)


Arduino IDE on Raspberry Pi


To install Arduino IDE on Raspberry Pi, run the command on Terminal:
$ sudo apt-get install arduino

Friday, September 19, 2014

Communication between Arduinos on I2C using Wire Library

Example to implement I2C communiation between Arduino Uno, using Wire Library.


Connection:


I2CMaster.ino
#include <Wire.h>

#define LED_PIN 13
byte CMD_ON = 0x00;
byte CMD_OFF = 0x01;
byte cmd = CMD_OFF;

byte slave_address = 7;

void setup()
{
  // Start I2C Bus as Master
  Wire.begin(); 
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, LOW);

}
void loop()
{
  if(cmd == CMD_OFF){
    delay(500);
    cmd = CMD_ON;  //prepare next cmd
  }else{
    delay(1500);
    cmd = CMD_OFF;  //prepare next cmd
  }
  
  Wire.beginTransmission(slave_address);
  Wire.write(cmd);
  Wire.endTransmission();
}

I2CSlave.ino
#include <Wire.h>

#define LED_PIN 13

//7-bit slave address (optional)
byte slave_address = 7;
byte CMD_ON = 0x00;
byte CMD_OFF = 0x01;

void setup() {
  // Start I2C Bus as Slave
  Wire.begin(slave_address);
  Wire.onReceive(receiveEvent);
  
  pinMode(LED_PIN, OUTPUT);
  digitalWrite(LED_PIN, LOW);  

}

void loop() {

}

void receiveEvent(int howMany) {
  byte cmd = Wire.read();
  if (cmd == CMD_ON){
    digitalWrite(LED_PIN, HIGH);
  }else if(cmd == CMD_OFF){
    digitalWrite(LED_PIN, LOW);
  }
}

Reference: Wire Library

Thursday, September 18, 2014

Arduino Launches an Open-Source Apartment


Located in their Torino, Italy headquarters, Arduino and futurist Bruce Sterling are building an experimental showcase apartment, outfitted with open-source hardware and furniture. But unlike the “homes of the future” of past years, this one will be available to rent via AirBnb. 

Make’s Mike Senese catches up with Arduino co-founder Massimo Banzi at MakerCon to get the details and hear about the other endeavors coming from the makers of the popular microcontrollers.


The smart dancing traffic light

The Dancing Traffic Light


Making of:

Communication betweeen Arduinos using SPI


This example show how to communicate between two Arduino Uno using SPI. The connection is shown here:


On Master side, any data received from Serial (PC), it will be sent to slave Arduino using SPI. And data received from slave will be sent to Serial (PC).

SPIMaster.ino
#include <SPI.h>
byte dataOut;
byte dataIn;

int pinSS = 10;  //Slave Select, active LOW

void setup(){
  Serial.begin(115200);  //link to PC
  
  pinMode(pinSS, OUTPUT);
  digitalWrite(pinSS, HIGH);
  SPI.begin();
}

void loop(){
  while(Serial.available() > 0){
    dataOut = Serial.read();
    dataIn = spiWriteAndRead(dataOut);
    Serial.write(dataIn);
  }
}

byte spiWriteAndRead(byte dout){
  byte din;
  digitalWrite(pinSS, LOW);
  delay(1);
  din = SPI.transfer(dout);
  digitalWrite(pinSS, HIGH);
  return din;
}

On Slave side, any data received from SPI will be sent to Serial (PC) and echo back to master Arduino in next round of transmission.

SPISlave.ino
byte dataEcho;  //echo back input data in next round
byte dataToPC;  //send input data to PC

void setup() {
    Serial.begin(115200);  //link to PC
    
    //The Port B Data Direction Register
    DDRB  |= 0b00010000; 
   //The Port B 
    PORTB |= 0b00000100;
    
    //SPI Control Register
    SPCR  |= 0b11000000;
    //SPI status register
    SPSR  |= 0b00000000;
    
    dataEcho = 0;
    dataToPC = 0;
    
    sei();
}

void loop() {
  
  if(dataToPC != 0){
    Serial.write(dataToPC);
    dataToPC = 0;
  }

}

ISR(SPI_STC_vect){
  cli();
  
  //while SS Low
  while(!(PINB & 0b00000100)){
    SPDR = dataEcho;
    
    //wait SPI transfer complete
    while(!(SPSR & (1 << SPIF)));
    
    dataEcho = SPDR;  //send back in next round
  }
  sei();
}

Sunday, September 14, 2014

Intel Edison Development Platform: Getting Started

This video take you through a step-by-step process to get up and running with Intel Edison technology.

Tuesday, September 9, 2014

Arduino Uno: scan LED Matrix in Timer Interrupt

The original tutorial "Row-columm Scanning to control an 8x8 LED Matrix" call refreshScreen() to draw the screen repeatly in main loop(). If anything in loop() have to do something for times, will block the program, and make the duty cycle (and the brightness) will become unstable. This example show how to scan LED Matrix in Timer Interrupt ISR, such that it will not be affect by the jobs in loop(). But the timing of Timer Interrupt will affect the performance. This video show how:



// 2-dimensional array of row pin numbers:
const int row[8] = {
  2, 7, 19, 5, 13, 18, 12, 16
};

// 2-dimensional array of column pin numbers:
const int col[8] = {
  6, 11, 10, 3, 17, 4, 8, 9
};

// 2-dimensional array of pixels:
int pixels[8][8];

int posX = 7;
int posY = 7;
int count = 30;
bool bg = false;

unsigned int timer1_counter;
int scanningRow = 0;

void setup() {
  Serial.begin(9600);
  
  // initialize the I/O pins as outputs
  // iterate over the pins:
  for (int thisPin = 0; thisPin < 8; thisPin++) {
    // initialize the output pins:
    pinMode(col[thisPin], OUTPUT);
    pinMode(row[thisPin], OUTPUT);
    // take the col pins (i.e. the cathodes) high to ensure that
    // the LEDS are off:
    digitalWrite(col[thisPin], HIGH);
  }

  // initialize timer1 
  noInterrupts();           // disable all interrupts
  TCCR1A = 0;
  TCCR1B = 0;

  //timer1_counter for 1 sec, with prescaler=256
  //65536 - 16000000/256
  //timer1_counter = 3036;
  //timer1_counter for 0.5 sec, with prescaler=256
  //65536 - 16000000/(256*2)
  //timer1_counter = 34286;
  //timer1_counter for 0.1 sec, with prescaler=256
  //65536 - 16000000/(256*10)
  //timer1_counter = 59286;
  //timer1_counter for 0.001 sec, with prescaler=256
  //65536 - 16000000/(256*100)
  //timer1_counter = 64911;
  //timer1_counter for 0.0002 sec, with prescaler=256
  //65536 - 16000000/(256*500)
  timer1_counter = 65411;
  
  TCNT1 = timer1_counter;   // preload timer
  TCCR1B |= (1 << CS12);    // 256 prescaler 
  TIMSK1 |= (1 << TOIE1);   // enable timer overflow interrupt
  interrupts();             // enable all interrupts
  
  //init pixels
  for (int x = 0; x < 4; x++) {
    for (int y = 0; y < 8; y++) {
      pixels[x][y] = HIGH;
    }
  }
  for (int x = 4; x < 8; x++) {
    for (int y = 0; y < 8; y++) {
      pixels[x][y] = LOW;
    }
  }
  
  pixels[1][3] = LOW;

}

ISR(TIMER1_OVF_vect)        // interrupt service routine 
{
  TCNT1 = timer1_counter;   // preload timer

  
  //scan LED Matrix in ISR
  digitalWrite(row[scanningRow], LOW);

  if(++scanningRow>=8){
    scanningRow = 0;
  }

  for (int thisCol = 0; thisCol < 8; thisCol++) {
    int thisPixel = pixels[scanningRow][thisCol];
    digitalWrite(col[thisCol], thisPixel);
  }
  digitalWrite(row[scanningRow], HIGH);
  
}

void loop() {
  //refreshScreen();
  
  //Do something, block the loop
  Serial.println("Hello!");
  //Serial.println("Hello! again");

}

void refreshScreen() {
  // iterate over the rows (anodes):
  for (int thisRow = 0; thisRow < 8; thisRow++) {
    // take the row pin (anode) high:
    digitalWrite(row[thisRow], HIGH);
    // iterate over the cols (cathodes):
    for (int thisCol = 0; thisCol < 8; thisCol++) {
      // get the state of the current pixel;
      int thisPixel = pixels[thisRow][thisCol];
      // when the row is HIGH and the col is LOW,
      // the LED where they meet turns on:
      digitalWrite(col[thisCol], thisPixel);
      // turn the pixel off:
      if (thisPixel == LOW) {
        digitalWrite(col[thisCol], HIGH);
      }
    }
    // take the row pin low to turn off the whole row:
    digitalWrite(row[thisRow], LOW);
  }
}

Monday, September 8, 2014

Using Timer Interrupt of Arduino Uno

Example to use Timer Interrupt of Arduino Uno.


WalkingLedMatrix.ino
// 2-dimensional array of row pin numbers:
const int row[8] = {
  2, 7, 19, 5, 13, 18, 12, 16
};

// 2-dimensional array of column pin numbers:
const int col[8] = {
  6, 11, 10, 3, 17, 4, 8, 9
};

// 2-dimensional array of pixels:
int pixels[8][8];

int posX = 7;
int posY = 7;
int count = 30;
bool bg = false;

volatile unsigned long lasttime;
volatile unsigned long now;

int timer1_counter;

void setup() {
  Serial.begin(9600);
  
  // initialize the I/O pins as outputs
  // iterate over the pins:
  for (int thisPin = 0; thisPin < 8; thisPin++) {
    // initialize the output pins:
    pinMode(col[thisPin], OUTPUT);
    pinMode(row[thisPin], OUTPUT);
    // take the col pins (i.e. the cathodes) high to ensure that
    // the LEDS are off:
    digitalWrite(col[thisPin], HIGH);
  }

  setupScreen();
  
  // initialize timer1 
  noInterrupts();           // disable all interrupts
  TCCR1A = 0;
  TCCR1B = 0;

  //timer1_counter for 1 sec, with prescaler=256
  //65536 - 16000000/256
  //timer1_counter = 3036;
  //timer1_counter for 0.5 sec, with prescaler=256
  //65536 - 16000000/(256*2)
  //timer1_counter = 34286;
  //timer1_counter for 0.1 sec, with prescaler=256
  //65536 - 16000000/(256*10)
  timer1_counter = 59286;
  
  
  TCNT1 = timer1_counter;   // preload timer
  TCCR1B |= (1 << CS12);    // 256 prescaler 
  TIMSK1 |= (1 << TOIE1);   // enable timer overflow interrupt
  interrupts();             // enable all interrupts
  
  lasttime = millis();

}

ISR(TIMER1_OVF_vect)        // interrupt service routine 
{
  TCNT1 = timer1_counter;   // preload timer

  if(posX--==0){
    posX = 7;
    if(posY--==0){
      posY = 7;
      bg = !bg;
    }
  }
  setupScreen();
  
  now = millis();
  Serial.println(now - lasttime);
  lasttime = now;
}

void loop() {
  refreshScreen();
}

void setupScreen(){
  if(bg){
    //ON all others
    for (int x = 0; x < 8; x++) {
      for (int y = 0; y < 8; y++) {
        pixels[x][y] = LOW;
      }
    }
    
    //OFF current pos
    pixels[posX][posY] = HIGH;
  }else{
    //OFF all others
    for (int x = 0; x < 8; x++) {
      for (int y = 0; y < 8; y++) {
        pixels[x][y] = HIGH;
      }
    }
    
    //ON current pos
    pixels[posX][posY] = LOW;
  }
}

void refreshScreen() {
  // iterate over the rows (anodes):
  for (int thisRow = 0; thisRow < 8; thisRow++) {
    // take the row pin (anode) high:
    digitalWrite(row[thisRow], HIGH);
    // iterate over the cols (cathodes):
    for (int thisCol = 0; thisCol < 8; thisCol++) {
      // get the state of the current pixel;
      int thisPixel = pixels[thisRow][thisCol];
      // when the row is HIGH and the col is LOW,
      // the LED where they meet turns on:
      digitalWrite(col[thisCol], thisPixel);
      // turn the pixel off:
      if (thisPixel == LOW) {
        digitalWrite(col[thisCol], HIGH);
      }
    }
    // take the row pin low to turn off the whole row:
    digitalWrite(row[thisRow], LOW);
  }
}

Tuesday, September 2, 2014

Node.js send string to Arduino Uno

Example to send Hello message from Node.js to Arduino Uno. Due to the Automatic (Software) Reset on Arduino Uno board, it will be reset Node.js open a SerialPort. So we have to insert a dummy delay (3 sec in the example) before first string sent.

reference:
Arduino Uno
DisablingAutoResetOnSerialConnection


Node.js code, nodejsUno.js
//To install 'serialport' locally, enter the command:
//$ npm install serialport
//Otherwise, Error: Cannot find module 'serialport' will reported

var SerialPort = require("serialport").SerialPort
var serialPort = new SerialPort('/dev/ttyACM0', 
    {   baudrate: 9600
    });
 
serialPort.on("open", function () {
    console.log('open');

    
    setTimeout(function() {
        serialPort.write("Hello...", function(err, results) {
            console.log('err ' + err);
            console.log('results ' + results);
        });
        
        setTimeout(function() {
            serialPort.write("...from Node.js", function(err, results) {
                console.log('err ' + err);
                console.log('results ' + results);
            });     
        }, 1000);
        
    }, 3000);
    

});

Sketch on Arduino Uno, refer to the post "Read from Arduino Serial port, and write to 2x16 LCD".


Communication between Android and Arduino Uno, in USB Host Mode

It's a example to implement communication between Android and Arduino Uno. Here Android is running in USB Host Mode. String received in Arduino Uno is displayed on 2x16 LCD Module.

Android side, refer to the post "Send data from Android to Arduino Uno, in USB Host Mode" of my Android blog.

Arduino Uno side, refer to last post "Read from Arduino Serial port, and write to 2x16 LCD".