Arduino

From 太極
Jump to navigation Jump to search

Hardware

  • Uno The Arduino Uno is a microcontroller board based on the ATmega328 (datasheet). It has 14 digital input/output pins (of which 6 can be used as PWM outputs), 6 analog inputs, a 16 MHz ceramic resonator, a USB connection, a power jack, an ICSP header, and a reset button. It contains everything needed to support the microcontroller; simply connect it to a computer with a USB cable or power it with a AC-to-DC adapter or battery to get started.
  • Due The Arduino Due is a microcontroller board based on the Atmel SAM3X8E ARM Cortex-M3 CPU (datasheet). It is the first Arduino board based on a 32-bit ARM core microcontroller. It has 54 digital input/output pins (of which 12 can be used as PWM outputs), 12 analog inputs, 4 UARTs (hardware serial ports), a 84 MHz clock, an USB OTG capable connection, 2 DAC (digital to analog), 2 TWI, a power jack, an SPI header, a JTAG header, a reset button and an erase button.

Arduino IDE

Source code in Github

https://github.com/arduino/Arduino/tree/master/hardware/arduino/cores/arduino

Install Arduino IDE under Ubuntu

sudo apt-get install arduino-core
sudo apt-get install openjdk-7-jre
# Go to http://arduino.cc/en/main/software to download the latest software
tar xzvf arduino-1.0.5-linux32.tgz
cd arduino-1.0.5
sudo ./arduino

Arduino Reset Button

To "reset" the Uno power it down, hold down the reset button, and, while still holding the reset button down, power it up again. This will prevent the existing sketch from running. You can then upload a new sketch.

C users

Tutorials

StepperMotor.jpg

MicroServo.jpg

  • Check google to see the difference between dc motor and servo.

Arduino IDE, programming, forums

Processing/Graph

It is possible to send a byte of data from the Arduino to a personal computer and graph the result. This is called serial communication because the connection appears to both the Arduino and the computer as a serial port, even though it may actually use a USB cable.

  • First, download and install Processing software (currently 2.0.3)
  • Check out http://arduino.cc/en/Tutorial/Graph for wiring. Very simple. Just one potentiometer and 3 wires (one goes to gnd, 2nd one goes to 5v and the 3rd one connects to A0).
  • Check out http://www.dustynrobots.com/news/seeing-sensors-how-to-visualize-and-save-arduino-sensed-data/ for the idea of how to plot the analog data using Processing. It contains 2 steps: 1. Open Arduino IDE (sudo is necessary if OS is not Windows) and compile/run a code to print byte to serial using Serial.write(). 2. Open Processing (sudo is necessary if OS is not Windows) and run a code. We shall be able to see a beautiful streaming graph appearing on screen. Both codes are attached below.

Arduino

int sensorPin = A0;    // analog input pin to hook the sensor to
int sensorValue = 0;  // variable to store the value coming from the sensor
 
void setup() {
  Serial.begin(9600); // initialize serial communications
}
 
void loop() {
  sensorValue = analogRead(sensorPin)/4; // read the value from the sensor
  Serial.write(sensorValue); // print bytes to serial
  delay(10);
}

Processing

import processing.serial.*;
Serial myPort;        // The serial port
float xPos = 0;             // horizontal position of the graph
 
void setup () {
  size(800, 600);        // window size
 
  // List all the available serial ports
  println(Serial.list());
 
  String portName = Serial.list()[0];
  myPort = new Serial(this, portName, 9600);
 
  background(#EDA430);
}
 
void draw () {
  // nothing happens in draw.  It all happens in SerialEvent()
}
 
void serialEvent (Serial myPort) {
  // get the byte:
  int inByte = myPort.read();
  // print it:
  println(inByte);
 
  float yPos = height - inByte;
  // draw the line in a pretty color:
  stroke(#A8D9A7);
  line(xPos, height, xPos, height - inByte);
 
  // at the edge of the screen, go back to the beginning:
  if (xPos >= width) {
    xPos = 0;
    // clear the screen by resetting the background:
    background(#081640);
  }
  else {
    // increment the horizontal position for the next reading:
    xPos++;
  }
}

ProcessingPotentiometer.png


More:

Robot based on BOE shield for Arduino

My robot is based on 'Shield for Arduino' which means I can use Arduino IDE + C code style to write my code instead of using PBASIC programming which is used in another similar robot.

  • Chapter 3. Activity 2: Re-test the servos. We can use Pins 11 and 12 instead of 12 and 13. Be sure to adjust your code accordingly.
  • Chapter 4. Activity 2: First time we disconnect robot from the computer and let it go (forward, left turn, right turn and back ward).
  • Chapter 5 (Whiskers). Activity 3 or 4: See my robot is in action on http://www.youtube.com/watch?v=sjzQI6GHe3w.

Robot whisker.jpg

Robot Infrared.jpg

This site contains some more information to use infrared LED to avoid object by testing on arduino board.

Using regular IR remote controll to control the ROBOT is also possible (it works as I have tested). The Arduino code provided for this project makes the BOE Shield-Bot recognize Sony IR remote signals only! For example, the BRIGHTSTAR universal remote sold by Parallax is programmed by holding the SET-UP button down until an LED on the remote lights up, then entering the code 605. Different models of remotes may use different codes and configuration methods. Check your remote's docs! See the instruction and arduino code in IR Remote Controlled Shield-Bot.

Using ping))) with BOEShield. Information and arduino code from Parallax. I find the code by searching within parallax.com. See http://thoughtfix.com/blog/2012/3/25/arduino-boe-shield-ping-and-a-servo.html for arduino code. Some modified code here. My recorded video is available on Youtube.

Robot ping.jpg

Other robots

Video

The astounding athletic power of quadcopters from TED.

Arduino with bluetooth

Bluetooth.jpg

Accelerometers & Gyroscopes

Adxl345.jpg

Electronics

Seller, Community

http://lifehacker.com/how-can-i-get-into-a-new-hobby-without-breaking-the-ban-489189582