Swag from Element14!

Been busy as of late, not much to report project-wise besides a version of my edge-lit lighted display for my Mom’s B-Day

Beyond that, I’ve gotten some cool swag from Element14 Newark!

http://canada.newark.com/

http://www.newark.com/

 

They sent me stickers for Tesla’s birthday

Element14 and Tesla Stickers

 

 

As well as some electronics

Element14 Swag

 

The electronics include:

 

Basys 2 development board

http://www.digilentinc.com/Products/Detail.cfm?Prod=BASYS2

The Basys 2 development kit is a Spartan3 FPGA development kit.  It’s been a long time since I programmed an FPGA and I’m looking forward to getting back into it.

 

An FPGA differs from a microcontroller as you are reprogramming hardware as opposed to just writing a program for your micro to step through and follow.  An FPGA is made up of repgorammable logic cells, usually look up tables or LUTs.  The code (unless otherwise specified) happens in parallel as opposed to step by step in a microcontroller, though you can specify clock edge actions.  You typically code in VHDL or Verilog.  Back in the day, we also used virtual gates like and, or, and nots which the compiler would churn down into those look up tables just the same as VHDL or Verilog.  It looks like that functionality seems to be by the way-side now, the last time I looked at Xilinx’s software I didn’t see an option to put down gates and wire them.

 

Also I received a micro HDMI to standard for my Beaglebone Black

http://uk.farnell.com/pro-signal/cdlhd4-micro-018/cable-assy-hdmi-d-m-to-hdmi-a-m/dp/2305808

 

And lastly a jumper kit

http://uk.farnell.com/multicomp/mcbbj65/jumper-wire-assortment-65pcs/dp/2396146

 

I don’t have exact plans for what I’m going to do with the Basys 2, FPGA’s really excel at memory intensive tasks like image and video processing.  Eventually it might be nice to re-do my school project of a resistive touch pad that draws on a monitor connected via VGA, but I might start a bit slower and do a simple combo lock switched in using the slide switches and buttons.  I’ll post the project and code when its finished.

 

Big thanks to Newark Element14 for the swag and the great community.  Now to prepare for Detroit Makerfaire with Ben Heck!  I’ll make sure to post pics

http://www.makerfairedetroit.com/

 

Homemade CS Go Swag

Ben Heck recently visited a friend from Valve.  He had promised me some cool CS Go swag as I’ve played Counterstrike off and on for many years (since 1.2).  Unfortunately they didn’t have any CS Go swag and we got Portal swag instead, still pretty cool.

 

Well this was our typical tinker-Saturday and I had some new NeoPixels that I got from Sparkfun.  Ben started playing around with them and his acrylics.  He decided to do an edge lit acrylic experiment.  I suggested the CS Go logo so I’d have something cool for my desk.  We found a couple of suitable logos and then Ben edited the best ones into one that would work well for our acrylic.

 

We cut the log on two pieces of acrylic, one clear that appeared to work great for edge lit, and one frosted, which works better to diffuse a backlight.  Ben then 3D printed a base to fit the NeoPixels and the acrylic.  We put them together for some testing and it worked great.  I then took the project home, hooked everything up to my Teensy 2.0 board and modified the code to have a little more functionality so I could switch between the different modes.

 

Here is a video of it in action

 

And here is the Arduino code

NeoPixel data line is Pin2, interrupt is Pin5

#include <Adafruit_NeoPixel.h>

#define PIN 2

// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic ‘v1′ (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(8, PIN, NEO_GRB + NEO_KHZ800);

// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 – 500 Ohm resistor on first pixel’s data input
// and minimize distance between Arduino and first pixel. Avoid connecting
// on a live circuit…if you must, connect GND first.

volatile unsigned int mode;
volatile boolean superBreakout;

void setup() {
strip.begin();
mode = 0;
superBreakout = 0;
pinMode(5, INPUT);
digitalWrite(5, HIGH);
clearWipe();
strip.show(); // Initialize all pixels to ‘off’
delay(50);
attachInterrupt(0, changeMode, FALLING);
}

