Boardgame Saturday

December 14, 2011 by · Leave a Comment 

We going to have a boardgame session this Saturday, we have game brought in by Chee Leong, one of our geeky friend.

Event: Boardgame Saturday

Date: 17 December 2011

Time: 11:00 – Before sun down, maybe

Agenda:  we will play the game below;

  • Battlestar Gallectica the Board Game (it’s a game of surviving and betrayal)
  • Bang! The Bullet (western shootout with some suspense element)
  • Power Grid (management and mathematics)

 

Anyone is welcome to join. And we will continue until we decide to done. Interested in these game. JOIN US ON THIS SATURDAY!!!!

p.s I have posted there event on facebook for sometime, I just forget to put it here. sorry
https://www.facebook.com/events/295891067105754/

Share this article

Making a Robot With Arduino Bonus Material: NewSoftSerial

November 19, 2011 by · Leave a Comment 

This is the last post of the robot adventure. Along the way, I am debugging the robot, and realized that the zigbee is hijacking the serial port. Once again the arduino community to the rescue. Introducing NewSoftSerial. What this do is, it provide ‘soft’ serial, i.e another serial port to be used for let say, your xbee shield.

A sample usage is below, it is just a relay from the real serial to a soft serial, which I set to run on digital 2 and 4. The seeestudio doc says it can run on digital 11 and 12, but digital 11 and 12 is used by the motor driver. So I set it to use digital 2 and 4.

#include <NewSoftSerial.h>

uint8_t pinRx=2;
uint8_t pinTx=4;
long BaudRate = 57600;

NewSoftSerial mySerial(pinRx,pinTx);

void setup(){
  Serial.begin(BaudRate);
  mySerial.begin(BaudRate);

}

void loop(){
  if(mySerial.available()){
    int val = mySerial.read();
    mySerial.print(val);
    Serial.print(val);
  }
}

It just echo what the hardware serial to the serial I set for the zigbee. As you the library is pretty easy to use. To me anyway. You can download it on that page. And install it like any arduino library.

Share this article

Making a Robot With Arduino Part 5: The PC Program

November 19, 2011 by · Leave a Comment 

The remote control part of the robot already done, now to control it. Because I am out of component. So I decide to write a program to do so. The control program uses python, and it control via serial interface to the arduino, without the microntroller.

Python have many stuff in their standard library, but they don’t have a serial library. On the other hand, python community have created many library that is not in the standard library, pyserial is one http://pyserial.sourceforge.net/. To install it, just use

pip install pyserial

The library is very easy to use too. You need a sleep because sometime the arduino will drop the command if you send it too fast. So just use sleep as a delay. The serial port on windows it is comN, on the constructure replace ‘your serial port’ with a number without quote, it could be 0 for com1, etc. On linux you can specify the path, ‘/deve/ttyUSB0′ or 1 or what not.

import serial
import datetime.time as time
s = serial.Serial('your_usb_serial_port')
time.sleep(2)
s.write('serial command')
s.close()

Essentially just 4 line minus import just to send serial command.

To make it fancy, I just bundle it with tkinter library for UI, which is part of the python standard library.

from Tkinter import *
import serial
import time

class RobotUI:
    def __init__(self,master,port):
        self.port = port
        frame = Frame(master)
        frame.pack()
        self.forward_button = Button(frame,text="Forward",command=self.move_forward)
        self.forward_button.pack(side=TOP)

        self.backward_button = Button(frame,text="Backward",command=self.move_backward)
        self.backward_button.pack(side=BOTTOM)

        self.left_button = Button(frame,text="Rotate Left",command=self.rotate_left)
        self.left_button.pack(side=LEFT)

        self.right_button = Button(frame,text="Rotate Right",command=self.rotate_right)
        self.right_button.pack(side=LEFT)

    def move_forward(self):
        print "forward"
        self.move_('w')

    def move_backward(self):
        print "backward"
        self.move_('s')

    def rotate_left(self):
        print "left"
        self.move_('a')

    def rotate_right(self):
        print "right"
        self.move_('d')

    def move_(self,direction):
        s = serial.Serial(self.port)
        time.sleep(2)
        s.write(direction)
        s.close()

