Monthly Archives: June 2014

Nifty Arduino/AVR hack: measuring VCC

JNv4Assem_sq-450x450In my previous article pondering sensors for my garden, I shamefully neglected a viable and interesting choice, the JeeNode JeeNode is available here in the U.S. from Modern Device. It’s sold as a kit, which is unusual, but not particularly scary to assemble. It’s just a few through hole parts. It’s a pretty bare bones processor, but does interestingly include a wireless module. It uses the RFM12B modules running on either 433 or 915 Mhz. But what really makes the JeeNodes interesting to me are that they abandoned the (I submit) broken shield model of Arduino shields, and instead group the output pins for the Arduino into a collection of identical Ports which can be accessed using their JeeLib library. Each port consists of six pins (one ground, one Vcc, and four data pins) and all can be used to implement an I2C bus in software to access peripherals. Very cute, and much nicer than the hodge podge of existing code for the Arduinos.

But the website at JeeLabs has a bunch of other cool stuff. Like details on one of their JeeNodes that’s been transmitting data wirelessly for over eight months, powered by just a coin cell. Or this Dive Into JeeNodes which is a tutorial on interfacing JeeNodes to a Raspberry Pi to make a house monitoring system. While the blog isn’t being updated anymore, it includes all sorts of good stuff, including this rather clever article on VCC Measurement (a software only way for an Arduino to determine it’s own input voltage). Great stuff.

DIY FPV Micro Quad…

Building my full sized quadcopter is going rather slowly (sigh) but in the mean time I picked up a little Hubsan X4 to play with. It’s cheap, and because it has a very low mass, it’s pretty hard to destroy. After more crashes than I can count, I’ve only managed to ding up one propeller (and replacements are pretty cheap and easy to get). But I must admit that one of the reasons I’m interested in quads and RC vehicles is to shoot video from them. While it is possible to get microquads that carry cameras, or even allow FPV, I kind of like the idea of home brewing something. Often, such projects are aided by following in the footsteps of giants, looking at how others have solved problems helps a bunch. It’s also inspiring. That’s why I was particularly enthused to find this article:

Build a micro-sized first-person-view quadcopter

A couple of things I like about the article:

  • It suggested the Vitality H36 quadcopter. It has one really interesting feature: it’s compatible with the Flyky/Turnigy radio transmitters. It would be cool to use my big transmitter with the tiny quad.
  • Provides good hints on the video camera, transmitter and receiver module that you might want to use.
  • Good links to circularly polarized antenna construction details.
  • It’s an existence proof that it can be done! Awesome!

It looks like a complete hoot!



Pondering some sensors for my garden…

DSC_1941-500x500We’ve started a garden at our house in a pair of raised beds. I’ve been pondering about possibly creating a set of sensors to monitor the dryness of the soil in the beds as well as in the container that I have a dwarf Meyer lemon tree going in. I was trying to figure out what a good sensor would be. Ideally, I want a simple, low power computer, which is fairly cheap and easy to deploy. I’ve got more than a few Arduino variants around (Uno, Fio, RedBoards, Nanodes, and Wildfires) and they have more than enough horsepower to do what I anticipate (reading temperature, humidity and moisture settings) but there are two things that make them less than completely satisfactory to me:

  • They don’t have any kind of wireless link. You could certainly add one of several kinds, but…
  • That adds to an already fairly expensive board. Unos are about twenty five dollars. That seems like a lot. There are simpler boards of course, such as the Pro Mini. Sparkfun has those for about ten dollars.. You can also order Arduinos from Chinese manufacturers to drive the cost down, but a board cost of about ten dollars about the minimum you can get.

It seems to me that a complete node has a minimum cost of around $20 when assembled this way. It’ll include a Pro Mini, a small wireless board, and a couple of cheap sensors. Making the node solar powered would probably cost a few bucks more. But while digging around, I discovered that Low Power Labs had a really cool little board: the Moteino. It’s a very cool little board, offers a choice of different RF choices, and includes versions with and without USB. Do I really need another different Arduino clone?

Sigh. Maybe.

Moteino from Low Power Lab

Drone Lunch…

At work, we have an informal group that is interested in drones and quadcopters. Every third Thursday, we get together and fly. Today we went over to Cesar Chavez Park for a bit of flying. I was hoping that I’d have more of my own quadcopter completed, but instead I just observed Mark fly his Bixler and his One Piece Quad, while John flew his Phantom 2 around. They should have some footage up in the next few days. To tide you all over, here is some footage that Jeremy shot on two previous drone lunches, one filmed at work, and the other at the top of Mount Diablo. Enjoy.

