Older blog entries for shimniok (starting at number 70)

Tiny, Portable Turntable Strobe


I love turntables. The very idea is simultaneously insane and an awesome feat of engineering. 

Microscopic grooves in a rotating disc of plastic vibrate a minuscule, precisely ground chunk of diamond stuck on a tiny metal tube with magnets attached, inducing tiny currents in a cartridge coil, subsequently amplified up the wazoo. Somehow, instead of sounding like garbled crap, the reproduced sound is quite excellent on a decent system.

But how fast does the record spin? That's the purpose of my project, an extremely accurate, compact turntable strobe. An LP is supposed to spin at 33-1/3 RPM. Many probably don't. Not precisely. And the voices in my head like precision.

Introducing Pocket Turntable Strobe

Some turntables, like my Realistic Lab 400 above, have strobes built in that run off mains frequency to illuminate precisely spaced platter markings that appear to stand still when the platter speed is just right. Except the mains frequency varies and is only 60Hz on average.

Compare to my Turntable Strobe, which uses a quartz crystal and ATtiny25 to flash a white LED at 60.0±0.03Hz (30ppm absolute accuracy plus 20ppm temperature variation). Use it with platter strobe markings or speed check disks that you can find online. 

Turntable Strobe with speed check disc
It uses a tiny 3V, CR1225 battery which, combined with not-quite-Vcc output from the ATtiny25, produces barely enough voltage to dimly light a white LED. Adding four components makes the strobe burns bright as below, right. 

Same circuit, same LED, CR2032 left, CR1225 right
What sorcery is this? A Dickson charge pump.

From Jonathan Thompson's Web Journal [link]
The circuit is simple, requiring two capacitors and two diodes and one of the pins on the microcontroller for the clock signal. The result is a higher voltage supply (4.2V unloaded) that can brightly illuminate the high intensity, 5mm LED through a 1K current limiting resistor. I'll provide more detail on this circuit in an upcoming article.

Diagrammed in Upverter
Another trick to minimize complexity and parts count is that the microcontroller directly sinks current from the LED. You may object, claiming it's unsafe given the LED circuit is powered by a voltage exceeding the Vcc+0.5V limits of the ATtiny. Rules are meant to be broken, provided you have sufficient understanding of their purpose and how things work. I'll show you why it's safe in another upcoming article.

Meanwhile, if you want one, they are for sale.

Syndicated 2014-03-12 16:30:00 from Michael Shimniok

Freescale FRDM-KL46Z Board


I've been playing with a $15 Freescale Freedom board based on the Kinetis MKL46Z256 [pdf]. It has a built in magnetometer and accelerometer and possibly the cutest little 4-digit, 7-segment LCD I've ever laid eyes on. This is quite a capable board.

It's a 48MHz Cortex M0+ with 256K flash memory, 32K RAM. That's enough power to do some serious computation. Perhaps a Kalman Filter-equipped Segway type robot? Or AVC rover?

On top of that, typical of other Freescale chips, a fast ADC running >400kSPS at 16bit or >800kSPS at lower resolution. With DMA available.


With Arduino form-factor headers plus another row of headers in addition to those, the board provides easy access to a lot of MCU pins, 64 to be exact.

You also get a light sensor, capacitive touch slider, a couple of tactile switches, and USB host / device capabilities.

The board is supported by mbed for easy programming and prototyping. And to dispel the myths: the mbed SDK is open source and you can offline compile it for several supported ARM toolchains.

Debug, in the form of CMSIS-DAP, is available, too. A 20mm battery holder footprint is provided on the board.

Getting Started


If you plug your USB cable into the OpenSDA USB connector (use your Quick Reference Card to locate it), then your system will mount a Mass Storage Device.

On the drive are several HTML files. SDA_INFO.HTM takes you over to a P&E Microcomputer registration site where you can register your hardware. TOOLS.HTM redirects your browser to a page listing P&E debugger tools. For some reason the FSL_WEB.HTM leads to 404 error on the Freescale website. It should point to this page.

Next, head over to the mbed.org site, register or login, navigate to the Freedom KL46Z platform page and on the right side, click the "Add to Compiler" button.

Compiling Demos

On this same page you'll find a series of examples for the board. You can also search mbed.org for more. I selected an accelerometer demo from Freescale. Import it into the IDE, select your platform with the button at the upper right. Click compile and then move the bin file that is downloaded onto the Freedom's mass storage device.

The demo prints accelerometer values for X, Y and Z axes to the USB serial port. On Linux this device appears as /dev/ttyACM*. Fire up minicom and you get output...

