20091231

Reality Blows: Strange LCD Problem and Strange Solution.

I spent the better part of two hours struggling with your average HD44780 driven 16x2 character LCD, even though I was using the LiquidCrystal library that comes with the arduino environment. My problem was the text I was printing out looks like this:


I tried a lot of things, like adding in delays here and there, even going so far as to use a subclass of LiquidCrystal which inserts a 2ms delay after each write to no avail. Then by a process of elimination, I found that if I reverse the order in which the lines were printed, i.e. print line 1 then line 0, the problem goes away:


Whiskey Tango Foxtrot.

Cheers,
Steve

Labels: , , ,


20091222

Latching Power Supply With Electronic Turn Off

This circuit has (as far as I can tell), 0 off current, and 17mA on current. It is latched by the momentary push button, and can be turned off by applying >0.7V at the input as shown. It is intended for use with embedded interactive installation (e.g. an arduino) where the user pushes the button to turn the device on, and the device will turn itself off after some time to conserve battery.

It is a modified version of this circuit.

Cheers,
Steve

Labels: ,


20090604

microbric viper review

The microbric viper is neat. Good quality parts and unique idea. Makes a decent robotics platform if you get the wheel add-on. However, you gotta have small fingers to get some of the parts in place. Despite this, the hardware is solid, I like it. The one thing I would ask for however is more short-nuts and a printed manual, not a CDROM with a PDF. Take a leaf from LEGO and their construction manuals.

While the hardware is decent, the microbric viper is sadly let down by the software.

The microbric viper uses the basicAtom (by basicmicro), a PIC 16F87{6,7} with a custom bootloader. Now there is nothing wrong with this - arduino uses a custom bootloader too. However the custom bootloader uses a proprietary programming protocol. This is pretty fail, but what really fails is the programming software only runs under windows (or wine under ubuntu, but only for now).

IMHO the basic-esque language used by basicAtom is no better than what picaxe offers. I am completely at a lost as to why companies would use the basicmicro's products and lock themselves to a single supplier. Think about it: if basicmicro goes bust, your products using the basicAtom will not longer have a supported development environment.

Robotics companies need to seriously consider how their selection of controller will affect their customers - specifically those customers who aren't going to be running windows and staying with in the limits of whatever custom language designed by the controller vendors.

Arduino would be the best choice IMHO. Open hardware, open software. You don't have to pay premiums for the bootloader, and the number of people who will consider your product increases to include people like me.

I bought the microbric viper because it was on sale: reduced to $29 from $199. If I had known I could only program it under windows or that it used such a closed platform, I won't have bought it, even for that price.

Cheers,
Steve

Labels: , , , ,


20090529

New addition to the work bench

Thanks to Anthony from Area I.T. & T, I am now a happy owner of a dual channel 40Mhz oscilloscope.

I am happier than a pig in mud!

Cheers,
Steve

Labels:


20090518

Sketch to calibrate SEN-08663

Got my hands on a ADJD-S371 on a breakout board from Sparkfun. The code below can be used to calibrate it. The most up-to-date version of the code can be found at my git repository under colour_sensor_calibration.

#include <Wire.h>
/* Calibrates the sensor to get white balance. Pin 2 should be connected
 * to LED on the breakout board's LED pin. Calibration is done by placing the
 * breakout board inside a pin pong ball, and using the built-in LED for
 * illumination.
 *
 * Amount of light is measured by charging N capacitors for time X then
 * reading off the voltage. (Conjecture)
 *
 * N is controlled by CAP_XXX
 * T is controlled by INT_XXX
 *
 * Calibration is done by adjusting the integration time. No real reason.
 */
int _slave_id = 0x74;
int _LED_pin = 2;

uint8_t read_register(uint8_t addr)
{
  i2c_send(_slave_id, &addr, 1);
  return i2c_read(_slave_id);
}

void write_register_int(uint8_t addr, int data)
{
 write_register_multibyte(addr, (uint8_t*)&data, 2);
}