root = Tk()
app = RobotUI(root,2)
root.mainloop()

Again the code for the controller can be found here https://gist.github.com/1378327

Now the robot is complete. And can be used. The last post, is on newsoftserial library for arduino. Not directly related to the robot. I experiment on it as I build it.

 

 

Share this article

Making a Robot With Arduino Part 4: The ZigBee Setup

November 19, 2011 by · Leave a Comment 

For this project we use zigbee series 2, which is both a good thing and a bad thing.

The good thing is, it have more capability. The bad thing is, you rely on x-ctu to configure the zigbee. While it is easy, the problem is, most our member in the space, uses mac, or linux. x-ctu only support windows, to work on linux/mac, one need to configure it on wine. I suppose that it is possible for someone to program it with the serial command sequence. I didn’t see it online on how. There is plenty for the old zigbee though.

Now enough x-ctu rant. Yours truly do have a windows machine fortunately. First get the software here.

Now, I don’t have FTDI for zigbee, so I modify an arduino for it. Here I use a duemilove, just unplug the arduino microcontroller(the long IC). Notice the missing microcontroller? This is so that the usb will send the command to zigbee instead of the atmega microcontroller. Notice the toggle on the zigbee top right, that is the toggle switch for telling it to read from the serial interface. If you move all the toggle switch the the right, you telling it to take over as the arduino serial interface.

Arduino Turn Zigbee programmer

Arduino Turn Zigbee programmer

If you have a seeeduino, upload the following sketch.

void setup()
{
  DDRB=0;
  DDRC=0;
  DDRD=0;
}

void loop()
{ 

}

 

Now start x-ctu, now test for the zigbee. Click on test

x-ctu first page

x-ctu first page

xctu message for the connection is ok

xctu message for the connection is ok

There is a few configuration for zigbee, we just use 2, one is the Coordinator, the other is the Router/End Device. Multiple router will connect to a coordinator. While we have only 2 zigbee, it really doesn’t matter for now. So I just put the Router on the robot.

First set one for Coordinator. First click on read. Under Modem XBee, select XB24-B, Function Set ZIGBEE COORDINATOR AT

xctu coordinator

xctu coordinator

Then we go down to NI, Node Identifier, click on it, there will be a set, click on it. Put a name, here I just put Coordinator. Once you done, click write on the top of the application. You are done.

xctu Node Identifier

xctu Node Identifier

We are done. For the Router, next do the same, but Change from COORDINATOR AT  to ZIGBEE ROUTER/END DEVICE AT

xctu router

xctu router

Again set the name, like above, here I just set ROUTER =.=

xctu router NI

xctu router NI

We are done for zigbee, pretty easy with X-CTU, and the default just works. Now we can plug the router for the robot and coordinator to empty arduino. The arduino code already have the delay necessary for the zigbee command receive or send properly. On the robot, the toggle switch on the top right, all go to the right, now the robot thinks the zigbee is the serial interface.

Bonus Material:

You can do serial command on the zigbee, you can find out more here ftp://ftp1.digi.com/support/documentation/90000866_A.pdf

We use xbee shield from seeestudio with the zigbee. It is pretty good, except inside it says toggle the seeeduino to 3.3v when use. For other arduino, no such toggle exist. It is actually fine, because the shield actually already have a regulator to convert 5V into 3.3V. The robot which uses seeeduino, also run on 5V Because the motor driver.

 

 

Share this article

Making a Robot With Arduino Part 3: The code

November 19, 2011 by · Leave a Comment 

After assembling the robot, Now we can start writing the code for the robot.

From the datasheet of the motor driver. In which I quore

If I1=1and I2=0, the motor rotates clockwise.
If I1=0 and I2=1, it rotates anticlockwise.
If I1=I2,it stops rotating

So we can start testing the controller this way.