X: 1.00, Y: 0.96, Z: 0.00
X: 1.00, Y: 0.96, Z: 0.00
X: 1.00, Y: 0.96, Z: 0.00
X: 1.00, Y: 0.96, Z: 0.00
X: 1.00, Y: 0.96, Z: 0.00
X: 1.00, Y: 0.97, Z: 0.00
X: 1.00, Y: 0.97, Z: 0.00
X: 1.00, Y: 0.96, Z: 0.00
X: 0.99, Y: 0.97, Z: 0.00
X: 1.00, Y: 0.96, Z: 0.00

On Windows you'd need to download a driver

Next I tried a touch slider demo which controls the PWM signal sent to the board's green LED. The code is really simple. Here's main:
  
int main(void) {
PwmOut led(LED_GREEN);
TSIAnalogSlider tsi(ELEC0, ELEC1, 40);

while (true) {
led = 1.0 - tsi.readPercentage();
wait(0.1);
}
}

Conclusion

I think this board is a decent deal at $15, the main selling point being mbed compatibility. My view is that boards are only worth as much as their toolchains and community support. And you can get other Freedom boards in the same form factor as well including other M0+ boards and an M4, the FRDM-K20D50M which boasts a 50MHz M4 with DSP capability.

While I touched on the highlights of this board, there's a lot more to explore. I'm looking forward to writing come code for it and using it in an upcoming project. SHARC will be hosting a Firefighting competition in the next few months and Pokey could use a major refit. However, come to think of it, I'm up to my ears in projects. Instead, perhaps I'll use it for one of those projects, such as my Take Out The Trash Bot. Whatever I do, I'll be sure to post about it here.

Syndicated 2014-03-06 16:00:00 from Michael Shimniok

Lithium-Sulphur Batteries

I ran across an article on Lithium-Sulphur batteries the other day. With theoretically double the energy density of Lithium-Ion batteries, Lithium-Sulpher batteries look promising, but the chemistry comes with many challenges. However, researchers at Lawrence Berkeley National Laboratory have found some ways to address the problems. (read the Full Article)

Syndicated 2014-03-04 18:15:00 from Michael Shimniok

27 Feb 2014 (updated 11 Sep 2014 at 05:15 UTC) »

AVC Path Following

I implemented an improved path following algorithm on Data Bus and later, the SHARC self-driving Jeep that won Doping in the 2014 Sparkfun AVC.

The old, simple path following algorithm worked but didn't correct cross track error. The new algorithm chases a virtual rabbit, computing where the rabbit is and how to intercept it.

The Pure Pursuit algorithm is conceptually elegant and simple. It's easy to program, it's popular, and, clearly, it works quite well.

Pure Pursuit Algorithm

The robot follows a virtual rabbit that travels around the legs of the course, with each leg defined by two points. The rabbit is always located along the current leg of the course, A=[W0 W1].

The projection of the robot's position onto A is point P and the rabbit is located along A, a fixed distance from P. The fixed distance between P and the rabbit is called the lookahead distance.


The algorithm moves the rabbit's position at each update step, computes a relative bearing from the robot to the rabbit, computes an arc path tangential to its heading that intercepts the rabbit. The result of this unending pursuit is a smooth correction to the robot's heading and cross track error. This algorithm is called Pure Pursuit.

Here's the math I used to compute the intercept arc. The distance from W0 to P is the projection of the robot's position onto W, given by a dot product:


Where A=[W0 W1] and B=[W0 robot]. Vector A, divided by its magnitude, is the unit vector pointing along A. The dot product can be computed with trig functions (slow) or you can do it this way (fast):


 

Once you have a scalar from the dot product you can find your goal point, the rabbit, like this:





Even if the math looks spooky, the code is trivial. Here's the Processing code I used for my simulation.

  // Leg vector
  float Ax = Xw[next] - Xw[prev];
  float Ay = Yw[next] - Yw[prev];
  // Bot vector
  float Bx = x - Xw[prev];
  float By = y - Yw[prev];
  // Dot product
  float legLength = sqrt(Ax*Ax + Ay*Ay);
  float proj = (Lx*Bx + Ly*By)/legLength;

  // Goal point ("rabbit")
  float Rx = (proj+lookAhead)*Ax/legLength + Xw[prev];
  float Ry = (proj+lookAhead)*Ay/legLength + Yw[prev];


See? Not bad at all!

Turning

The robot now knows where the rabbit is. The robot knows it's heading and position. It can compute the relative bearing to the rabbit. But how much should the robot turn to catch the rabbit?

An elegant approach with smooth behavior that doesn't require complex programming logic or trial and error tuning is to use an intercept arc that intersects both robot and rabbit, and is tangential to the robot's heading. Here's how.

We have the robot at B, it's heading described by BC, and the rabbit or goal point at G. The distance between B and G is D.


A circle that intersects B and G and is tangential to BC with radius R will have an origin along a line that is perpendicular to BC and passes through B. We simply need to find out R, the radius for this circle. Time to break out some trigonometry.



