Tampilkan postingan dengan label Arduino. Tampilkan semua postingan
Tampilkan postingan dengan label Arduino. Tampilkan semua postingan

Use an IDE cable for Mounting Arduinos

Everybody has plenty of extra IDE cables just laying around, if not have five of mine. Now its time to put them to good use for mounting some of those smaller Arduino boards that have pins on the bottom for bread boarding and such.

This is a convent trick I have been using which allows you to securely mount one of these boards when you pass the bread boarding stage and decide to just stick the Arduino somewhere for a while. I have found that the IDE cables make the perfect platform for mounting smaller Arduinos on. Even better, some of the smaller IDE cables that are used to connect floppy disk drives have almost the exact number of matching pins. The only think that you have to figure out is where each wire in the ribbon cable connects to because there is two rows in the socket, nothing that a bit of testing with a multimeter cant determine!

Hardware Arrangement

Today I cleaned up the robot's wiring by moving the robot's router and two Arduinos to the front cavity in the robot's chest. To do this I had to replace the plywood piece that was behind the robot's computer with a thinner piece of luan. The move centralizes electronic components and eliminates several feet of wires which now take up only a few inches. The only disadvantage is that this places the robot's most vital components in a vulnerable location; as a solution I plan on making a protective cage that will fit over them. The cage will both act as a Faraday cage as well as a protective enclosure to prevent objects from contacting the electronic components.

Arduino Leonardo Review


Arduino packaging is by far the most attractive of any microcontroller brand I have seen. The first thing I noticed about the Arduino Leonardo straight out of the package was that it uses a Micro USB port. I had thought that it was a Mini USB when I ordered it and so I had to order an additional Micro USB to Mini USB 2.0 Adapter M/F. I now have three different Arduino boards (Uno, Pro Mini, and Leonardo), each one with a different USB port type. Having to switch between different USB cables is a bit inconvenient but I am more than willing to cope.

The Arduino Leonardo has more pins than the Uno and it works perfectly with my Ethernet shield which worked, but was too big for the Uno board. The Leonardo has the same dimensions as the Arduino Uno but it has an overall lighter weight because of the physical size of the USB port and processor. On top of the lower weight the Leonardo also sports a lower cost than the comparable Uno model.


Real Working Sonic Screwdriver



This is a fully functional electronic multi-tool modeled after the Sonic Screwdriver used in the hit series Dr. Who. This screwdriver is built using an Arduino Pro Mini to control it. Among the various features and functions that this device has are an EMF (electromagnetic field) meter, voltage detector, dog whistle, brown note tone generator, sound level meter, ohm meter, volt meter, and an IR universal remote. It can also serve as a laser pointer or a flashlight and of course there is several settings for making the LED pulse dramatically. The device can also be configured to have an electromagnet or output voltage supply if necessary.

Video of this working on youtube: http://youtu.be/zqc8fmZKMMI



Using the Arduino Pro Mini

  1. In order to use the Arduino Pro Mini you will first need to connect  the FTDI Basic Breakout board so that you can connect the Arduino to your computer through a USB port. I physically soldered my FTDI board to the Arduino by cutting off the socket that came with it and soldering the remaining pins into the Arduino.
  2. Plug your Arduino into the computer using a USB TYPE A to USB MINI B cable. You may see windows installing drivers if you have not used this board before. You will also need to download the Arduino software from their website (www.arduino.cc).
  3. Run the software and choose the correct board type by going to Tools --> Board and select Arduino Nano w/ ATmega 328
  4. Now you can connect an LED between the ground (GND) and pin 13 on the board. Run this test program to make sure it works. The LED should flash on and off repeatedly. If that does not happen disconnect the Arduino from the computer immediately and examine your solder connections.
  5. Under the tools menu select the correct board (Arduino Duemilanovo w/ ATmega328).
// TEST PROGRAM:
int ledPin = 13;              // LED connected to digital pin 13

void setup() {
  pinMode(ledPin, OUTPUT);    // sets the digital pin as output
}