//Define pin number
int left_1 = 9;
int left_2 = 8;
int right_1 = 13;
int right_2 = 12;
int speed_left = 10;
int speed_right = 11;
void setup(){
  pinMode(left_1,OUTPUT);
  pinMode(left_2,OUTPUT);
  pinMode(right_1,OUTPUT);
  pinMode(right_2,OUTPUT);
  pinMode(speed_left,OUTPUT);
  pinMode(speed_right,OUTPUT);
}
void loop(){
  analogWrite(speed_left,100);
  digitalWrite(left_1,HIGH);
  digitalWrite(left_2,LOW);
  digitalWrite(left_1,LOW);
  delay(1000);
  analogWrite(speed_right,100);
  digitalWrite(right_1,HIGH);
  digitalWrite(right_2,LOW);
  digitalWrite(right_1,LOW);
  delay(1000);
}
The robot should just move forward and backward, if it doesn’t
  1. Check that the battery is connected properly
  2. Check that the pin is connected properly from motor driver
  3. Check that the EA and EB is plug into PWM, not analog.
  4. and make sure the EA or EB is connected to the right connector.
The analog call to pin 10 and 11, determine the speed of the robot. For the tutorial, you can adjust it anyway you want it.
Now to move direction like the code above is very tedious, so we can split it into functions
int left_1 = 9;

int left_2 = 8;

int right_1 = 13;

int right_2 = 12;

int speed_left = 10;
int speed_right = 11;

void setup(){
  pinMode(left_1,OUTPUT);
  pinMode(left_2,OUTPUT);
  pinMode(right_1,OUTPUT);
  pinMode(right_2,OUTPUT);
  pinMode(speed_left,OUTPUT);
  pinMode(speed_right,OUTPUT);
}

void loop(){
      forward();
      delay(2000);
      halt();
      backward();
      delay(2000);
      halt();
      turn_left();
      delay(2000);
      halt();
      turn_right();
      delay(2000);
      halt();
}

void halt(){
  wheel_halt(right_2,right_1);
  wheel_halt(left_2,left_1);
}

void forward(){
  wheel_forward(right_1,right_2,speed_right);
  wheel_forward(left_1,left_2,speed_left);
}

void turn_left(){
  wheel_forward(right_1,right_2,speed_right);
  wheel_forward(left_2,left_1,speed_left);
}

void turn_right(){
  wheel_forward(right_2,right_1,speed_right);
  wheel_forward(left_1,left_2,speed_left);
}

void backward(){
  wheel_forward(right_2,right_1,speed_right);
  wheel_forward(left_2,left_1,speed_left);
}

void wheel_forward(int pin_1,int pin_2,int spd){
 analogWrite(spd,100);
 digitalWrite(pin_1,HIGH);
 digitalWrite(pin_2,LOW);
}

void wheel_backward(int pin_1,int pin_2){
  digitalWrite(pin_1,LOW);
  digitalWrite(pin_2,HIGH);
}