Pixar Drone Meet from Jeremy Vickery on Vimeo.

Making a simple RC switch…

Over the last couple of years, I’ve spent a little bit of time making fixed wing aircraft from Dollar Tree foam. The results have been interesting and fun, but I’ve found that the need to find relatively large areas to fly means that it’s harder to go fly than I would like. On the other hand, multicopters require relatively less area, and I suspect I could do some test flights almost anywhere. So, over the last few months I’ve begun to accumulate the necessary parts to put one together. As this project continues, I’ll write up some more.

But one of the things I thought about today in between World Cup matches was putting some LED lights on the quadcopter. Besides just looking cool, they are especially useful on quadcopters because they allow you to see the orientation of the quadcopter more easily.

My RC mentor Mark Harrison has some notes about he wired up LEDs on his quadcopter. The basic idea is to get some LED strips, and then power them from a brushed ESC (like this one for $4.95) driven by a spare channel on the RC receiver. It’s a pretty good way to go.

But I wondered if I could do better. I’ve made a Christmas hat with LEDs before, driven by an Atmel ATTiny13, surely I could homebrew something…

So here’s where my thought is: I want to create a small pc board with just a few components. It will be powered from the receiver, and will read the servo control channel, and will use an Atmel ATTiny85 (I have a dozen on hand that I got from Tayda Electronics for about about $1.12 each, and they have 8K of memory, plenty for this application). At it’s simplest, we want the program to configure one pin as an input, and one pin as an output. The servo control signal looks like this:

ServoPwm

The pulse will be somewhere between 1ms and 2ms long. The ATTiny just needs to monitor the channel, and if the pulse is longer than 1.5ms, it will set the output high, otherwise set the output low. And that is pretty easy.

In the past, I’ve used avr-gcc to program these tiny chips. For the ATTiny13 with just 1k of flash, that’s pretty understandable. But it turns out that with a bit of work, you can use the Arduino environment to program the ATTiny85s. This website gives most of the details. It’s pretty easy, and I got my MacBook all configured in just a few minutes. Then, I entered and compiled this (as yet untested) code:

[sourcecode lang=”cpp”]
/*
* I thought I would dummy up a simple RC controlled switch using
* an Atmel ATTINY85 processor, but code it all in the Arduino
* environment. The idea is to use pulseIn() to read the data signal
* from the RC receiver, and threshold it, setting an output pin
* if the pulse length is > 1500 ms, and clearing it if less.
* Very simple. It should be able to be powered directly from the
* receiver, and if we had some kind of FET we can switch large loads
* (like a strip of LEDS).
*/

int inputPin = 0 ;
int outputPin = 1 ;

void
setup()
{
pinMode(inputPin, INPUT) ;
pinMode(outputPin, OUTPUT) ;

// if we never get a pulse, we want to make sure the
// ourput stays switched off.
digitalWrite(outputPin, LOW) ;
}

void
loop()
{
digitalWrite(outputPin,
pulseIn(inputPin, HIGH) > 1500 ? HIGH : LOW) ;
}
[/sourcecode]

Couldn’t be much easier. If you hooked up an led with a current limiting resistor to pin 1, you can test this (I’ll put up some video once I get it going). To power a larger 12v string (like this red LED string I got for $8.90 for 5m from Amazon) you’ll use that output to power a FET to switch the much larger current, but that’s dead simple too. I can probably run the ATTiny off its internal oscillator at just 1Mhz.

But as cheap as that is, it’s probably not worth the cost of home brewing one.

But of course, you don’t need to stop with this stupid application. You have a total of five or six pins, so you can easily control multiple strings. You can also implement more sophisticated controls: instead of just using an on/off signal, you can look for short switch flips versus long switch flips, and change into different blinking modes. A short flip might make the landing lights blink. A long one turns them on steady. You could even use the ATTiny to drive RGB addressable LEDS (check out this Instructable for details). Different flips might turn on different colors, or switch between Larson scanner modes… blinking… the skies the limit.

I’ll let you know when I get more of this done.

Probabalistic Models of Cognition

This week began with a visit from Pat Hanrahan, currently a professor at Stanford and formerly at Princeton, where I was lucky enough to meet him. He came by to talk about probabilistic programming languages, which are an interesting topic that he and his students have made some interesting progress in solving difficult problems. I don’t have much to say about it, except that it seemed very cool in a way which I’ve come to expect from Pat: he has a tendency to find interesting cross disciplinary connections and exploit them in ways that seem remarkable. I haven’t had much time this week to think about his stuff more, but he did mention this website which gives examples of probabilistic computation and cognition, which seemed pretty cool. I’m mostly bookmarking it for later consumption.