void loop() {
  digitalWrite(ledPin, HIGH); // sets the LED on
  delay(1000);                // waits for a second
  digitalWrite(ledPin, LOW);  // sets the LED off
  delay(1000);                // waits for a second
}

Arduino Pro 328 Mini Review


This is the 5V/16MHz Arduino Pro Mini that I bought from Trossen Robotics. The first things that you will notice about this board is its simplistic design. The board itself is 0.7x1.3" (18x33mm) and according to Trossen's website it weighs less than two grams! I don't have a scale to verify that claim but I can tell you that is is probably quite accurate.

The Arduino Pro Mini comes without connectors of any sort but anyone serious enough to tinker with a little soldering can easily work around that. This board lacks a built in USB port and so you will also need a FTDI cable or FTDI Basic Breakout board. I recommend using the Breakout Board because it supports auto-reset. The FTDI cable lacks a DTR pin to connect to the Arduino Pro Mini and so you will not be able to use the auto-reset feature with the cable. You can also read my review of the FTDI Basic Breakout  board here if you desire: http://robotrecycled.blogspot.com/2012/09/ftdi-basic-breakout-review.html

The reason that this board lacks a lot of features is so that it can be made as inexpensive as possible.

Details:
Trossen tells its users to select 'Arduino Duemilanove w/ 328' within the Arduino software when using this board. They also say to expect your delays to work twice as long (code will run half as fast as the Duemilanove at 16MHz).

Features:
ATmega328 running at 8MHz, Low-voltage board, USB connection off board, Supports auto-reset, 3.3V regulator Max 150mA output, Over current protected, Reverse polarity protected, DC input 3.3V up to 12V, On board Power and Status LEDs



FTDI Basic Breakout Review


The photo above shows the FTDI basic breakout board's size compared to a quarter. The size of the board was the first thing that caught my attention but the board has several features that come in really handy.

For starters this the board comes ready to work with any 5V power source but you need it to work with 3.3V you can cut the default trace and add a solder jumper. This tip comes from the boards description page and I haven't tried it myself since I am only using it with 5V power sources.

The board has an LED that is handy for checking if it is even on but you can also use the LED to see serial traffic going to and from the board.

I had the board out of the package and working in under three minutes (I connected it to my Arduino Pro 328 Mini which is what took the longest). This board will work pretty much out of the package. It was astoundingly easy to connect it to my arduino and get started. You can read my review of the Arduino Pro 328 Mini here: http://robotrecycled.blogspot.com/2012/09/arduino-pro-328-mini-review.html.

I ordered my FTDI breakout board form Trossen Robotics for $13.95 plus 3.99 for shipping. My order arrived in four days which I thought was impressive considering that I have ordered from other suppliers before and it has taken a week to get my shipment. Obviously if your interested in purchasing this board you don't have to buy it through Trossen but I would recommend it because I have never had a bad or damaged shipment from them. The information bellow is from the Trossen downloads page. The technical information comes in quite handy.

This is a basic breakout board for the FTDI FT232RL USB to serial IC. The pinout of this board matches the FTDI cable to work with official Arduino and cloned 5V Arduino boards. It can also be used for general serial applications. The major difference with this board is that it brings out the DTR pin as opposed to the RTS pin of the FTDI cable. The DTR pin allows an Arduino target to auto-reset when a new Sketch is downloaded. This is a really nice feature to have and allows a sketch to be downloaded without having to hit the reset button. This board will auto reset any Arduino board that has the reset pin brought out to a 6-pin connector. The pins labeled BLK and GRN correspond to the colored wires on the FTDI cable. The black wire on the FTDI cable is GND, green is CTS. Use these BLK and GRN pins to align the FTDI basic board with your Arduino target. This board has TX and RX LEDs that make it a bit better to use over the FTDI cable.
Accessories:


This board does not come with any accessories and so you will need to provide your own cables. To use this board you will need a USB TYPE A to USB MINI B cable.

Arduino

"Arduino is an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. It's intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or environments." - http://www.arduino.cc


Both the code and the designs for Arduino are open source so you can either purchase one from a dealer or make your own. You can find reference designs for different models of the arduino at http://arduino.cc/en/Main/Hardware.

Detail: Arduino

