Pages

Wednesday, 13 August 2014

C3Pi: The Teensy and Motor Driver are talking

C3Pi Teensy 3.0 and Motor Driver
At the end of the previous post I let myself get a bit carried away!

C3Pi has always used a Solarbotics motor driver. In the past it's been controlled by an Arduino Pro Mini.

While the software for the Teensy is very similar, I needed to make a couple of changes to the code and more significant changes to the pinout.

Slow and steady

So my rush to solder up some stripbaord was premature. I've breadboarded the circuit instead.

I've now got the Teesny 3.0 controlling it, and the Teensy is controlled by serial input.

Since I've already checked that the Pi can drive the Teensy's serial port, I'm ready to go.

Tomorrow's plan

Tomorrow I will prepare the stripboard, connect the motors and take C3PI for his first outing. Initially I will control C3Pi via ssh over wifi.

Come back tomorrow to find out how the project is going. If you want to meet C3Pi in person, come along to this Saturday's Southend Raspberry Jam. There will be lost of other exhibits and talks, and it's going to be a lot of fun.

Book your free tickets via Eventbrite.


C3PI: the Pi and Teensy are talking



The Pi and the Teensy are talking.

The Teensy is running the fortune cookie sketch. I've been using pyserial on the Pi, and using interactive python.

Here's a screenshot of an ssh session on the Pi:


Next Step

Next I'm going to solder up a mini-stripboard for the Teensy.

C3Pi - the Raspberry Pi meets Teensy 3.0

Teensy 3.0

Yesterday I started to set up the C3Pi's new brains - the Raspberry Pi model B+, with its lower power requirements, extra mounting holes and four USB ports. The USB ports are really useful; while I'm developing the new software, I need to connect a keyboards and mouse,  a wifi dongle and the Teensy 3.0 which will be used for motor control and other tasks.

Teensies rule

If you haven't come across the Teensies they are Arduino-compatible miniature boards developed by Paul Stoffregen. The early Teensies used ATmega chips, but the Teesny 3.0 and 3.1 use ARM processors. Paul has done an amazing job of extending the Arduino IDE and porting many of the libraries to work with the ARM chips. As a result the Teensy family are just as developer-friendly as the original Arduinos.

The main attraction of the Teensy 3.0 is that it's faster, has more I/O, and much more RAM than the Arduino Pro. The fact that the Teensy runs at 3.3 volts is an added bonus, since it's safe to connect GPIO pins directly to the Pi.

Using a Serial USB link

At present, though, I'm using a simple USB connection between the Pi and the Teensy.

C3Pi previously used I2C to link the Pi and an Arduino Pro Mini. That worked, but there are a number of attractions to using a serial link, including physical reliability. The previous C3Pi wiring was based on jumper leads and was prone to intermittent failure, usually during demos. The USB connection should be much more robust.

Checking it out

My first job today was to verify that I could
  1. program the Teensy 3.0 from my workstation
  2. powered the Teesny from one of the Raspberry Pi's USB ports
  3. establish two-way Serial communications between the workstation the Teensy
  4. establish two-way communications between the Teensy and the Pi.
The eagle-eyed will notice that I take baby steps, introducing one change at a time. I love to work that way: progress is slow, but it's steady.

The first snag: serialEvent

The first two checks went fine, but the third test hit an unexpected problem.

I'd decided to use a bit of sample code from my Life after Blink workshop. One of the experiments ends up with a simple fortune cookie server running on the Arduino. You can see a snippet of code below.

 void loop() {  
  // print the string when a newline arrives:  
  if (reply) {  
   int index = (int) random(MAX);  
   Serial.println(greetings[index]);  
   reply = false;  
  }  
 }  
 void serialEvent() {  
  while (Serial.available()) {  
   // get the new byte:  
   char c = (char) Serial.read();  
   if (c == '\n') {  
    reply = true;   
   }   
  }  
 }  

I uploaded the full sketch to the Teensy and opened the Arduino serial terminal. It locked up.

After a series of experiments, I found that serial comms was working fine but serialEvent does not seem to be supported on the Teensy. When I folded the body of serialEvent into my loop the code worked perfectly.

 void loop() {  
  // print the string when a newline arrives:  
  while (Serial.available()) {  
   // get the new byte:  
   char c = (char) Serial.read();  
   if (c == '\n') {  
    reply = true;   
   }   
  }  
  if (reply) {  
   int index = (int) random(MAX);  
   Serial.println(greetings[index]);  
   reply = false;  
  }  
 }  

What next?

My next step will be to connect the Teensy to the Pi and see if I can drive the cookie server on the Teensy using a terminal on the Pi.

Watch this space!


Tuesday, 12 August 2014

C3Pi gets a wifi update

C3Pi B+ Pi, Quick2Wire board and downverter
I'm busily working on C3Pi ready for his outing to the Raspberry Jam at Southend this Saturday.

I'll be setting up my own mini-wifi network, but sometimes wifi doesn't work as it should. I need a way of configuring the Pi that doesn't rely on networking, just in case.

When the Raspberry Pi model B+ first came out I built a downverter - a cable which links the 40-pin header on the B+ to the old-style 26-way connectors. I linked it to a Quick2Wire interface board and plugged in an FTDI cable, which I connected to my laptop's serial port.

Once I'd installed gkterm on the laptop I could log in to C3Pi using the serial console. So now I have a safety net! I don't think I'll need it, as I've also got the laptop, my phone and C3Pi chatting away happily on the private network, but it's good to know I've got options.

I'm hoping to control C3Pi via a tablet or phone at the Jam, and for the next three days I'll be blogging about progress as I go.

There are still tickets left for this Saturday's Jam. Get yours here.


Monday, 11 August 2014

C3Pi gets a Raspberry Pi B+ and a face lift

C3Pi+

C3Pi, the tracked robot that I've been working on for several years, just got a new brain: a Raspberry Pi model B+.

The old version used a Model B with an Arduino micro. This one will probably use a Teensy 3.0 as the Pi's companion.

(Less) Power to the Raspberry Pi

The main reason for upgrading the Pi is the reduced power consumption, but the extra mounting holes also appealed.

I took the opportunity of replacing C3Pi's old stripboard top with a proper pololu board, and the result looks much neater.

I've added the motor controller which also provides a regulated 5v supply. My next job is to make a small circuit board to hold the Teensy and provide connection points to the Pi and the controller.

C3Pi at Southend - Saturday 12 August

C3Pi will be making an appearance at Southend this Saturday. The Southend Raspberry Pi Jammers are holding a big summer meeting, and C3Pi will be one of the many attractions. Book your tickets here!