void loop() {

if ( digitalRead(5) == HIGH){
superBreakout = 0;
}

switch (mode){

case 0:
// Some example procedures showing how to display to the pixels:
colorWipe(strip.Color(255, 0, 0), 50); // Red
colorWipe(strip.Color(0, 255, 0), 50); // Green
colorWipe(strip.Color(0, 0, 255), 50); // Blue
// Send a theater pixel chase in…
// Send a theater pixel chase in…
theaterChase(strip.Color(127, 127, 127), 50); // White
theaterChase(strip.Color(127, 0, 0), 50); // Red
theaterChase(strip.Color( 0, 127, 0), 50); // Green
theaterChase(strip.Color( 0, 0, 127), 50); // Blue
// Send rainbow code
rainbow(20);
rainbowCycle(20);
theaterChaseRainbow(50);
break;

case 1:
// Some example procedures showing how to display to the pixels:
colorWipe(strip.Color(255, 0, 0), 50); // Red
colorWipe(strip.Color(0, 255, 0), 50); // Green
colorWipe(strip.Color(0, 0, 255), 50); // Blue
break;

case 2:
// Send a theater pixel chase in…
theaterChase(strip.Color(127, 127, 127), 50); // White
theaterChase(strip.Color(127, 0, 0), 50); // Red
theaterChase(strip.Color( 0, 127, 0), 50); // Green
theaterChase(strip.Color( 0, 0, 127), 50); // Blue
break;

case 3:
// Send rainbow code
rainbow(50);
rainbowCycle(25);
theaterChaseRainbow(50);
break;

case 4:
rainbow(50);
break;

case 5:
rainbowCycle(25);
break;

case 6:
theaterChaseRainbow(50);
break;

case 7:
clearWipe();
strip.show(); // Initialize all pixels to ‘off’
break;

case 8:
mode = 0;
break;
}

}

void changeMode(){
if (superBreakout == 0){
mode++;
clearWipe();
strip.show(); // Initialize all pixels to ‘off’
superBreakout = 1;
while(digitalRead(5) == LOW);
}
}

void clearWipe(){
for (int i = 0; i < 8; i++){
strip.setPixelColor(i,strip.Color(0,0,0));
}
}

// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
if (superBreakout)
break;
delay(wait);
}
}

void rainbow(uint8_t wait) {
uint16_t i, j;

for(j=0; j<256; j++) {
for(i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i+j) & 255));
}
strip.show();
if (superBreakout)
break;
delay(wait);
}
}

// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
uint16_t i, j;

for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
for(i=0; i< strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
}
strip.show();
if (superBreakout)
break;
delay(wait);
}
}

//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
for (int j=0; j<10; j++) { //do 10 cycles of chasing
for (int q=0; q < 3; q++) {
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, c); //turn every third pixel on
}
strip.show();
if (superBreakout)
break;
delay(wait);

for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}

//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t wait) {
for (int j=0; j < 256; j++) { // cycle all 256 colors in the wheel
for (int q=0; q < 3; q++) {
for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, Wheel( (i+j) % 255)); //turn every third pixel on
}
strip.show();
if (superBreakout)
break;
delay(wait);

for (int i=0; i < strip.numPixels(); i=i+3) {
strip.setPixelColor(i+q, 0); //turn every third pixel off
}
}
}
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r – g – b – back to r.
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 – WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 – WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 – WheelPos * 3);
}
}

Components

Teensy 2.0 - https://www.sparkfun.com/products/12765

NeoPixel - https://www.sparkfun.com/products/12661

Ben Heck Reflow Oven

Many months ago I worked on a reflow oven at Ben Heck’s shop over a couple of weekends.  It worked out pretty well and he included it in an episode

I used a toaster oven, two thermocouples and readers, one of Ben’s homemade Arduino boards, an LCD screen, and a solid state relay.

Many of the parts can be found from the distributor Newark http://www.newark.com/ or http://canada.newark.com/

SSR –  http://www.newark.com/opto-22/240d10/ssr-panel-mount-280vac-32vdc-10a/dp/96F1061
Thermocouple reader –  http://www.adafruit.com/products/269
Thermocouples  - http://www.omega.com/pptst/5TC.html
Arduino – http://www.newark.com/arduino/a000073/dev-brd-atmega328-arduino-uno/dp/63W3545
LCD – http://www.newark.com/powertip/pc1602ars-cwa-a-q/display-alphanumeric-16-x-2/dp/05M0978