Draw another radius line perpendicular to BG. This line will bisect BG (each line is D/2 in length). Studying the right triangles generated by these lines, notice that the relative bearing, theta, is also the angle between the new radii intersecting B and G, respectively.


We can express D/2 in terms of R and Theta, then solve for R:



The robot recomputes a new intercept arc at every update step. The result is a continuous path towards the goal point. The path is followed, the cross track error is accounted for.

Conclusion

So, despite planning to test this on a small 1:10 RC car, I ended up proving it out on the full size Jeep. Once the turning radius and lookahead distances are set reasonably, it works a treat!

If I get some time I'll post up the calculations for converting from arc radius to steering angle to servo signal. Suffice it to say that determining the correct steering angle to traverse the intercept arc is relatively simple to figure out, using basic geometry.

References
Path Tracking for a Miniature Robot.pdf
coulter_r_craig_1992_1/coulter_r_craig_1992_1.pdf

Syndicated 2014-02-27 22:02:00 (Updated 2014-09-11 04:17:13) from Michael Shimniok

27 Feb 2014 (updated 26 Mar 2014 at 15:15 UTC) »

Clock for my Vision Impaired, Aging Mom

My 82 year old mother can't see very well and regularly forgets what day it is. I looked around for a clock to help her keep track of the day of week but decided in the end to build my own using components from tindie.com.




You can build one of these yourself. Here's how I built the prototype...

LED Matrix from FriedCircuits

First up the 8x8 LED Matrices. I bought three
LED Matrix Links from FriedCircuits on Tindie.  The product is a Matrix plus backpack using an AMS AS1107 (MAX7219 compatible) that you can easily daisy chain together. These LED drivers communicate with SPI and there is an Arduino library to drive them (or you could roll your own driver).

LED Matrix Master, left, and three LED Matrix Links from FriedCircuits

You can also buy an LED Matrix Master that plugs in conveniently to the display chain to drive it with an ATmega328P. For now I'm using a bona-fide Arduino Uno but I'll probably hack something together, maybe use one of my ATtiny breakout boards.

I calculated that I could generate 5-column numbers plus a narrow 1 for hours 10-12, and fit it all into 3 8x8 matrices (24 columns) including the blinking colon. The days of week could be abbreviated to three characters, each 7 columns wide.

The boards are nicely built with quality soldering, clever layout, and a great chip to work with. These appear to be OSHPark boards with all the quality you'd expect.

RTC from Jack Christensen

To keep track of time, even with the power off, I selected Jack Christensen's Real Time Clock module based on the MCP79412 chip. It's got a large coin-cell battery backup and all the pins broken out. It uses I2C to communicate. It takes a supply voltage from 1.8-5.5V. Quite convenient.

Jack Christensen's MCP79412 RTC breakout
The quality of the board and its assembly is outstanding. Beautiful, shiny, well-wetted solder joints, nice layout, crisp soldermask. I'm not sure who makes the boards but I'll have to find out because they're quite nice.

Microcontroller

For now I'm using an Arduino Uno. I connected the devices as follows:

  • RTC SDA to Arduino A4
  • RTC SCL to Arduino A5
  • Matrix LOAD to D10
  • Matrix DI to D11
  • Matrix CLK to D13

Software

LedControl is the Arduino library you need to control the matrices. I created an array of data for the fonts, a routine to draw a particular character, a routine to draw the hours and minutes and (optionally) the colon, and another routine to draw the day of week.

Jack wrote an MCP79412 library for his module, exposing all sorts of features, and providing examples. I used this library to read the time, then call the other routines to write out the time (blinking the colon) or, if seconds fall between 20 and 30, write out the day of week.

Take a look at the code in my Software Repository

Next Steps

To date the project took maybe 2 hours to get working. This just goes to show you what can be accomplished quickly thanks to the open source movement.

I took it over to her apartment tonight and she was able to read the time and day right away. Good.

Next step will be to select a microcontroller, finish the code, then encase the project with a nice box with tinted acrylic front panel. I'll add a power supply (battery? wall wart?) and let my mom try it out.

Ideally I'd like to have a simple interface for setting the time or, even better, use of NTP over WiFi. We'll see.

Next: Completing the Clock

Syndicated 2014-02-27 17:35:00 (Updated 2014-03-26 14:25:03) from Michael Shimniok

25 Feb 2014 (updated 26 Feb 2014 at 02:11 UTC) »

Things-API exposes Arduino as REST

Things-API (github), by by Vicius Senger, exposes Arduino's physical computing capabilities as REST services through Java on a Raspberry Pi. I had a chance to use it during the JavaOne Raspberry Pi Embedded Challenge.

Here's an overview of how it works...

On the Arduino side, simply declare a Device object, then add things (rest services) to it, defining the pin type and pin number, e.g., Analog pin 2. Then just loop calling the appropriate loop functions.