Preventing Shorts When Using Arduino Ethernet Shield

I discovered this a while ago but I thought it would be important to share in case anyone is working on a project using an Arduino Ethernet shield. Most shields connect directly to the arduino board using the standard cascading pin system. The Ethernet shield like many others has the cascading pin feature but what it does not account for is the fact that the Ethernet jack on the board stands higher than the rest of the female pins. I have tried attaching boards above the Ethernet shield and the bottom of the board ends up contacting the metal on the top of the jack. This results in a short circuit if the problem is not noticed before the boards are powered up.

As a quick and easy solution all you have to do to prevent this is place a piece of tape or insulated adhesive over the metal Ethernet jack. This prevents shorts even if another board is directly contacting the jack.

Ethernet Shield Power Drain [SOLVED]

I have found that the Arduino Ethernet Shield has an issue where there is a power drop once it is plugged into the main Arduino unit. The voltage drop is due to the fact that power is fed from the Arduino to the Ethernet Shield through the cascading pins that the two devices share. To solve this problem I have switched out the battery pack that I was using with a larger 12 volt one that seems to have enough power to keep the Arduino and the Ethernet Shield both working. Hopefully this will be enough for now to power everything because the Arduino is also connected to a motor controller and a relay shield. The motor controller and the relay shield both have options for adding an external power source so perhaps I will need to power them separately from the Ethernet shield and the Arduino.


Grove I2C Motor Driver Setup and Example Code

After much deliberation I was finally able to get my Grove I2C motor driver and its example code working. I had originally had problems compiling a set of example code that I found online but now I have fixed the code. Also I have made a drawing showing how to connect the Grove I2C Motor Driver to an Arduino Uno. It seems that very few people have made tutorials on this controller other than the wiki page which has just a lot of technical information which is great but for people who don't want all that extra information I have made this short tutorial. I kept it short sweet and to the point so hopefully if you are trying to use one of these controllers you will be able to use the information on this page.

Setup:
(CLICK TO VIEW IMAGE LARGER)

The example code bellow should simply make the motor spin and then reverse directions repeatedly.
Additional help can be found here:
http://www.seeedstudio.com/wiki/index.php?title=Grove_-_I2C_Motor_Driver
http://www.seeedstudio.com/forum/viewtopic.php?f=17&t=2935
http://www.arduino.cc/en/Reference/Wire

Working Code Example:



#include <Wire.h>

//#define MOTORSHIELDaddr   0x0f
#define SETPWMAB          0x82
#define SETFREQ           0x84
#define CHANGEADDR        0x83
#define CHANNELSET        0xAA
#define MOTOR1            0xA1
#define MOTOR2            0xA5
#define SAVEADDR          'S'
#define NOTSAVEADDR       'N'
byte val = 0; // I put this here to replace the "Wire.write(0);"

static unsigned char MOTORSHIELDaddr = 0x28;

void speedAB(unsigned char spda , unsigned char spdb)
{
  Wire.beginTransmission(MOTORSHIELDaddr); // transmit to device MOTORSHIELDaddr
  Wire.write(SETPWMAB);        //set pwm header
  Wire.write(spda);              // send pwma
  Wire.write(spdb);              // send pwmb  
  Wire.endTransmission();      // stop transmitting
}

void fre_pre(unsigned char pres)
{  
  Wire.beginTransmission(MOTORSHIELDaddr); // transmit to device MOTORSHIELDaddr
  Wire.write(SETFREQ);        // set frequence header
  Wire.write(pres);           //  send prescale
  Wire.write(val);            //  need to send this byte as the third byte(no meaning)
  Wire.endTransmission();
}

void change_adr(unsigned char new_adr, unsigned char save_or_not)
{
  Wire.beginTransmission(MOTORSHIELDaddr); // transmit to device MOTORSHIELDaddr
  Wire.write(CHANGEADDR);        // change address header
  Wire.write(new_adr);              //  send new address
  Wire.write(save_or_not);          //   save the new address or not
  Wire.endTransmission();    //
  delayMicroseconds(100); //this command needs at least 6 us
}