/* write data[i] = register+i */
void write_register_multibyte(uint8_t addr, uint8_t* data, uint8_t bytes)
{
 for (int i = 0; i < bytes; ++i)
 {
  write_register(addr+i, data[i]);
 }
}

void write_register(uint8_t addr, uint8_t data)
{
 uint8_t bytes[] = {addr, data};
 i2c_send(_slave_id, bytes, 2);
}

uint8_t i2c_read(uint8_t id)
{
 Wire.requestFrom(_slave_id, 1);
 for(int i = 0; i<10 && !Wire.available(); ++i, delay(10));
 if (!Wire.available())
 {
  return 11;
 }
 return Wire.receive();
 
}

void i2c_send(uint8_t id, uint8_t * data, uint8_t len)
{
 Wire.beginTransmission(id);
 for(int i = 0; i < len; ++i)
 {
  Wire.send(data[i]);
 }
 Wire.endTransmission();
}

#define CTRL    0x00
#define CONFIG    0x01

#define CAP_RED   0x06
#define CAP_GREEN   0x07
#define CAP_BLUE   0x08

#define INT_RED_LO   0x0A
#define INT_RED_HI   0x0B
#define INT_GREEN_LO  0x0C
#define INT_GREEN_HI  0x0D
#define INT_BLUE_LO  0x0E
#define INT_BLUE_HI  0x0F

#define DATA_RED_LO  0x40
#define DATA_RED_HI  0x41
#define DATA_GREEN_LO  0x42
#define DATA_GREEN_HI  0x43
#define DATA_BLUE_LO  0x44
#define DATA_BLUE_HI  0x45

int read_colour(uint8_t low_addr)
{
 int lo = read_register(low_addr);
 int hi = read_register(low_addr+1);

 return lo|(hi<<8);
}

int red_integration_time = 2048;
int green_integration_time = 2048;
int blue_integration_time = 2048;

void set_integration_times(int red, int green, int blue)
{
 write_register_int(INT_RED_LO, red);
 write_register_int(INT_GREEN_LO, green);
 write_register_int(INT_BLUE_LO, blue);
}

void setup()
{
 pinMode(_LED_pin, OUTPUT);
 digitalWrite(_LED_pin, HIGH);

 Serial.begin(57600); 
 Wire.begin(); // join i2c bus (address optional for master)
 Serial.println("Setting up...");

 // datasheet says, wait 10us for hardware reset, so lets wait 1000
 delay(1);

 // gain setup
 write_register(CAP_RED, 0x08);
 write_register(CAP_GREEN, 0x08);
 write_register(CAP_BLUE, 0x08);

 set_integration_times(
  red_integration_time, 
  green_integration_time, 
  blue_integration_time
 );

 // ask for colour data and offset
 write_register(CTRL, 0x01);
}

void loop()
{
 if (read_register(CTRL))
 {
  return;
 }
 
 int red, green, blue;
 red = read_colour(DATA_RED_LO);
 green = read_colour(DATA_GREEN_LO);
 blue = read_colour(DATA_BLUE_LO);
 
 Serial.println("--------------");
 Serial.print("red: ");Serial.println(red);
 Serial.print("green: ");Serial.println(green);
 Serial.print("blue: ");Serial.println(blue);


 Serial.print("red_int: ");Serial.println(red_integration_time);
 Serial.print("green_int: ");Serial.println(green_integration_time);
 Serial.print("blue_int: ");Serial.println(blue_integration_time);

 // have to calibrate against blue, because LED has a blue bias otherwise
 // it would look like blue has high gain than it does
 float P = 1;
 int reference = blue;
 red_integration_time += (reference - red)*P;
 green_integration_time += (reference - green)*P;
 blue_integration_time += (reference - blue)*P;

 // set the new integration times
 set_integration_times(
  red_integration_time, 
  green_integration_time, 
  blue_integration_time
 );
 
 // ask for colour data again
 write_register(CTRL, 0x01);
}