For the toaster oven, look at rummage sales or resale stores. The dumber the interface the easier it is to take over with a solid state relay instead, and you definitely want a top and bottom element for more even circuit board heating. I’ve heard of issues with reflow ovens with only one.

For modifying the profiles-

int profile[4][6] = {
{
75,140,45,125,205,20 }
,
{
75,140,45,125,205,20 }
,
{
75,140,45,125,205,20 }
,
{
75,140,45,125,205,20 }
};
String profileNames[4] = {
“Ol’ Fashioned Pb”, “New Fangled RoHS”, “Profile 3 “, “Profile 4 ”
};

The format of the profiles is:

{Ramp 1 0-255, 1st target temp, hold seconds at 1st target, Ramp 2, 2nd target temp, hold seconds at 2nd target}

Ramp rate is kind of a misnomer, its just the analog write value but because our relay is a zero cross and we aren’t accounting for the cross, it doesn’t exactly work as good as a PWM value would.

 

The ROHS profile definitely needs changing, probably a 220 target. Your results may vary but you will definitely have to tweak for your own oven and possibly it could change depending on your board as well.

 

Attached at the end of the post is the code.  For more discussion on the project or for links to Ben’s wooden cut panel, go to the thread on the Element14 forums

http://www.element14.com/community/docs/DOC-65496/l/episode-116-bens-home-brew-solder-reflow-oven-20-episode

 

Arduino code:

Reflow Oven Code

Great Glue Gun Recap!

I recently helped out behind the scenes of the two part Ben Heck Great Glue episode. I did the electronics design, assembly, and firmware for Ben. He put that with the mechanical part of the extruder, changed out the trigger, and packaged it up real nice for the episode. As he rarely does write ups I thought I’d post the code (pre hall effect) and the parts I remember using for others to follow in the great glue gun foot steps.

Here is a partial working demo early in the process

 

Here are the two episodes-

 

Original Parts – Sparkfun

H-Bridge $2.35 https://www.sparkfun.com/products/315

Trigger Pot (retired) https://www.sparkfun.com/products/retired/10314

SSR $4.95 https://www.sparkfun.com/products/10636

Proto board $2.95 https://www.sparkfun.com/products/8811

Wall Wart 9V $5.95 https://www.sparkfun.com/products/298

Thermistor 10k $1.95 https://www.sparkfun.com/products/250 (I think I ruined one and ended up using a 100k though)

RGB LED $.95 https://www.sparkfun.com/products/11120

 

By request I cross referenced what I could for Newark http://www.newark.com , they should be available at http://canada.newark.com/ as well

BenDuino (Ben’s custom Arduino Uno, link is similar but larger) - http://www.newark.com/arduino/a000066/dev-brd-atmega328-arduino-uno/dp/78T1601

H-Bridge - http://www.newark.com/texas-instruments/sn754410ne/ic-peripheral-drivers-half-h-36v/dp/08F8145