void channel(unsigned char i4) //0b 0000 I4 I3 I2 I1
{
  delayMicroseconds(4);
  Wire.beginTransmission(MOTORSHIELDaddr); // transmit to device MOTORSHIELDaddr
  Wire.write(CHANNELSET);        // channel control header
  Wire.write(i4);                // send channel control information
  Wire.write(val);               // need to send this byte as the third byte(no meaning)
  Wire.endTransmission();
}
void motorAndspd( unsigned char motor_s,unsigned char Mstatus, unsigned char spd)
{
  Wire.beginTransmission(MOTORSHIELDaddr); // transmit to device MOTORSHIELDaddr
  Wire.write(motor_s);        // motor select information
  Wire.write(Mstatus);        // motor satus information
  Wire.write(spd);            //  motor speed information
  Wire.endTransmission();
}

void setup()
{
  Wire.begin(); // join i2c bus (address optional for master)
  delayMicroseconds(10); //wait for motor driver to initialization
}

void loop()
{

  motorAndspd(0xA1,0B01,225);
  motorAndspd(0xA5,0B01,30);
  delay(2000);

  motorAndspd(0xA5,0B10,225);
  motorAndspd(0xA1,0B10,30);
  delay(2000);

  change_adr(0x12, NOTSAVEADDR );
  MOTORSHIELDaddr = 0x12;

  for( int i = 0;i< 16;i++)
  {
    fre_pre(i);
    channel(i);
    delay(100);
  }
  speedAB(100 , 100); // was 0 , 0
  change_adr(0x28,NOTSAVEADDR );
  MOTORSHIELDaddr = 0x28;

  while(1)
  {
    channel(0b00001010);
    delay(500);
    channel(0b00000101);
    delay(500);
  }
 }


Arduino Ethernet shield illustrates inner workings of servers

Arduino Ethernet Shield
With the Arduino Ethernet shield that I recently purchased I have been doing a lot of programming involving making a web page. The pages that I have programmed are somewhat simple and use all of the usual HTML tags but since i'm not using any server at all this has been very interesting. My current setup for the arduino web server on the robot is using the Ethernet shield as an adapter to send the code over the internet via a wireless router. Why I think this is so cool is that it is just like a real server in the sense that it is giving information to a user's computer. I have set up servers before and I have designed web pages to go on them but part of programming them to run from the arduino shows something that most people never think of. When you learn how a website works; how a server sends the information to your browser you don't usually think about what it takes beyond a few HTML and PHP files to generate the webpage that you are looking at. With the arduino relay shield you can see in the code that it really is sending the information.

This is a sample of the code that I have been talking about:


   client.println("<html><head><title>arduino web page</title></head><body>");
   client.println("<h1>Example Web Page</h1>");
   client.println("<p>This is some page text.</p>");
   client.println("<p>You should visit http://robotrecycled.blogspot.com for more information.</p>");
   client.println("</body></html>")

This code is sent by the Arduino and received by a user's browser and is indistinguishable from any other webpage that could be displayed by a real server. I thought it was interesting because the " client.println " part that tells the Arduino to send the code to the user's browser is actually visible. Normally servers handle these requests using separately installed software but with the Arduino it is actually the worlds smallest server!

Glossy and 3D Arduino Logos collection

I was doing some experimenting today with Gimp. Gimp is a great and free alternative to applications like Adobe Photoshop. I have been meaning to make a "Powered by" button for Arduino products since I just so happen to have a six foot tall humanoid robot that uses one. For all its worth the Arduino that Salvius uses as a brain is probably the most important piece of robotic hardware that I have. And so... that leads me into this: my new "Powered by" button for Arduino products:
Powered by Arduino button made with Gimp

 I was very happy with how the glossy effect of the button came out. After I finished I decided to experiment with adding some different gradients to the arduino logo to make it more interesting:

Original Arduino logo

Arduino logo with a light colored gradient

Arduino logo with blue to red gradient

Arduino logo with black to red gradient.

I thought that the gradients were a nice touch. I used the light colored one on my "Powered by" button. As for the others I was trying to place the colors in relation to the positive and negative polarity symbols. The last thing that I tried was adding a bevel around the edge of the logo so that it would have a 3D appearance.