Cheers,
Steve

Labels: , ,


20090216

Futurlec Ultrasonic Sensor Note

Part number US1440, these sensors are not dual use, which means the transmitter and receiver is not exchangeable. They also look identical from the outside, so if you build my arduino ultrasound ranger with these (as I did) and find you can't see echoes, try swapping your transmitter and receiver around! It cost me no small amount of headach this morning.

Cheers,
Steve

Labels:


Arduino ultrasound ranger

Code to drive it is avaliable under GPL.

An updated version of the schematic as a .sch file is available also.

Cheers,
Steve

Labels: , , ,


20090125

Auto leveller

A simple 2 DoF setup with an accelerometer (LIS302DL) attached to the effector. The seeeduino attempts to drive the servos so the Z and Y axis measure zero acceleration. The sketch is available at the usual place.

The algorithm employed is a simple PD controller with pseduo-gradient stepping to determine how to control each servo without any knowledge of how the servos are arranged. To deal with sensor noise from the accelerometer, a schmitt trigger mechanism is employed along with a moving average.

The code also allows the system to be calibrated to deal with accelerometer miscalibration.

It is cute, but that is about it :-) Coupled with a tripod and better construction ut might be useful for some DIY surveying or construction work.

Cheers,
Steve

Labels: , , ,


20090113

Turn a servo into 1-wire-control bi-directional motor

It is often a pain building H-bridges or getting a motor shield just because you want to control a few motors. This is where servos come in: they are cheap(ish), have motor and gearbox, and they are controlled ysing only a single wire.

The only problem is of course, servos aren't designed for continuous motion. Servos are designed to respond to PWM pulses which encode the desired position for the servo to be in, not a desired speed or direction. So some modification is required.

Now there are many articles on the intertubes on how to do this, but they mostly concern themselves with making the servo into little more than a normal motor with a gearbox - you still need a H-bridge to control the direction. This modification is a little different: it leaves you with a servo that behaves like a bi-directional motor where the direction is controlled by a single wire.

Due to the variety of servos out there, I will present only the general idea, which applies to servos which use a potentiometer to determine position.

Firstly, a quick explanation of how these servos work. The principle behind these servos is that the potentiometer is connected to the output gear such that the voltage of the sweeper (connected to the middle pin usually) depends on the angular position of the output gear. The onboard controller converts the input PWM signal into a target voltage, then it powers the motor so it turns the output gear until the voltage of the sweeper matches the target voltage. This is kind of control action is relatively easy to achieve using an operational amplifier.

The basis of the modification is essentially this: if we fix the sweeper voltage, then any input asking the servo to move away from the sweeper voltage will result in the onboard controller continuously attempt to match sweeper voltage to target voltage. By making the target voltage higher or lower than the sweeper voltage, we get directional control.

To fix the sweeper voltage, the potentiometer will need to be disconnected and replaced with a voltage divider. I assume that when the output gear is in centre position, sweeper voltage is half the supplied power because the potentiometer will be in its centre position. Since I wanted 0 degree rotation to map to stop, I fixed the sweeper voltage at this value by using 2x1.5K resistors in series. This is all you need to do electronically. There should be enough room to fit in 2 extra resistors, even in small 8g servos (what I had).

The last thing to do is to remove any physical obstructions which prevent the output gear from completing a full revolution.

Once the electronic and physical modifications are complete, you should have a servo which can turn in either direction continuously and controlled via single wire. Two of these would be perfect for say powering a small rover...

Cheers,
Steve

Labels:


20090104