Trigger Pot – Sorry no cross reference for this sweet product :-(

SSR - http://www.newark.com/sharp/s202s02f/ssr-pc-board-8a-80vrms-to-240vrms/dp/14N9588

Proto board with ground plane – No cross reference

Wall Wart 9V - http://www.newark.com/triad-magnetics/wsu090-0800-r/ac-dc-conv-external-plug-in-1/dp/83T4327

Thermistor 10k - http://www.newark.com/epcos/b57891m0103k000/thermistor-ntc-radial-leaded/dp/63W2796

Make sure to change the code to use the 10k, I ruined my 10k’s after a few prototypes, jbweld is too strong.  Anyways I used 100k’s, it’s an easy code change and 10k is more often used

RGB LED we used 10mm not a 5mm - http://www.newark.com/kingbright/l-154a4sureqbfzgew/led-multicol-rgb-5mm-x-bright/dp/66W1972

Code

#include <math.h>
#define MotorENPIN  3
#define Motor1APIN  2
#define Motor2APIN  4
#define Light1PIN  5
#define Light2PIN  6
#define minSpeed 50
#define maxSpeedLow   90
#define maxSpeedHigh  160
#define meltTemp 235
#define speedTempOffset 25
//#define SSRPIN    7
#define ThermistorPIN A0                 // Analog Pin 0
#define TriggerPIN  A1
//#define TempSetPIN  A2
boolean extruding = false;
boolean atTemp = false;
int maxSpeed = maxSpeedLow;
int updateCount = 0;
int setTemp = 0;
int reqSpeed = 0;
int setSpeed = 0;
int temp;
int count = 0;
float pad = 100000;                       // balance/pad resistor value, set this to
                                        // the measured resistance of your pad resistor
float thermr = 100000;                   // thermistor nominal resistance
float Thermistor(int RawADC) {          //converts thermistor reading into a resistance and then temperature in C
  long Resistance;
  float logVal;
  float tempTemp;  // Dual-Purpose variable to save space.
  Resistance=((1024 * pad / RawADC) – pad);
  logVal = 3950/log((float)100000/Resistance);
  //T2= T1*B/ln(R1/R2)  /  ( B/ln(R1/R2) – T1 )
  tempTemp = (25+273.15)*logVal;
  tempTemp = tempTemp / (logVal-(25+273.15));
  tempTemp = tempTemp – 273.15;  // Convert Kelvin to Celsius
  tempTemp = (tempTemp * 9.0)/ 5.0 + 32.0;                  // converts to  Fahrenheit
  return tempTemp;              // Return the Temperature
}
void setup() {
  Serial.begin(115200);
  pinMode(MotorENPIN, OUTPUT);
  analogWrite(MotorENPIN, 0);
  pinMode(Motor1APIN, OUTPUT);
  digitalWrite(Motor1APIN, LOW);
  pinMode(Motor2APIN, OUTPUT);
  digitalWrite(Motor2APIN, LOW);
  pinMode(Light1PIN, OUTPUT);
  digitalWrite(Light1PIN, HIGH);
  pinMode(Light2PIN, OUTPUT);
  digitalWrite(Light2PIN, LOW);
  //pinMode(SSRPIN, OUTPUT);
  //digitalWrite(SSRPIN, LOW);
  analogRead(ThermistorPIN);
  analogRead(TriggerPIN);
  //analogRead(TempSetPIN);
}
void loop() {
  int readTemp = Thermistor(analogRead(ThermistorPIN)); // read ADC and  convert it to F
  if ((readTemp > 0) && (readTemp < 500))
    temp = readTemp;
  //setTemp = analogRead(TempSetPIN);
  //setTemp = map(setTemp,0,1023,50,350);            //analog reading 0-1023, temperature range 50 to 350F
  if (temp <= meltTemp){                            //if less than set temp, turn on SSR, set lights
    //digitalWrite(SSRPIN, HIGH);
    digitalWrite(Light1PIN, LOW);
    digitalWrite(Light2PIN, HIGH);
    maxSpeed = maxSpeedLow;
    atTemp = false;
  }
  if ((temp > (meltTemp + 5)) && (temp <= meltTemp + speedTempOffset)){  //if greater than set temp but less than set temp + 10, set lights
    digitalWrite(Light1PIN, HIGH);
    digitalWrite(Light2PIN, HIGH);
    maxSpeed = maxSpeedLow;
    atTemp = true;
  }
  if (temp > (meltTemp + speedTempOffset + 5)){                        //if greater than set temp + 10, turn off SSR, set lights
    //digitalWrite(SSRPIN, LOW);
    digitalWrite(Light2PIN, LOW);
    digitalWrite(Light1PIN, HIGH);
    maxSpeed = maxSpeedHigh;
    atTemp = true;
  }
  reqSpeed = 1023 – analogRead(TriggerPIN);
  if (reqSpeed < 3){                                 //if less than 3 (deadzone) and was extruding, reverse the motor to suck in the gluestick
    if (extruding == true && count >= 450){
      analogWrite(MotorENPIN, 0);
      delay(50);
      digitalWrite(Motor1APIN, LOW);
      digitalWrite(Motor2APIN, HIGH);
      analogWrite(MotorENPIN, 125);
      setSpeed = 0;
      delay(150);
      analogWrite(MotorENPIN, 0);
      delay(50);
      extruding = false;
      count = 0;
    }
    else{                                              //if less than 3 (deadzone) and was not extruding or reverse timed out, turn off motor
      count = 0;
      analogWrite(MotorENPIN, 0);
      setSpeed = 0;
    }
  }
  else if (reqSpeed > 5 && atTemp == true){                              //if greater than 5 (deadzone), turn on motor mapped to stick, 5-1023 reading 50-150 motor, set extruding
    if (count < 450)
      count++;
    setSpeed = map(reqSpeed,5,1023,minSpeed,maxSpeed);
    digitalWrite(Motor1APIN, HIGH);
    digitalWrite(Motor2APIN, LOW);
    analogWrite(MotorENPIN, setSpeed);
    extruding = true;
  }
  if (updateCount <= 250)
    updateCount++;
  else{
    writeUpdates();
    updateCount = 0;
  }
  //writeUpdates();                                      //for debugging
}
void writeUpdates(){
  Serial.print(“Temp: “);
  Serial.print(temp,1);
  Serial.println(“”);
  //Serial.print(“Req Speed: “);
  //Serial.print(reqSpeed,1);
  //Serial.println(“”);
  //Serial.print(“Set Speed: “);
  //Serial.print(setSpeed,1);
  //Serial.println(“”);
}
As always code and parts list offered without warranty and very little support but you can always shoot me an email and I’ll see what I can do :-)

 