3D Arduino logo


Also feel free to use any of these for your own purposes, hopefully you can get some good use out of these graphics if you are doing a project with an Arduino Product.

Please note that the Arduino logo is a Trade Mark of Arduino which has no affiliation at this time with the robot that I am building and writing about on this site.

Using the Grove - L298 Dual H-Bridge I2C Motor Driver with Arduino

Grove - L298 Dual H-Bridge I2C Motor Drive

These are the specifications that I used from the http://www.seeedstudio.com/wiki/index.php?title=Grove_-_I2C_Motor_Driver
  • Default address: 0x28 
  • Grove compatible 
  • I2C interface 
  • Changable slave address 
  • Speed control: proportional 8-bit 
  • Number of channels: 2 
  • Maximum output per channel: 2A 
  • Input/output voltage on I2C bus: 5v 
  • Input voltage on screw terminals: 6v-15v 
 NOTE: Input voltage on screw terminals is regulated to 5v and connected to I2C +5v via a jumper (J4). Remove jumper if both external power via the screw terminals and power via the I2C header is used. Use jumper if 5v should be supplied to the I2C bus.

I removed the jumper because I am going to be using a larger voltage supply to power the motors.

One of the issues I ran into with connecting the motor controller to the arduino is that I don't have a Grove Base Shield to connect my Arduino Uno to the motor controller. I had to do some research because I had no idea what pins to plug the motor controller into on the Arduino board. I came up with some useful information. The wire library for the Arduino programming enables communication with I2C / TWI devices. On most Arduino boards, SDA (data line) is on analog input pin 4, and SCL (clock line) is on analog input pin 5. On the Arduino Mega, SDA is digital pin 20 and SCL is 21. Since I am currently using the Uno I will go with the pin 4 option.

Robot Web Based Remote Control

I have been working a lot lately on making it so that I can control Salvius using a wireless internet connection. I still have not finished hooking up the motors and the motor controller but I have managed to get the wireless control code working enough to turn the robot's headlights on and off. More on the relay shield that I used can be found here: http://www.seeedstudio.com/wiki/index.php?title=Relay_Shield


And as always because Salvius is an open source robot here is the code as seen working in the video:


/*  Programmer: Gunther Cox
    http://robotrecycled.blogspot.com
    Created: 12/25/11
    Last Modified: 02/25/12
    Hardware setup instructions:
 
    Plug Ethernet shield into Arduino Uno.
    Plug Seeed Relay Shield into Ethernet Shield.
    Attach 9 volt power supply to GND and +9V plugs of Relay Shield.
    PIR + to arduino 5V, PIR - to arduino GND, PIR OUT to HUB2 D3.
    Connect ethernt shield to wireless router with ethernet cable.
     
    Parts of this code is based on work done by others:
    * Button controls based on code by Minde
    * Navigation buttons based on work by Su Ray Sh
*/

#include <SPI.h>
#include <Client.h>
#include <Ethernet.h>
#include <Server.h>
#include <Udp.h>

// change these to fit your setup:
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x00, 0x0F }; // physical mac address
byte ip[] = { 192, 168, 1, 177 };             // ip in lan
byte gateway[] = { 192, 168, 0, 1 };     // internet access via router
byte subnet[] = { 255, 255, 255, 0 };                //subnet mask

  // Initialize the Ethernet server library
  // with the IP address and port you want to use
  // (port 80 is default for HTTP):
  EthernetServer server(80);

byte sampledata=50;            //some sample data - outputs 2 (ascii = 50 DEC)

int pirPin = 3;    // input pin (for PIR sensor)
int relayPin1 = 4; // relay connected to digital pin 4 (D3 on relay shield - on switch)
int relayPin2 = 7; // relay connected to digital pin 5 (D2 on relay shield) - Inferred LEDs
int relayPin3 = 6; // relay connected to digital pin 6 (D1 on relay shield) - Ultraviolte LEDs
int relayPin4 = 5; // relay connected to digital pin 7 (D0 on relay shield) (not used)
//pin 10 - reserved for ethernet shield
//pin 11 - reserved for ethernet shield
//pin 12 - reserved for ethernet shield
//pin 13 - reserved for ethernet shield