Tips for interfacing a electret mic with an arduino

  1. The arduino ADC is 10bit, which means the range is 0-1023 and this is mapped to 0-5V most of the time, unless you do funky things to AREF.
  2. Most amplifier circuits on the net (using op-amps or LM386s) will have a DC bias of 2.5V, this is to allow the output to swing both ways. So on the arduino side even with complete silence you will read a value ~512 or so.
  3. The resistor connecting the electret mic and power also adjust the sensitivity of the microphone in addition to providing power to the mic (which includes an internal pre-amp, by the way). This resistor is very important - if you find your microphone isn't responsive enough, then adjust this resistor first before debugging your amplifier circuit. For me this "fixed" my microphone's responsiveness. It is best of this was a variable resistor which makes adjustment trivial.
  4. I was making a simple volume meter, and I did the following: clamp upper values to about 600, then using map map this to a range between 0-7 (since I had 8 LEDs). This was because I found the value never went above 600 very often, so the upper few LEDs were essentially going to waste sitting around. YMMV.

Cheers,
Steve

Labels: ,


20081226

DIY digital spirit level



DIY digital spirit level
Originally uploaded by sentientintelligence
A simply digital spirit level using a LIS302DL accelerometer from nkcelectronics coupled with a seeeduino for processing and a 2x16 character LCD display for output.

Sketch is available for your convenience. Note the Sketch includes an extra feature: PWM backlight on pin3.


Cheers,
Steve

Labels: , , ,


20081220

RIP DSE, Greetings Futurlec

Dicksmith Electronics is dead to me now. Dead as a door nail, dead just like Tandy.

When I was growing up, Tandy and DSE were the two places I went to get my electronic parts and information. The Engineer's Mini Notebook series and Getting Started in Electronics sold at Tandy were treasure troves of tips, tricks, and insights. The best thing was of course I could buy nearly any component mention in the book at either DSE or Tandy.

Those days are no longer. Tandy degenerated into a specialised consumer electronics retailer long ago, and now DSE has suffered the same fate. Take for example my wasted journey to Burwood DSE: I had searched on DSE's website for some pin headers, and was inform Burwood store had them in stock. 30 minutes later I was there, and lo and behold: they no longer have an electronics section. Only a few years ago I would frequent Burwood DSE because they were the only component retailer I could reach with relative easy by public transport. Now there is nothing but the shiny and vacuous desert of electronic bling.

How the mighty have fallen.

Currently Futurlec is my supplier of choice. Not only do they have reasonable prices, they also have a fantastic range of components, boards and hardware, a better range than Jaycar with a easier to use website too.

I am torn to use Futurlec - Jaycar has been an excellent business in encouraging the next generation to get into electronics, and I really want to support them. But their website leaves much to be desired, and their range in recent years has been slowly been invaded by consumer electronic bling. Will Jaycar fall like Tandy and DSE before it? Maybe if they stayed out of the hands of the Woolworths...

Cheers,
Steve

Labels: , ,


20081212

2x16 character LCD displays

2x16 character LCD displays can be tricky beasts. I got mine working today with my seeeduino (an arduino compatible board with more awesome), and really wished I had known that:

  1. The contrast pin needs to be in the same power network as the power and ground pins. The contrast pin at 0v provides highest contrast, which means you can probably just ground it normally.
  2. The timing between LCD driver power up and commencement of device programming appears to be important. I had the LCD power independently, and this gave me garbage on screen. When the LCD shared the same power supply as the seeeduino everything worked perfectly.

Cheers,
Steve

Labels: , ,


20081006

Electronics, it gets the heart pumping

There is it, the new current limited H-bridge for my team's SUMO entry. Put it together this afternoon, and will be mounted on a piece of perspex (which I forgot to bring home) and then mounted on the robot.

Statistics:

This is basically 2 MOSFET H-bridge each powered by a LM138/LM338K rigged with 150/150K for R1 and R2 respectively, providing ~13.5V.

Cheers,
Steve

Labels:


20080708

Evolution of a circuit layout


evolution of a circuit layout
Originally uploaded by sentientintelligence
Half way mark to a 4 channel motion controller. Version 3 of the layout seems to work well and was relatively easy to duplicate by eye. In fact I hardly used the schematic at all.

The new lead free solder (1mm) I am using is much too thick for my liking, I ended up using more solder than I normally would, and made some unintentional bridges which caused problems. That and one of the diodes were wired in reverse.