Also, if you have questions regarding this project, I did a little write up on Element14, any Ben Heck questions and suggestions should go there, it’s a helpful community with better knowledge base than just me (though I do contribute a lot there).

 

Oh, and look for a reflow write up in a few weeks.  Ben ended up doing a few episodes on the toaster reflow oven I was working on at his shop.

XBMC and Revival of WiFi Radio!

Well WiFi radio kind of fell off the face of the earth for awhile.  I had a chance to get a free XBMC (Xbox Media Center) kit from Element14 and I figured it would make a great revival of WiFi radio.  Here is an unboxing video of the XBMC kit

and here is a picture of the Pi
DSC01325

Hopefully I’ll get to post more updates and work on this project throughout the summer. I’m also doing more projects with Ben Heck including working on another project for an episode as well as possibly doing a Kickstarter project. More details on that later.

Another Ben Heck Show Appearance

Well, this will be a quick little post, mostly for a location to drop some files.  I made another Ben Heck Show appearance, this brings me up to 3.  The video can be seen here

 

All the videos can be seen here

http://www.youtube.com/playlist?list=PLty7pvZZzbVi8Ud1Tei8N7pI25UojzUFa

 

 

It was a cool experience as it always is.  Some guys from Engadget were there to film as well and it was cool to talk with them.  Also Ben and I got in an abbreviation contest which was fun. VHDL stands for VHSIC Hardware Description Language, with VHSIC standing for Very High Speed Integrated Circuit.  That is the coolest one I know.

 

Anyways, a few people have asked for the code and such so I will embed it at the bottom.  I have the Android code and the TI Launchpad firmware code, both in separate zips.  The Android code was written for either Jellybean or ICS, don’t remember which, and that was for the rotate command, like the pot stir app.  The APK is in the zip file.  I didn’t take the time to really document as I’ve been a busy guy.  Hopefully I’ll get to do a life update and an update on my ShapeOko CNC machine shortly.

 

Anyways, here you go

Android SANTA Project

TI Arduino Code Files

3D Printing-Minecraft-Shapeways

Next week is my Wife’s birthday.  She loves Minecraft so I decided to get her 3D printed versions of our Minecraft characters from Minetoys.  Minetoys uses Shapeways as their “factory”.  Shapeways 3D prints parts via several methods, these use printing a binder (glue) onto powder, then put more powder, print more binder, more powder, etc.  See more info here.

The parts came in today, see below

My character looks a bit like Cthulhu (looks better in the game with extending tentacle head) and hers was a diamond block based character.  The back of my character is wings

She was very excited and loved them.  As I have been looking into these technologies, I was kind of bothered by the mistakes on the right arms of the characters.  Mine has a big blob of material and hers has a divot in it.  I am not sure if this is the best quality powder-binder printing can do, or if it was a just a bad print.  Either way, it was an experience as my first ordered print and I’m pretty satisfied overall.

Skin files

 Colecago

 Kiloari

 

Took a bit of reverse engineering to get these.  To see any player’s Minecraft Skin, use the following format

http://minecraft.net/skin/username.png

ex

http://minecraft.net/skin/Colecago.png

 

Stay tuned for 3D printing and CNC update/preview!