// Begin variables for motion sensor
//int pirState = LOW; // we start, assuming no motion detected
//int val;            // variable for reading the pin status
//int pirMode = 0;    // determines if the relay closed already (0 = not closed yet)
// End variabled for motion sensor

String readString = String(30); //string for fetching data from address
boolean FORWARD = false; //relay status flag
boolean BACKWARD = false; //relay status flag
boolean LEFT = false; //relay status flag
boolean RIGHT = false; //relay status flag
boolean LEDON = false; //LED status flag
boolean LED2ON = false; //LED status flag
void setup(){
//start Ethernet
  Ethernet.begin(mac, ip, gateway, subnet);
  pinMode(relayPin3, OUTPUT);  //Set pin 7 to output
  pinMode(relayPin4, OUTPUT);

//  pinMode(pirPin, INPUT);        // declare sensor as input
  pinMode(relayPin1, OUTPUT);    // declare relay1 as output
  pinMode(relayPin2, OUTPUT);    // declare relay2 as output
  pinMode(relayPin3, OUTPUT);    // declare relay3 as output
  pinMode(relayPin4, OUTPUT);    // declare relay4 as output

  //digitalWrite(relayPin1, LOW);
  //digitalWrite(pirPin, LOW);
  //pirState = digitalRead(pirPin); // read the initial state
  //delay(60000);                   // pause before calibrating
}

void loop(){
// Create a client connection
EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
   if (client.available()) {
    char c = client.read();
     //read char by char HTTP request
    if (readString.length() < 100) {
        readString += c; //store characters to string
      }
     
        if (c == '\n') {  //if HTTP request has ended
       
          if (readString.indexOf("?") <0) //dirty skip of "GET /favicon.ico HTTP/1.1"
          {
            //skip everything
          }
          else
       
          // begin drive control
          if(readString.indexOf("N1=Forward") >0)
           {
             //item has to be turned ON
             digitalWrite(relayPin1, HIGH);    // set the item on
             FORWARD = true;
           }else{
             //item has to be turned OFF
             digitalWrite(relayPin1, LOW);    // set the item off
             FORWARD = false;          
           }
         
           if(readString.indexOf("N2=Backward") >0)
           {
             //item has to be turned ON
             digitalWrite(relayPin2, HIGH);    // set the item on
             BACKWARD = true;
           }else{
             //item has to be turned OFF
             digitalWrite(relayPin2, LOW);    // set the item off
             BACKWARD = false;          
           }
         
           if(readString.indexOf("N3=LEFT") >0)
           {
             //item has to be turned ON
             digitalWrite(relayPin3, HIGH);    // set the item on
             LEFT = true;
           }else{
             //item has to be turned OFF
             digitalWrite(relayPin3, LOW);    // set the item off
             LEFT = false;          
           }
         
           if(readString.indexOf("N4=RIGHT") >0)
           {
             //item has to be turned ON
             digitalWrite(relayPin4, HIGH);    // set the item on
             RIGHT = true;
           }else{
             //item has to be turned OFF
             digitalWrite(relayPin4, LOW);    // set the item off
             RIGHT = false;          
           }
          // end drive control
       
          //lets check if LED should be lighted
        if(readString.indexOf("L=ON") >0)//replaces if(readString.contains("L=1"))
           {
             //led has to be turned ON
             digitalWrite(relayPin3, HIGH);    // set the LED on
             LEDON = true;
           }
           else if(readString.indexOf("L2=ON") >0)//replaces if(readString.contains("L2=1"))
           {
             //led has to be turned ON
             digitalWrite(relayPin4, HIGH);    // set the LED on
             LED2ON = true;
           }
           //led has to be turned OFF
           else{
             //led has to be turned OFF
             digitalWrite(relayPin4, LOW);    // set the LED OFF
             LED2ON = false;
             digitalWrite(relayPin3, LOW);    // set the LED OFF
             LEDON = false;
           }
         
          // now output HTML data starting with standart header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          client.println("<body style=background-color:#FFB880><h1>Web Remote</h1><hr />"); // background color and heading
       
   client.println("<h2>Navigation</h2>");
   client.println("<form method=get name=NAV><table CELLPADDING='10' style=background-color:#CC6600>");
   client.println("<tr><td align=center></td><td align=center><input type=submit name=N1 value=FORWARD></td> <td align=center></td></tr>");
   client.println("<tr><td align=center><input type=submit name=N3 value=LEFT></td><td align=center><input type=submit value=STOP></td><td align=center><input type=submit name=N4 value=RIGHT></td></tr>");
   client.println("<tr><td align=center></td><td align=center><input type=submit name=N2 value=BACKWARD></td> <td align=center></td></tr>");
                  //controlling leds via buttons (address will look like http://192.168.1.177/?L=ON when submited)
          if (LEDON)
          client.println("<tr><td align=center><form method=get name=LED><input type=submit value=OFF></form></td>");
          else
          client.println("<tr><td align=center><form method=get name=LED><input type=submit name=L value=ON></form></td>");

          if (LED2ON)  // begin second LED
          client.println("<td align=center><form method=get name=LED2><input type=submit value=OFF></form></td></tr>");
          else
          client.println("<td align=center><form method=get name=LED2><input type=submit name=L2 value=ON></form></td></tr>");
   client.println("</table></form>");
     
          // Begin print drive status
          if (FORWARD)
              client.println("<font size='4'>DRIVING FORWARD</font>");
           
          else if (BACKWARD)
              client.println("<font size='4'>DRIVING BACKWARD</font>");

          else if (LEFT)
              client.println("<font size='4'>TURNING LEFT</font>");

          else if (RIGHT)
              client.println("<font size='4'>TURNING RIGHT</font>");
           
          else
          client.println("<font size='4'>PROBABLY NOT DRIVING</font>");
          // End print drive status
           
          //printing LED status
          client.print("<font size='4'>LED status: ");
          if (LEDON)
              client.println("<font color='purple' size='4'>ULTRAVIOLET ON</font>");
           
          else if (LED2ON)
              client.println("<font color='red' size='4'>INFERRED ON</font>");
           
          else
          client.println("<font color='grey' size='4'>OFF</font>");
          // end second LED
       
          client.println("<hr />");
          client.println("<hr />");
          client.println("</body></html>");
          //clearing string for next read
          readString="";
          //stopping client
          client.stop();
            }
          }
        }
      }
 }