I really need to find some sub millimeter lead free solder - no one seems to stock them here in Australia :-|

Cheers,
Steve

Labels:


20080119

Programming 16F84As with piklab-prog and JDM programmer

Finally got around to using piklab-prog to program my surplus 16F84As. The command line options are a little confusing, so here is what I used:

piklab-prog -d 16F84A -t /dev/ttyS0 -p direct -h 'JDM classic' -c program led_test.hex

For some reason there is a hardware option which doesn't work for me and is not documented in the man page. piklab-prog seems to magically detect that I am using a JDM classic programmer, so all is well :-)


Cheers,
Steve

Labels: , , ,


20070510

Log clock

Got my log clock running. It is not entirely accurate, loses a second every 7hr or so. However its nature is such I doubt it will really matter.Thanks to the JAL interval library routines, it is very accurate. I originally thought the next interval routine returns after the 1 second delay I setup, only that is not the case. It returns when the internal clock ticks over to the next second. So as long as all the logic is done with in a second, and it is, each loop takes exactly 1 second.

The design is very simple. Using a 16F84A (yeah yeah, its obselete blah bah) with a 4Mhz crystal, lots of wires, and a 12 segment bar display. The button is used to advance the clock to the next interval. This method of setting the time is very crude - but then it doesn't have to be sophisticated. Software was written in JAL.

The loss of a second every ~7hr is due to the fact its basically a loop which has a delay of 1 second, and does some logic to handle display and button presses. The logic skews the overall delay per loop because each branch and such takes up cycles. There are several things I can do to improve this:

  • Pad out each branch with NOP so they all take the same time, then compensate for this in the loop delay accordingly.
  • Have a secondary circuit to output a pulse every second, so the logic and such won't skew the clock. This would also allow me to check for button presses more often.
  • Write my own interrupt routines to handle TMR0 interrupts and handle logic in the main routine.

The button is debounced in hardware implicitly, since there is a 1 second delay between each polling of button state. As the 16F84A only has 8bit registers, the intervals in seconds are not stored but rather the time in seconds between intervals is stored. This allows me to avoid multi-register arithmatics. The clock can also represent 13 states despite having only 12 LEDs - the 13th state is all LED off, which I have reserved for midnight.

I will report on how accurate it is eventually. I will check the log clock when I wake up, against real time, to see if the right interval is correctly illuminated.

Update 10/5/07 - Woke up, clock was right. Every 30minutes or so I check it and its been right so I declare it a success :-)


Cheers,
Steve

Labels:


20070509

Webcam astrophotography

After seeing what can be done with a webcam, I decided to try it. I asked my cousin for her webcam which she bought a while back - some generic Chinese product, with no identifying brands. macam reported it as Generic ZC031P Webcam.

So anyway I dis-assembled it (with permission of course), which wasn't too hard. Then I mounted the imaging unit on a piece of wood using a few screws (salvaged from dismantlement of the webcam casing) and hot glue. Then I used a film canisters which tapers towards the bottom slightly as an adapter - it fits snugly into a 1.25" eyepiece holder. Luckily its black. Some more hotglue and electrical tape later, I had a home made webcam adapted for prime focus use.

Unfortunately I did not have the presence of mind to take pictures while I was making it... so you will have to make do with these.

Naturally after I built this, the clouds moved in. I tried "spying" on some near by highrises to test it, but found my telescope didn't have enough in focus (back focus? Basically, I can't retract the focuser enough to focus). Maybe things will be better with a target at infinity - i.e. a planet. I will post an update when I get a clear sky.


Cheers,
Steve

Labels: ,


20070429

PIC-PG2C

PIC-PG2C is a simple JDM serial FLASH programmer. It runs directly off the serial port, requiring no external power source. There is some concern it will not work with low power serial ports, such as those found on laptops. I am happy to report however that it works on an IBM Thinkpad T20.


Cheers,
Steve

Labels:


This page is powered by Blogger. Isn't yours?