Getting More out of USB Car Chargers

CameraZOOM-20120613123138837

I’ve done this little “hack” twice now and figured others would benefit from it as well.

 

Have you ever noticed your phone/tablet charges slower from USB than from the wall socket?  Many of these devices have a USB charging mode and an AC charging mode.  This is because USB has a limit to what current it can supply unless the device negotiates with the port for more current.

USB car chargers can usually supply more current than the standard USB charging level, but if your device thinks its charging from USB instead of from an AC adapter it will only charge at the lower rate.  So how do you trick it into thinking its hooked to an AC adapter?

Well, that’s pretty easy.  For most mobile devices nowadays, short the USB Data- and Data+ pins together.  Apple has their own methods using specific voltage levels on those pins.  For an example for an iOS device, see Ben Heck’s Universal Wall Wart episode

http://revision3.com/tbhs/earth-day

 

First, here is my charger, it is manufactured by Rosewill, I bought it from Newegg

 

There are two USB ports and the charger says it supports up to 1A total

 

I took the charger a part and this is what was inside

 

It is a basic switching circuit, probably a buck topology as your car battery is always (hopefully) going to be higher than your USB voltage.  A fuse was contained on the front end.  More info about buck converters here

http://en.wikipedia.org/wiki/Buck_converter

 

What I’m interested in is the bottom of the board, where the USB connector is soldered

I shorted the Data+ and Data- pins together as you can see above.  I also tried removing the resistors near the pins but they are glued to the board.  I think those are the resistors for iOS devices I mentioned earlier.  After looking at them, I can see their values are high, about a 52k equivalent resistance across the 5V and GND lines, meaning very minimal current draw because of them, so I can leave them in.

I tested the device before and after, and before I achieved about 200mA of charging current.  Afterwards, I achieved 400-500mA.  I’m guessing each channel can do a maximum of 500mA to get the 1A total.  I also checked the voltage level it was supplying.  Many of these cheaper chargers are super noisy, here is a scope picture

Pretty good clean signal.  Also, I should take a scope picture class so I remember to actually have some useful info on the right side of the scope and not the display controls :-D

I’ve done this once before with similar results.  It’s a great way to get more out of your USB car chargers, especially if your phone is a battery hog like my Galaxy Nexus, that before could drain the battery while charging if using navigation.  Now I can at least break even, and maybe even get a charge.

Ben Stur

Promo

The Build:

I went to Ben’s to get a PS3 controller to assist him with a controller mod and he mentioned working on an upcoming Android episode. I told him I had a little experience with Android and bluetooth control and I offered my assistance. He came up with an idea of making a remote pot stirrer so you can stir and monitor your cooking from another room. We talked throughout the week about the basic look and he gave me some graphics to use.

As I was busy most of the week, I ended up doing the program Friday night. I had some sample code from my other apps, but strange Android errors still made it take me until 3AM before I finished a working product. I had weird layout issues, it seemed to be something to do with the main.xml file. I would move something and I’d get casting errors that crashed the program when it ran on the phone. I’d delete a few objects and re-add them, doing nothing in the java code, and the problem would go away. The biggest offender was the image button. I could not line the device id textview up with it otherwise I’d get one of those crashes. When doing the layout xml’s, I made it specifically for my phone, which included editing some of the graphics. I figured I’d port the program to Ben’s nook or phone the next day.

I showed up on Saturday for taping. Ben had the hardware for the stirrer complete.  It was an arm on a stand that moved a spoon back and forth using continuous rotation servos and limit switches.  As we had discussed the protocol over email, the firmware was pre-coded and working from a terminal.  I also had my app working with a terminal.

Despite having both of our devices working separately, getting them to work together didn’t work straight out of the box. First, our baudrate on the Arduino was incorrect. We were using the Roving Networks RN41 module and those modules default at 115,200 which I forgot. After we figured that out, we had to get our continuous rotation servo working correctly. We simplified our code to just send exactly what the android phone sends, to the arm via pwm, so 0-180 with 90 being stop. This fixed that issue.  And of course whenever you have an issue, you ended up “fixing” everything else until you find the real problem and have to go “unfix” what you had changed.