//void loop() {
//  // code to do auto activation
//  val = digitalRead(pirPin);  // read input value and store it in val
//  if(digitalRead(pirPin) == HIGH) {
//    if (pirMode == 0) {
//      if (val != pirState) {            //look for 2 inconsistant readings
//          // turn main computer on
//        digitalWrite(relayPin1, HIGH);  // sets relay1 on
//        delay(1000);                    // waits for 1 second
//        digitalWrite(relayPin1, LOW);   // sets relay1 off
//        pirMode = pirMode + 1;   // relay has been on    
//        //delay(50);
//      }    
//    }
//  }
//}

Arduino Ethernet Shield MicroSD

I have begun to experiment with my new Arduino Ethernet Shield. The shield itself had a built in miniSD card slot so today I went out and got a  4GB Sandisk microSDHC Card from Staples so that I could see how this works. I haven't gotten anywhere yet with the SD card but I guess it could be extremely useful for holding a database of sensor data or something like that. I have done some research so far and I have found that the Arduino uses digital pins 10, 11, 12, and 13 (SPI) to communicate with the W5100 on the ethernet shield and so these pins cannot be used for general i/o.

I also just want to add that I was very impressed with the SD card because it boasted the following on the front of the package:
      • Water proof
      • Temperature proof
      • Shock proof
      • X-Ray proof

Controlling robot over a wireless internet connection