void wheel_halt(int pin_1,int pin_2){
 digitalWrite(pin_1,LOW);
 digitalWrite(pin_2,LOW);
}
Now we have a more functional code. Which turning left or right, as well as forward backward. Finally just add a touch of serial. Then we are done.
int left_1 = 9;
int left_2 = 8;
int right_1 = 13;
int right_2 = 12;
int speed_left = 10;
int speed_right = 11;
void setup(){
  pinMode(left_1,OUTPUT);
  pinMode(left_2,OUTPUT);
  pinMode(right_1,OUTPUT);
  pinMode(right_2,OUTPUT);
  pinMode(speed_left,OUTPUT);
  pinMode(speed_right,OUTPUT);
  Serial.begin(9600);
}
void loop(){
  int incoming_byte = 0;
  char incoming_char;
  if(Serial.available() > 0){
    incoming_byte = Serial.read();
    incoming_char = char(incoming_byte);
    if(incoming_char == 'w'){
      forward();
      delay(2000);
      halt();
    }
    else if(incoming_char == 's'){
      backward();
      delay(2000);
      halt();
    }
    else if(incoming_char == 'a'){
      turn_left();
      delay(2000);
      halt();
    }
    else if(incoming_char == 'd'){
      turn_right();
      delay(2000);
      halt();
    }
  }
}
void halt(){
  wheel_halt(right_2,right_1);
  wheel_halt(left_2,left_1);
}
void forward(){
  wheel_forward(right_1,right_2,speed_right);
  wheel_forward(left_1,left_2,speed_left);
}
void turn_left(){
  wheel_forward(right_1,right_2,speed_right);
  wheel_forward(left_2,left_1,speed_left);
}
void turn_right(){
  wheel_forward(right_2,right_1,speed_right);
  wheel_forward(left_1,left_2,speed_left);
}
void backward(){
  wheel_forward(right_2,right_1,speed_right);
  wheel_forward(left_2,left_1,speed_left);
}
void wheel_forward(int pin_1,int pin_2,int spd){
 analogWrite(spd,100);
 digitalWrite(pin_1,HIGH);
 digitalWrite(pin_2,LOW);
}
void wheel_backward(int pin_1,int pin_2){
  digitalWrite(pin_1,LOW);
  digitalWrite(pin_2,HIGH);
}
void wheel_halt(int pin_1,int pin_2){
 digitalWrite(pin_1,LOW);
 digitalWrite(pin_2,LOW);
}
Now it is completed. Almost, the code for the arduino is completed. The zigbee shield that we going to use, will hijack the serial interface on the arduino. We essentially just send serial over zigbee anyway. So there is no code need to change on the arduino to use it. Of course there is way to change it, but that is the next post on setting up zigbee.
You can download code from the links : https://gist.github.com/1378327

Share this article

Making a Robot With Arduino Part 2: Assembly

November 7, 2011 by · Leave a Comment 

Sorry for taking so long, there is a lot of picture here.

After showing the motor controller last week, we can start making the robot.

Step 0

Robot Base

Robot Base

This is the robot base, bare only with motor and wheels.

Step 1

Robot base Rearrange Wire

Robot base Rearrange Wire

Notice the hole, it is used to screw in the board and component, and a place to arrange the wire around to make things neat. The wire put in a way we can put it into the motor controller neatly.

Step 2

First Screw Into the hole

First Screw Into the hole

Put the motor controller on the side, where we have arrange motor wire. Under it there is some fasteners already in place. First screw in the first screw into the pre positioned fasteners. Then from it, rearrange the rest of the fasteners, to make fastening of the screw easier.

Installed motor controller

Installed motor controller

It should look this way

Step 3

Motor Wire

Motor Wire

Twist the wire a bit, to make it easy to install into the terminal

Install motor to terminal

Install motor to terminal

Just unscrew the terminal abit, and install the wire, and screw it back. Don’t worry about the direction. If the motor turn reversed. Just reverse the order of wire.

Now do the same for the other motor, on the terminal opposite of this one.

The robot minus arduino

The robot minus arduino

The robot now should look this way

Step 4

Install the arduino

Install the arduino

Now we can install the arduino. There is fastener that I already put in a hole on the robot, to make screw it easy. There is a few hole on the robot, just install into one that fit. You don’t need to screw into all the screw holes on the arduino. Just make sure it secure in place.

Mounted arduino

Mounted arduino

It should be around that way.

Step 5

Now we can start wire up everything.

The arduino wire goes here

The arduino wire goes here

There is a few terminal on that side of the robot. The top 3 pin is the control for one side of the motor, the bottom 3 is for the other side. The middle one is the power for the motor and motor controller

 

EA1 pin to digital 8

I2 pin to digital 9

Connect pin on the motor controller labeled I2 to digital 9,

EA2 to Digital 9

I1 to Digital 8

Now I1 to Digital 8 on arduino.

EA to pin 10

EA to pin 10

The reason for digital pin 10 is because it is also can be use as PWM that is used to control the speed of the motor.

Now do the same for I3, I4 EB on the motor controller. Connect wire from I3 to Digital 12, I4 to Digital 13 and EB to Digital 11 for the PWM.

Step 7