When trying to get this ported to the nook, I had problems. First of all, I needed to find usb dev drivers for the nook, not too bad. Then the version of Android I developed for 4.03 or Ice Cream Sandwich, was too new for the nook. I revered the project to 2.3, or Gingerbread, but then I had to take out the rotates as Gingerbread didn’t support the imagview.rotate command. I also had to change the layout a lot to get things to line up. I had edited Ben’s files to work on my phone and I had to edit them back to what he originally made.

Once I got it installed, I tried to get the bluetooth working. It would not, the nook, no matter what I did, would talk to the module. It couldn’t even pair. It would fail and give an error. Without even a successful pair, it was dead in the water.

Next, I tried Ben’s phone. This was harder, the drivers were not readily available to connect for development. I had to put his phone into recovery mode first, which windows then took over and installed the drivers. The phone took forever to reboot and I was worried I had broke it as I had to take out the battery to get it to leave recovery mode. It finally did boot though.

I tried to send the apk to the phone through eclipse. It didn’t work. No matter what I did, it couldn’t see his device as a target even with USB debugging enabled. I ended up having to put his phone into mass storage mode and dropping the apk on there. I got it installed on the phone and gave it a try. It would pair to the Roving Networks module, but would never connect. I’m not sure if it supports SPP or Serial Port Profile, which is a Bluetooth mode, kind of like HID or audio protocol. In the end I had to use my phone. We had to fix a few code problems on the receiver side and then we were up and running, except for the thermistor. We only worked half a day so Ben said he’d add the thermistor code that night and I would port the program back to my phone and re-add the rotate command for ICS.

I came in on Sunday for a few hours to finish up. Ben added the thermistor code and we started getting some sending errors back to the phone. We removed the old sending code, which sent the speed value received as a temp, it was a debugging tool of ours and no longer needed, and then it appeared to work on the terminal. I was still getting erratic behavior on the device when I plugged into Ben’s universal wall wart. I thought the previous day we had used a 5V supply, but apparently we must have used the 12V line to power the Arduino board. With the drop caused by the regulator, the Arduino wasn’t getting enough power to work correctly. After that fix, everything was working great. We finished taping the function and that was that. Not without problems, but definitely not as hectic as Robot Luggage.

Program Information:

I wrote this program based on some samples of previous programs I’ve written for Bluetooth Control.  Much of the Bluetooth code was used and Adapted from the book “Programming Android”.

 

AboutInfoActivity- This file is all about showing the “About” section when you hit the options key.  It just shows information I put in the about.xml file explaining the protocol

DeviceListActivity- This pertains to choosing a bluetooth device.  After you hit the sync button, a screen comes up letting you connect to a bluetooth device.

BtHelperHandler and BtSPPHelper- These are the bluetooth control classes.  They are pretty much exactly from “Programming Android” except I had to add some code to allow me to receive data.  These codes I believe were adapted from the bluetooth chat example on Google’s code database.

BenSturActivity- This is the main activity.  It is what you interface with for the program.  It controls the other activities, uses the bluetooth, reads the seekbar and button inputs, and sends the bluetooth information every 250mS by use of a thread.  You sync with a device and it will show the Device ID, you know its connected when the temperature changes from — to a number.  Then you slide your finger back and forth on the slider in the upper right to move the arm.  Releasing puts the position back to 90, or off.  That’s about it.

Protocol- Its a pretty simple protocol with everything sent in Ascii.  I did this because I was having trouble getting useful Byte data from the bluetooth helper classes but strings worked fine.

Sending- Start character – Three digits of position, always 3 digits, padded with 0′s when neccessary

ex- !090 (stop)    !180 (full CW)   !000 (full CCW)

Receving- Start character – One to Three digits of temperature, does not need to be 0 stuffed

ex-  !99  !120

 

Known Issues- When coming back from a screen off condition (like a sleep), the program often crashes from an inflater error.  Something about unknown class.  I’ll see if I can fix it, but I’m not an Android nor Java king.  If anyone else looks at this code and fixes it, let me know so I can update it.

 

Older Support- Because of the ImageView.rotate command, this is ICS and above only.  Remove the ImageView rotation command and then configure the project for an older version of Android to work on older phones.  Also remember to update the Minimum Version in the Android Manifest !

 

Eclipse Project file and APK is attached:

BenStur Files

 

Android Market Link:

Ben Stur