This is how I made my robot [Salvius] able to be controlled using a wireless internet connection. The process is simple and costs very little if you don't have the parts already. One of the best things about using this method to control your robot is that you don't even need a specific remote control. You can use any wireless enabled device like a phone, iPod, tablet, or laptop computer to control your robot. Also, there will be no need for any programs to be installed on the device you are using as a remote because everything is installed on the robot in a similar configuration to a regular web server. All you have to do is type a URL in your address bar and press enter.

WiFi-Enable Your Robot!

For this project you will need:

I purchased these parts from Trossen Robotics. They are an online vendor for robotic parts and I have found that they have a great selection. You can visit their site at: http://www.trossenrobotics.com.
For this example I will be showing you how to simply turn an LED on and off by using a web browser. I will post updates for doing this with more complex parts like motor controllers in a later post.

Here is a picture of this working:
LED off

LED on
In the photos the arduino is programmed to render a web page that has two buttons; one turns the LED on and the other turns it off.

Here is the code for the Arduino:


/*
        The circuit:
* Arduino Uno
        * Arduino Ethernet shield
        * LED connected to GND and pin 5
     
     
        This code is based on work done by Minde
        http://www.sciencprog.com/
*/

#include <SPI.h>
#include <Client.h>
#include <Ethernet.h>
#include <Server.h>
#include <Udp.h>

// change these to fit your setup:
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0D, 0x00, 0x0F }; // physical mac address
byte ip[] = { 192, 168, 1, 177 };             // ip in lan
byte gateway[] = { 192, 168, 0, 1 };     // internet access via router
byte subnet[] = { 255, 255, 255, 0 };                //subnet mask

EthernetServer server(80);                           //server port

byte sampledata=50;            //some sample data - outputs 2 (ascii = 50 DEC)          
int ledPin = 5;  // LED pin
String readString = String(30); //string for fetching data from address
boolean LEDON = false; //LED status flag
void setup(){
//start Ethernet
  Ethernet.begin(mac, ip, gateway, subnet);
  pinMode(ledPin, OUTPUT);  //Set pin 4 to output
  Serial.begin(9600);  //enable serial data print
}
void loop(){
// Create a client connection
EthernetClient client = server.available();
  if (client) {
    while (client.connected()) {
   if (client.available()) {
    char c = client.read();
     //read char by char HTTP request
    if (readString.length() < 100)
      {
        //store characters to string
        readString += c; //replaces readString.append(c);
      }
        //output chars to serial port
        Serial.print(c);
        //if HTTP request has ended
        if (c == '\n') {
          //dirty skip of "GET /favicon.ico HTTP/1.1"
          if (readString.indexOf("?") <0)
          {
            //skip everything
          }
          else
          //lets check if LED should be lighted
        if(readString.indexOf("L=ON") >0)//replaces if(readString.contains("L=1"))
           {
             //led has to be turned ON
             digitalWrite(ledPin, HIGH);    // set the LED on
             LEDON = true;
           }else{
             //led has to be turned OFF
             digitalWrite(ledPin, LOW);    // set the LED OFF
             LEDON = false;          
           }
          // now output HTML data starting with standart header
          client.println("HTTP/1.1 200 OK");
          client.println("Content-Type: text/html");
          client.println();
          client.print("<body style=background-color:#FFB880>"); // background color
          client.println("<h1>Web Remote</h1>");          //send first heading
          client.println("<hr />");
       
          //controlling led via checkbox
          client.println("<h2>LED Control</h2>");
          //address will look like http://192.168.1.110/?L=1 when submited
          if (LEDON)
          client.println("<form method=get name=LED><input type=submit name=L value=ON CHECKED><input type=submit value=OFF></form>");
          else
          client.println("<form method=get name=LED><input type=submit name=L value=ON><input type=submit value=OFF></form>");
          //printing LED status
          client.print("<font size='4'>LED status: ");
          if (LEDON)
              client.println("<font color='green' size='4'>ON");
          else
              client.println("<font color='grey' size='4'>OFF");  
          client.println("<hr />");
          client.println("<hr />");
          client.println("</body></html>");
          //clearing string for next read
          readString="";
          //stopping client
          client.stop();
            }
          }
        }
      }
 }  

Older Post ►
 

Copyright 2011 robot recycled parts is proudly powered by blogger.com