Sunday, December 23, 2012

Arduino Line Follower part 1: H Bridge

I thought I would build an Arduino based Line Follower using a couple of DC motors so that it can move around a bit quicker than the servo motor based sumo bots. Here I will discuss the basic platform construction.
Parts List:
9 cm x 15 cm dense 5mm plastic
Solarbotics GM8 Gear Motor (143:1), 6V, 80r/min x 2
Solarbotics 69mm GMPW wheel x 2
Solarbotics GMB28 metal bracket x 2
4-40 bolt, 3/4 inch x 4
4-40 bolt, 1/2 inch x 4
4-40 nut, x 8
6mm standoff x 4
4AA battery holder
22 gauge hook up wire
2N3904 x 8
1k ohm x 8
Arduino Uno
DFRobot ProtoShield
nylon bolt (found)

Attach the mounting brackets to the motors. The motors are mounted such that the axle line is 5 cm from the rear of the platform using 1/2 inch bolts and nuts. Take care to mark and drill holes so that the wheels end up true and parallel. The wiring tabs on the motors are delicate so carefully hook and pinch your wires in place and solder quickly so as not to over-heat them. Use cable ties to secure the wires to the body of the motor so that any further strain is kept away from the tabs. I used an old nylon bolt (found) for the third idler wheel at the front.


I hot-glued a popsickle stick between the motors and glued the battery holder on top. I also added a small found DPST slide switch onto the battery holder so that I can easily switch the unit on and off. Most of the weight is over the axle line so that later on it can turn its nose easily to find the line.



After mounting the Arduino in place I considered the H Bridges needed to interface to the motors. I did not have any spare 293 chips on hand but I did have lots of 2N3904 transistors. I drew out the H bridge schematic on a scrap of paper and messed around with setting up the breadboard. I realized that the 4 transistors could be lined up, 2 facing one way and 2 facing the other such that the last leg of one transistor overlapped the first leg of the next. Thus: E B C-E B C-C B E-C B E. The 2 outer Es go to ground and the C-C connected to Vin (6V). C-E and E-C connect to the motor and each B connects to a 1K resistor. It's a simple matter to make sure the other ends of the resistors pair up.


Building 2 of these circuits on a tiny breadboard became possible. The wiring is not very neat but with colour coding and careful planning it is fairly robust and easy to trouble shoot. Here is the same circuit drawn as clearly as possible using Fritzing:
In this diagram again you can see how the transistors are essentially in a line with the last leg of one connected to the first on the next. 

Here is the code I used to test the motors. Each motors accelerates from minimum (80) to maximum (255) and then decelerates back to minimum first in one direction and then the other. Notice that I made sure each transistor is fully off before moving on. Remember that turning on both inputs to the H bridge will short out your power supply!

/* M Druiven, Dec. 23, 2012
   This program tests 2 DC motors connected to 2 H bridges.
   M1 is controlled from analog out pins 5 and 6.
   M2 is controlled from analog out pins 10 and 11. */

int M1F = 5; // motor 1 forward
int M1R = 6; // motor 1 reverse
int M2F = 10; // motor 2 forward
int M2R = 11; // motor 2 reverse

