Teardown of a 12V DC to 110V AC Inverter
November 25, 2011 by klks · Leave a Comment
A few weeks ago as i was browsing eBay i came across this item. It was a 12/24V DC to 110V AC Inverter (5W). Seeing that it was only around RM10, i bought one to rip apart and see its inner workings.
Share this article
Making a Robot With Arduino Bonus Material: NewSoftSerial
November 19, 2011 by sweemeng · 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 sweemeng · 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 serialimport datetime.time as times = 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 sweemeng · 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.
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
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
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.
We are done. For the Router, next do the same, but Change from COORDINATOR AT to ZIGBEE ROUTER/END DEVICE AT
Again set the name, like above, here I just set ROUTER =.=
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 sweemeng · 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 numberint 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);}
- Check that the battery is connected properly
- Check that the pin is connected properly from motor driver
- Check that the EA and EB is plug into PWM, not analog.
- and make sure the EA or EB is connected to the right connector.
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);
}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);}
Share this article
Making a Robot With Arduino Part 2: Assembly
November 7, 2011 by sweemeng · 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
This is the robot base, bare only with motor and wheels.
Step 1
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
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.
It should look this way
Step 3
Twist the wire a bit, to make it easy to install into the 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 now should look this way
Step 4
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.
It should be around that way.
Step 5
Now we can start wire up everything.
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
Connect pin on the motor controller labeled I2 to digital 9,
Now I1 to Digital 8 on arduino.
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.
The motor controller need 5v, so we put a wire on 5V.
The to one from ground, to ground, the middle one.
Step 8
Now connect power to the motor
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
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 sweemeng · 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.
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
Making a Robot With Arduino Part 0: The Intro
October 17, 2011 by sweemeng · 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
- to show you how to make a robot,
- how to control it with arduino, and
- how to interface it using ZigBee wireless.
- A 2 wheeled robot base, this comes with 2 3-6V DC Motor
- Motor Driver
- 2 Arduino, one to control the transmitting ZigBee
- 2 Zigbee Wireless
- 1 9v and 4 1.5v Batteries
- Usb Cable for programming the arduino
Share this article
Electronics Friday 30/09/2011
September 29, 2011 by kakeman · Leave a Comment
Our weekly Electronics Fridays meetup is on from 8:00pm – 11pm, 30 September 2011.
What?
- Weekly get-together to solder, wire, design, etch, and make electronics stuff.
- Learn new skills
- Make a project
- Show, tell and get help (bring your project – advance or simple, it doesn’t matter)
When?
We are usually open as early as 4pm, with a break for dinner at around 7-8pm. And continue on till 10:30 or 11pm. If you want to come earlier, the best time is usually around 6:30 (before we go off for dinner)
Where?
Hackerspace KL
Who?
Everyone is welcome! Even if you are not a member and you want to check out what HackerspaceKL is about, feel free to come.
Cost?
Free for members. Non-members however, cannot use any of our equipments (to be fair, they are paid by the members). Non-members can buy the electronics components from us. We have stuff to sell to – QuarterK, and Seeeduino.
See you guys there!
Share this article
Electronics Friday 23/09/2011
September 21, 2011 by kakeman · Leave a Comment
Our weekly Electronics Fridays meetup is on from 8:00pm – 11pm, 23 September 2011.
What?
- Weekly get-together to solder, wire, design, etch, and make electronics stuff.
- Learn new skills
- Make a project
- Show, tell and get help (bring your project – advance or simple, it doesn’t matter)
When?
We are usually open as early as 4pm, with a break for dinner at around 7-8pm. And continue on till 10:30 or 11pm. If you want to come earlier, the best time is usually around 6:30 (before we go off for dinner)
Where?
Hackerspace KL
Who?
Everyone is welcome! Even if you are not a member and you want to check out what HackerspaceKL is about, feel free to come.
Cost?
Free for members. Non-members however, cannot use any of our equipments (to be fair, they are paid by the members). Non-members can buy the electronics components from us. We have stuff to sell to – QuarterK, and Seeeduino.
See you guys there!





