Now connect power output from arduino the motor controller.

Now Connect the wire to power

Now Connect the wire to power

The motor controller need 5v, so we put a wire on 5V.

Connect power to one labelled logic

Connect power to one labelled 5v

The to one from ground, to ground, the middle one.

Step 8

Now connect power to the motor

Connect battery

Connect battery

It is 4 1.5v battery connect together to get 6v. The positive goes to the terminal labeled vms, and negative to ground(the middle one). It shares a common ground, so don’t worry about the existing ground connected to the middle.

Step 9

Finally connect battery to arduino

I just use jst 2 pin from seeeduino

I just use jst 2 pin from seeeduino

We are done for the assembly

Next round, we start writing code.

Share this article

Making a Robot With Arduino Part 1: Intro to Motor Controller

October 24, 2011 by · Leave a Comment 

So from the previous post, we already have a base, with all the thing plugged in.

The big idea, arduino control motor, so we just plug a dc motor into arduino? No? Not so fast, a robot don’t just need to move forward, it also need to move backward, in addition, a robot need to rotate to change direction. Not so easy now isn’t it.

Like many stuff in electronics, there is a component for this. Introducing the The Motor Driver, it make it easy for us to move a motor is both direction, and as it stop, the circuit is cut off, and stop the current from the motor from going back to arduino(it is a good thing ;-) ). Also it control both dc motor, independently.

The motor driver we used is based on the L298N , which is an IC to control it. But we are lazy, so we just buy a ready made controller. To make things easy for us.

The datasheet for the motor driver have the information we need on how to drive a motor on it.

Motor Driver

Motor Driver

That’s all for the motor controller. This is essentially the main component of the robot, along with the arduino. Next post will involve wiring the controller to the arduino, and some test code.

Share this article

Electronics Friday is Off This Week

October 21, 2011 by · Leave a Comment 

Yup, you heard it right, there will be no electronics friday this week, i.e today.

We will going to have electronics friday next week.

Sorry for the late announcement

Share this article

Making a Robot With Arduino Part 0: The Intro

October 17, 2011 by · Leave a Comment 

One of the thing we show case during Hack in The Box is a Arduino powered robot, controlled over ZigBee, i.e this guy.

The plan of this series is

  1. to show you how to make a robot,
  2.  how to control it with arduino, and
  3. how to interface it using ZigBee wireless.
What we going to use
  1. A 2 wheeled robot base, this comes with 2 3-6V DC Motor
  2. Motor Driver
  3. 2 Arduino, one to control the transmitting ZigBee
  4. 2 Zigbee Wireless
  5. 1 9v and 4 1.5v Batteries
  6. Usb Cable for programming the arduino
Lets introduce our first component, the robot base, it only have a frame and 2 motor, and a few hole here and there to allow us to mount and secure components on it. This is what we going to make the robot on.
 Side view of robot base Notice that the component is secured via screw

 

This is the robot base installed with the electronics, basically you install it by screwing the components into the hole on the base, as you can see from the image. The arduino itself have holes for this purpose. There is no special component on the base, the electronics is just what we added ourself.

 

So there is no special requirement to the base,  so you can get it easily from a few source online, such as sparkfun and seeestudio. and there is not even requirement for it to run  on a 3-6v motor. It just that most 2 wheeled robot base comes with it. you just need to adjust the battery needed if you have a different motor. I seriously doubt this is the case.

 

Thats all for part 0, the next post will be about, why you need a motor controller

 

p.s Sorry that I can’t show the empty base, because the wiring can be a mess to put back.
[UPDATE]
Look like there will be a post on assembly after all

 

 

 

 

Share this article

Electronics Friday Cancelled This Week

October 13, 2011 by · Leave a Comment 

Due to all the awesomeness that happen in Hack In The Box 2011. We have to cancel Electronics Friday this Friday. But Electronics Friday will continue as usual next Friday.

So yes there is no activity this Friday.

Share this article

« Previous PageNext Page »

Performance Optimization WordPress Plugins by W3 EDGE

Switch to our mobile site