void setup()  { 
  // Make sure everything is off
  analogWrite(M1F, 0);
  analogWrite(M1R, 0);
  analogWrite(M2F, 0);
  analogWrite(M2R, 0);

void loop()  { 
  // fade M1 in from min to max in increments of 5 points:
  for(int fadeValue = 80 ; fadeValue <= 255; fadeValue +=5) { 
    analogWrite(M1F, fadeValue);           
    delay(20);                            
  } 
  // fade out from max to min in increments of 5 points:
  for(int fadeValue = 255 ; fadeValue >= 80; fadeValue -=5) { 
    analogWrite(M1F, fadeValue);          
    delay(20);                            
  } 
  analogWrite(M1F, 0); // reset output to off
  //************************************************************
  
  // fade M1 in reverse from min to max in increments of 5 points:
  for(int fadeValue = 80 ; fadeValue <= 255; fadeValue +=5) { 
    analogWrite(M1R, fadeValue);           
    delay(20);                            
  } 

  // fade out from max to min in increments of 5 points:
  for(int fadeValue = 255 ; fadeValue >= 80; fadeValue -=5) { 
    analogWrite(M1R, fadeValue);          
    delay(20);                            
  } 
  analogWrite(M1R, 0);
  //***********************************************************
  
  // fade M2 in from min to max in increments of 5 points:
  for(int fadeValue = 80 ; fadeValue <= 255; fadeValue +=5) { 
    analogWrite(M2F, fadeValue);           
    delay(20);                            
  } 

  // fade out from max to min in increments of 5 points:
  for(int fadeValue = 255 ; fadeValue >= 80; fadeValue -=5) { 
    analogWrite(M2F, fadeValue);          
    delay(20);                            
  } 
  analogWrite(M2F, 0);
  //**********************************************************
  
   // fade M2 in reverse from min to max in increments of 5 points:
  for(int fadeValue = 80 ; fadeValue <= 255; fadeValue +=5) { 
    analogWrite(M2R, fadeValue);           
    delay(20);                            
  } 
  // fade out from max to min in increments of 5 points:
  for(int fadeValue = 255 ; fadeValue >= 80; fadeValue -=5) { 
    analogWrite(M2R, fadeValue);          
    delay(20);                            
  } 
  analogWrite(M2R, 0);
}



Sunday, November 4, 2012

Opening a new school

 
During the last 2 years we have been planning the move from EC Drury High school to a new building called Craig Kielburger Secondary School. Last June we packed our classrooms into boxes and during August and September we've been unpacking and setting up. The construction crew left just a week before classes started and you could still see their dusty footprints on the floor on the first day of classes. The last few weeks have been a daily dose of 'real world' meets 'architects dreams'.
   The move from EC Drury to Craig Kielburger Secondary School, CKSS, was a rare one in that the board closed the whole school and moved the entire staff, all the programs and most of the books, computers, basketballs and paint brushes to the new building. The good old Drury culture has been rebranded as the new CKSS culture. This has allowed us to concentrate on the physical space since most of our procedures, rules, ongoing discussions and chemistry are already in place. The old school was physically integrated with the EC Drury School for the Deaf. That building is old and small, spread out over several buildings on a campus. The School for the Deaf is still there and the old high school classrooms are temporary housing for elementary students. Milton is growing so fast that they can't build elementary schools fast enough to house all the students. The new CKSS building is a single modern structure with a beautiful 2 1/2 story main hallway full of flags and a living wall, a triple gym, a nice theatre and lots of warm sunlight everywhere.
   Plans to move the 'Robotics Lab' at Drury to the new digs at CKSS started a couple of years ago with the architect drawing up the plans. The 1500 square foot Drury lab could not be replicated and so it was replaced with a computer lab right next to a 'lab' featuring a passage door between the 2 classrooms. I'm not sure if I want to continue calling the new lab 'Robotics'.  Hacker-Space, Engineering Lab, Maker Lab and Digital Hub are other names that spring to mind. The main idea is that the 'lab' is a flexible space that can be modified on the fly depending on the subject and work being done that period. The mini machine shop at Drury did not make it however a couple of the machines, the engine lathe and the vertical mill have been set up in the new AutoBody shop at CKSS. The spacious old storage closet was forgotten so we created the same amount of storage by replacing the architects puny shelves with full size kitchen cupboards in both rooms. The cupboards were manufactured by our own students last spring. The 'lab' houses our CNC Router, CNC mill and a newly refurbished CNC lathe. We have compressed air for cleaning and powering a solder extraction station. The work benches have been moved in along with our Smart Board.
   Today we are able to run Technological Design and Computer Technology classes in the same period, switching the classes between the 2 rooms depending on the type of work the students need to do that day. Students in the "lab" have access to 12 laptops and a few old desktop computers.

This is the Computer lab:
This is the "Lab":
   Its a new building and new classrooms but the program remains unchanged. The students in our ICT SHSM program are earning CISCO certifications as a part of their high school program. The grade 12 Computer Studies class is learning to program games for the XBox. They are as keen as ever to continue their learning and enjoy working in the new rooms as much as they did in the old. On Friday I was still unpacking boxes so the place still feels unfamiliar to me. I guess its just a matter of time (and a few more minor modifications like paint on the cupboards) and a name. What do you think? Robotics? Hacker? Maker? Hub? Engineering?

Monday, August 6, 2012

Raspberry Pi up and running

I received a Raspberry Pi computer about a month ago and had to put it aside to teach a summer course.  I also wanted some time to look around for a used monitor with an HDMI input since the RPi provides HDMI and composite outputs. It looks like HDMI monitors are fairly rare birds in North America so I settled for a Sabrent HDMI to VGA converter. At first I had trouble getting any output onto the VGA monitor but with a little bit of work I managed to get some fuzzy text going. The Linux Raspian "wheezy" OS gives you an initial setup screen. I did not pay close enough attention to it and so the keyboard is not configured correctly. I had to work through several discussion topics to learn how to edit the config.txt file to get a decent 1024 x 768 display. Now I'm learning how to add applications to the system - not an intuitive task and reconfigure the keyboard.
The RPi computer is a small single circuit board computer so you need to supply power, 5V 1A, to the micro USB power port. Mouse and a keyboard are no problem on the 2 USB ports. We all have SD cards laying around but the RPi requires a class 4 card. The SDRAM provides all the storage while the card/computer houses 256 Mb RAM.

Once you have all the pieces this computer works just as it should with an HDMI monitor. HDMI monitors are rare in Canada. I can purchase cheap used 4:3 LCD VGA monitors and even have a spare around the house. Since my budget was $100 I could not afford a new HDMI type monitor, they start at around $150. The adapter is my work around but, naturally, getting it to work was another problem. I think the lack of a VGA adapter is going to slow down interest in the RPi in North America. So after an initial setup using my daughter's TV (with HDMI input) I was able to get a very poor resolution output onto the VGA monitor using the HDMI to VGA adapter. From there some reading on line led me to a helpful post called setting up HDMI output. I altered the config.txt file several times until I found the best setting: hdmi_group=2 and hdmi_mode = 0x10. The config.txt file is best edited from the root terminal using nano /boot/config.txt (ctrl x, Y then enter - after making changes).

Some more reading led me to another useful post called Helpful Instructions for New Users where I learned the command dpkg-reconfigure keyboard-configuration to change back to a good old USA PC101 keyboard.

List of parts:

  1. $57.59  RPi board.
  2. $20.33  5V 1A USB power adapter.
  3. $60.14  Sabrent HDMI to VGA adapter.
  4. $03.93  HDMI cable.
  5. $14.68  Class 4 16GB SD card.
  6. $0          USB A to micro USB B cable.
  7. $0          Keyboard.
  8. $0          Mouse.
  9. $0          VGA Monitor.

Total $156.67
- includes tax, currency conversion and shipping charges.
- 0$ items found surplus

.....now on to learning Linux. If apt-get or Synaptic Package Manager don't get it and the installer is on the website then how do I install it?

.....here is an interesting interview with Raspberry Pi creator Eben Upton about the state of Computer Studies in the UK.

Tuesday, June 5, 2012

Awards and bursaries for High School Students.


Many companies 'give back' in many ways and if you do then good on you. If you are looking for a way to 'give back' think about this.

If you have made a connection with your local high school Computer teachers and are thinking about ways to help out then here's an idea. You can help encourage students to go on in Computer Studies, Computer Technology or Robotics by offering the school an award or bursary for one of their top ranking students in this area. Right now we offer one school generated award, a plaque, for the top ranking student in Computer Studies. These students often tough it out for 3 or more courses in a room many other students dismiss as a place for geeks. Of course these other students don't realize that the so called geeks will be driving sports cars and setting trends that they will then follow. I think it would be cool if Computer Studies and Technology students got a little recognition and encouragement from the community. A small amount of money every year puts your companies name out into the community.

What do I want to see on the wall when I walk into a company office? A Coop appreciation certificate showing that the company takes on High School Coop students and a picture of a CEO shaking some young persons hand while looking at a certificate and cheque. That's a company that gives back to their community.


Sunday, June 3, 2012

Cool use of Smart phones in the classroom

In their grade 12 summative students had to design, build and test a complex (series/parallel) circuit that included 2 IR LEDs. The big question of course was "How do we know it is working." Simple, turn on your smart phone camera and look at the LEDs through the camera. Since modern CCDs see into the near infra red the students could see the magically glowing LEDs on their phones when, to the naked eye, they appeared to be off.

2D LED Matrix Summative challenge

A 2 day independent summative challenge this year was to use an Arduino, Stamp or OOPic to program an LED matrix to show the students' initials.
Good: One initial.
Better: 2 initials, alternating.
Best: 2 initials scrolling.


3x3x3 LED cube.

I always wanted to try this project out. We just followed some of the examples on line and had terrific results. Here you can see one programmed to scan through all the LEDs.

Thursday, May 3, 2012

Spartan Robotics team all time best

I spent all day Monday and Tuesday this week supervising a 4 student robotics team at the Ontario Skills competition in Waterloo. This was the culmination of 8 months of work after school helping the students design and build their entry. You can see some of the action on YouTube. The RC robots needed to pick up wooden blocks and place them onto the rolling target, the higher up the more points earned.


Competing in this event taught the students more than they will ever learn in a regular course. Every year, after months of after school meetings full of trials, plans, building and testing I begin to despair in March. It never looks like the robot will be ready, that the team is together, that the robot will fast enough or strong enough to last through even a county trial. I start muttering "never again." But every year now for the last 4 years the students have pulled it off and had their entry ready. Sometimes we are working on it on the Saturday before the first county competition! The students organize into a team, each assigned tasks to do. The equipment is tested, parts, tools and batteries are packed into boxes, and for the last two years we've made it to the Ontario level at Waterloo. The growth and learning that happens during this brief interval is phenomenal to watch. Engineering, troubleshooting, planning, observation and tactics come pouring out making me proud of the students and, maybe, open to doing it again next year. Then, playing against a machine that is far bigger, faster and better engineered the team pulls off a win and I go "Yes!", pumping the air and thinking of course, of course we're going at it again next year. Competing at this level reaffirms my faith that I teach the best students in the world.

How did the team do? On Monday the robot broke down and we went home in last place, 19 out of 19. The top 16 teams would continue to the finals on Tuesday afternoon. The team very confidently rebuilt their robot and returned Tuesday morning to fight back into 15th place. On Tuesday afternoon they never gave up despite a deteriorating gripper function and continued to win 50% of the time allowing them to finish in 7th spot.
Here is some video shot with a smart phone: http://www.youtube.com/watch?v=-xwMO6mb9EE&feature=youtu.be

Sunday, April 29, 2012

Who will be our 21rst century heroes?

I took four senior programming students to the ECOO Regional programming competition up at York University on Saturday. 54 teams of 4. Over 200 bright, competent, young people. I know my students are going on to Engineering, Computer Studies and the like in University. I imagine most of the students in that room will do likewise. I thought, "Here was a room full of students with a plan, going forward into decades where they will never want for work. They've made the right choice to learn about the stuff the next few decades will be made of. The right stuff."

Think about it. After WW2 our heroes were the brave young men who flew to the limits of our atmosphere and then beyond to the moon. Remember the movie? http://en.wikipedia.org/wiki/The_Right_Stuff_(film). Who are our 21rst century heroes? I would argue that they are Microsofts' Bill Gates, Apples' Steve Jobs, Googles' Larry Page and Serjey Brin, Facebooks' founder Mark Zuckerberg and so on. These are the people our students aspire to be like, to use their talent to hit the right moment to take the world by storm with the next big app.

And here I was in a room full of just the people who will do it, will become our next heroes. This was it. The real brain trust that would bring wealth and prosperity to our nation in the years to come. Some one among them would be the next Gates or Zuckerberg.  14 of the 54 teams will go on to the Ontario round. 30 of the teams went home with a certificate of appreciation and an experience they will remember for a long time. And all of them should know that they will be our next heroes.

Monday, April 9, 2012

Druiven's Arduino electronics starter kit

This is the basic electronics kit I order from Abra. It allows grade 10 and 11 students to complete many different labs and challenges with the Arduino.

Kit Part pt# quantity price sub
push button PBS-150 1 0.69 0.69
5mm LED, clear
2 0.11 0.22
Bicolor 3 mm LED
1 0.49 0.49
resistor R1/4 390 3 0.05 0.15
resistor R1/4 1 k 2 0.05 0.1
resistor R1/4 10 K 2 0.05 0.1
Variable R 91AR10K 1 1.29 1.29
Red bar display MV57164 1 1.39 1.39
SIP resistor 4610X-101-391 1 0.59 0.59
Photo resistor Photo300 1 0.99 0.99

TOTAL 6.01

Saturday, February 11, 2012

The Move Craig Kielburger Secondary School part 1

Work on the new school is proceeding apace. Dan and I had our first look at what will be our new digs on Feb 1. The 2 rooms pictured here replace the V135 Robotics lab facility at Drury. 1107 will be a Computer Lab and 1108 will be a Technology Lab with workbenches and CNC machines.

Calling V135 "Robotics" was a spontaneous gesture so I'm thinking about the name for 1108. The idea of something like a "Hacker Space" appeals to me but may sound too geeky.