Archive for April, 2014

h1

AAs vs rechargeable and tutorials

April 30, 2014

Ok, I’m writing up the tutorial. Or I would be if I wasn’t writing this.  In the comments for the photo essay, punkiepunkie mentioned putting this together with AAs instead of the rechargeable solution I’ve got going on.

When I started, the Electric Imp drew so much power, AAs seemed crazy to me.

Once I got the battery stuff mostly settled, though, I had trouble killing off even my littlest LiPo. With 150mAh, my littlest Lipo looks like it will last 20+ days.

According to Wikipedia, I can expect 1500 mAh from normal grocery store AAs. I’d need to put two in serial to serial to get 3V. Oh, looking at the power section of the Electric Imp’s breakout board description, I  need 3.3V to 17V, so three or four AAs in serial would be best. Lots of power there, probably can go a year between new batteries, at least six months.

I like rechargeable batteries but it definitely adds a lot of cost to my build. If I take out the LiPo charger, the LiPo battery, and the fuel gauge, that makes the build cost $53 instead of $91. (It also makes the build easier.)

There are three different 4-AA holders, all of them $2:

I’m so attached to the fuel gauge, this is difficult. But Electric Imp has a built in voltage meter (hardware.voltage() returns the current voltage in floating point), I was only using the fuel gauge because LiPos are so tricky.

It is hard to get attached to a method of doing things and then try to change. But if I’m going to write a tutorial (I am, I am!), it would be better to focus on the important parts (the Electric Imp parts). I can easily put the LiPo stuff in another file and tell people how to upgrade.

Now I need to redraw my circuit, get a battery case, and take more build pictures. And fix my code. But this makes me happy, it is hard to shift directions but I wouldn’t have known I was making it unnecessarily complicated if punkiepunkie hadn’t mentioned a different path.

I don’t doubt there is goodness in open source (I use Wikipedia daily) but I don’t think it has every applied so directly to one of my projects. It is neat.

 

 

h1

Tootsie’s has the best cappuccino

April 28, 2014

There is a little restaurant in Palo Alto, really on Stanford, sort of near the mall. It is frou-frou food: if you get the fritatta, you don’t get to choose what is in it, you just get to be happy with the deliciousness that comes to you. With Nutella toast.

I love Tootsie’s. I love the cappuccino with its microfoam and deep espresso. I love the tiny donuts (zepole) that make me remember a time I liked donuts. The salads are great, the fruit is fresh, if you are there when they have macarons, get some. I sit outside, courting a pink nose, because the lavender is about to bloom (and the roses are already).

So, though it is a bit closer to her house than mine, it is absolutely no hardship to meet Elizabeth at Tootsie’s to talk about the are-you-ok manatee. It was almost enough to make up for the loss of the mock-up manatee that was so soft and spent so much time in my lap last week.

I’ll be getting a prototype in the next few weeks, probably with the LED and accelerometer sewn in. She’ll have to deal with the boards, though we’ve figured out that right angle connectors would have been better for the next revision. The height of the wires ended up being a bit, um, deformative to the stuffed animal.  I don’t know if Elizabeth is going to try modifying the sewing pattern to put more pocket inside the manatee or if it is going to be a bit lumpy.

Of course, it may not be a manatee. Elizabeth warned me that a whale would be good (for the twitter connection) and a narwhal would look great with an LED on the top of its tooth. I’m excited about all the options.

As punkiepunkie noted in the comments, I did update the agent code in github, cleaning up the comments and starting to indicate what other people are likely to want to change. I’m not done but I am very excited someone is trying this out. I do intent to add comments regarding using AA batteries and non-Sparkfun accels to the device. (Though, I’m hoping to make this a tutorial for Sparkfun. No, I don’t know how to do that. One step at a time… I’ll write up a proposal for the tutorial soon.)

I’ve got a few other things that need doing this week. I was cramming them in since the weather is about to get warm and I’d like to play hooky and go to the beach. But now I’m cramming a bit so I can stop mining salt (short contract) and get back to my gadget.

h1

Manatee photos

April 23, 2014

I usually say that if I am not blogging about my personal projects, I’m not working on them. That isn’t true this week.

I’m afraid that if I take the time to write everything that is bursting in my head, I won’t get to continue working. So I’m going to just put up some photos. These aren’t build instructions, maybe they are just place holders for all the stuff that should (and some that shouldn’t) be in the ayok build notes.

Choosing an LED has been tough. In that pic there are two RGB LEDs, both the same power but the big one (10mm) has a diffuser. The three little ones are red, yellow, green individual LEDs. They are from LilyPad which means they are built to be sewn into things.

Elizabeth made a manatee prototype, including the diffuse LED as a nose and the smaller three as buttons.

For the nose, the question of how to attach it to the fabric came up. Hot glue seems to be my solution for everything but that does make fabric feel yucky so I cut out a perfboard. Elizabeth then used the holes in that to build a prototype nose.

But before I show you how she put it together, here is the base-model manatee. The pattern came from cationdesigns.

It sits up unaided (thanks to some sand weights in the tail and lower belly). It is soft and utterly adorable.

But less so when you add an LED schnoze. That manatee body doesn’t have any stuffing but, even so, not the look we were going for.

The button style LEDs are kind of boring. And since they don’t color mix we lose a lot of flexibility. (All GPIOs are the Electric Imp are used!)

Using conductive thread seemed neat but the interface between pins and wires is not easy. To get the LEDs to light, I ended up knotting all the plus and all the minus sides.

Of course, the thing the thread likes to do most is make knots so that part was easy. I wasn’t thrilled by the look or the electronics side of those buttons.

Putting the tummy in the empty cavity of the body looked nice but that isn’t exactly realistic, the LED can’t just float around in open (deflated) air.

Elizabeth suggested that since we are using a double layer fabric, we could put it between layers . So I unraveled some of her work and shoved it in a newly opened seam in the back.

With the LED in between the two layers of fabric, t gave a nice glow. We are going to try that some more, to give it a tummy glow. I hope that works. It is better than our fallback plan of making the big diffuse LED into some sort of tophat.

The new manatee model also came with a pocket for electronics so we could make things fit. But before we see that, let’s look at the electronics build.

First a parts list in graphic form. This is also in a SparkFun wishlist.

Next I tried to show how things would get assembled. I don’t think I want to do a step by step assembly. The soldering isn’t too tough… But here is what I took while I built it.

First attach headers!

Next, attach red to ground and black to power. Sigh, that is really what happened in the next pic.

I figured it out two days later when the fuel gauge would not work, not even after I fixed its I2C lines. So, maybe this pic won’t go into the instructions.

I need an extra set of I2C pins and another ground pin. I devised this stupidly complex way to go about it involving another breadboard.

I’m not sure how to explain that you can follow this tutorial even if you solder like a drunken sailor. In high winds. Also, you don’t have to do this because you don’t need all these pins that I thought you might want.

Happily at this point we can go back to the manateee. Which I’ve named Hugh. At least this one is.

He’s got a pocket in his butt. This is what needs to fit.


From another angle…

I have more electronics than will fix, though it isn’t too far off. The problem comes from using up-down headers. With right angle headers, this would have worked better. So do I go back and re-do it with right angles?

Because while I jammed everything in there, it appears that Hugh has some unsightly wires coming from his, um, backside.


Ok, this one I took for twitter because I was getting Hugh’s Electric Imp to work. I found a short with the I2C connection (bad solder joint) and then the fuel gauge ground/power swap.


There are some software oddnesses with running two Impees from one account. It took me awhile to get it running. I’m still not sure how to differentiate between the two units (though I’m pretty sure there is a way).

Having gotten it working, I took some pictures today to help explain the wiring. The power subsystem could all be be stuck together: hot glue!

Actually, I wanted that foamy double stick tape but couldn’t find any. Note that only two sets of wires go out of the frame: I2C SDA (green) and SCL (yellow); power (red) and ground (black).

Those go to the Electric Imp board. Two bundles of wires then come off the Electric Imp board: the LED and the accelerometer. The LED has a red (Imp pin 2), green (Imp 5), and blue wire (Imp 7).

The LED pins are:

  • the longest is ground (black)
  • the short one next to that is red
  • the remaining inside one is green
  • the last one, outside, opposite red is blue

The accelerometer has power (red), SDA (green) , SCL (yellow), (nothing), Wakeup (violet), and ground. These all go back to the Imp board.

Finally, the un-taped, un-hotglued ball of wires on my desk.

So you can see, progress is being made.

The second set of electronics work. I have enough drawings and pictures to describe how to do the build (if not enough to do the stuffed animal). The code is working though I have some tweaks (multiple users need different names, handle email, and separate test from real code then comment it).

But Elizabeth is getting this set of electronics this weekend so expect another manatee soon (and maybe another set of electronics).

h1

In which it becomes obvious that I’m not in marketing

April 18, 2014

I want to name my are-you-ok gadget. I mean give it a proper name, something catchy and jingly. Something that takes the awkward description I give and then the example and turns it into a blindingly obvious system.

Unfortunately, I am not good at this. If it was up to me, all our pets would likely be called Bob. (It would make things easier, don’t you think?) Also, when working on a tshirt to improve posture, my favorite name (and the working name of the project before my husband explained the negative connotations): StraightT!

I thought to ask Elizabeth but she was the one who wanted to have it post to Facebook with a status of “Maybe not dead”. I find that hilarious but I’m not sure everyone would.

In the code, I call the thing ayok (for “are you ok?”). It is unwieldy to pronounce, I don’t say it very often. Even in my internal monologue.

A day or two ago, I had a brainstorm and decided that the name should be Mandy-the-manatee since the plush is (currently) a manatee. And Mandy is sort of a portmanteau of Maybe Not Dead (ok so Mande might be “better”).

I emailed Elizabeth to tell her the good news. I hadn’t considered it before but Elizabeth had this rant about how pre-named plushies are wrong. Wrong, I tell you. Owners should get to name their own animals.

Which, of course, means I immediately want to name mine Bob.

But back to a system name. How about POM for piece of mind? I bet the pomegranate people not appreciate it. Though their little heart logo would be nice too. As long as I’m going to infringe, might as well go all the way.

POL or Polly for proof-of-life? That’s another name for the animal, not for the system. Though Pet Polly isn’t bad and tells you what to do with the device.

What about GlaDos due to the “Still Alive” (also due to innate creepiness of having a stuffed animal spy on you)? I suppose that has a copyright or something.

Anyone want to suggest a name? The bar here is quite low.

 

h1

Fuel gauge for batteries

April 16, 2014

Lithium polymer (LiPo) batteries are strange beasts. I can’t simply measure the current voltage and tell you how full it is. (You can on throw-away AAs.) Worse, a nearly-full battery and a nearly-empty read about the same voltage until it become really empty and the battery dies.

Determining the LiPo battery’s state of charge requires an algorithm that monitors the battery over time and over a few charge cycles. The simplest way for me to do it for the are-you-ok widget is to buy the monitoring in the form of a small board: the LiPo Fuel Gauge.

However, while not adverse to reading datasheet, I just wanted to plug this board into my system and have it work. I did read the example code: it reads the percent from a register and sets up an alarm-interrupt I don’t care about.

I should have been more suspicious when my full battery read a state of charge (SOC) that was in the 30,000s but really, I didn’t care the actual number as long as I could see the power go down over several days. Except, with deep sleep working, the power is taking much longer than several days to go down. Last time I read the battery, it said 18664. Reading the voltage with a DVM showed it to be very high.

Then I broke that battery’s wire so I need to switch to another module (a very small one this time so I can check the fuel gauge better). Also, this time I’m going to read the datasheet, to get it set up properly.

I figured I might as well take notes here. Maybe note a few things about how to write instructions since that’s also on my mind. The intro starts off pretty good and a line caught my eye in the third paragraph.

A quick-start mode provides a good initial estimate of the battery’s SOC.

Good, that’s what I need. And I already know I can connect to it, at least to read registers. I can probably write registers but I don’t have that code for this chip.  (That’s like 3 minutes of coding and 4 minutes of testing so this isn’t a major deal.)

Next in the datasheet is a bunch self-congratulatory blahblahs that don’t help me solve my problem. Why do they do that? I already bought the thing, quit selling it to me and tell me the good stuff. I get through the “for the electric engineer” tables (those can be important to me but on first skimming, I tend to let the data slide over my brain), then  messy graphs followed by more coy hinting at their algorithm and finally to a section called IC Power-Up.

When the battery is first inserted into the system, there is no previous knowledge about the battery’s SOC.

Since the LiPo’s state of charge depends on it’s history, the first power up is tricky. It goes on to say about how the fancy-schmancy algorithm will converge with time. This was what I was depending on before (and about where I stopped reading the datasheet before). Eventually, the fuel gauge figures itself out, after a few charge and discharge cycles. Of course, if you are talking about months, then that isn’t so useful.

I want a way to charge the battery fully (because the charger says it is done and it have been charging for several hours) and then tell the fuel gauge it is full. Ideally, that will be covered in the Quick-Start section that is next.

A quick-start is initiated by a rising edge on the QSTRT pin, or through software by writing 4000h to the MODE register

Yay? Ok, so now I know how to go into quick start mode but what does that do? It doesn’t tell me. This is why I hate reading datasheets sometimes. It is like talking to a recalcitrant four-year old.

Moving on, maybe things will become clear if I keep reading. The next section is ALERT Interrupt. I don’t want that (not enough pins on the Electric Imp, maybe I could use pulldowns to double up the wakeup pin but that seems too much like work; I don’t mind polling the fuel gauge every hour since the unit needs to wake up and check-in to the server anyway).

The next section is on Sleep Mode. That should be interesting but since I can’t kill batteries, I haven’t done the last few power optimizations: put this and the accelerometer into sleep mode when they aren’t needed.

Let’s see, I can reset the fuel gauge, as though I power cycled it. Whee. (That was an unenthusiastic whee in case you couldn’t tell from the tone.)

Now for the Registers section. As a software person, this is the section I usually skip to. If this datasheet was a walnut, this would be the delicious meaty core.

Usually.

The SOC Register really should be giving me a percent full.

Units of % can be directly determined by observing only the high byte of the SOC register. The low byte provides additional resolution in units 1/256 %.

Ok! So my last reading was 18664, in hex that is 48 EB. Looking at only the high byte hex 48 equals decimal 72. My battery is 72% full. Look at that, it makes sense now.

On April 8th, my reading was 24839, in hex that is 61 07. So hex 61 is 97%.

Essentially I’ve been reading it wrong. To be fair to my previous self, I did look at the figure that showed how to read it which says something different than the text. (Different and implausible but I know why I decided I could just read the 16-bits and concatenate them together.)

This is an easy fix to my software. Where the code used to have

local tmp = (data[0] << 8) + data[1];

I modified it to

local tmp = data[0];

As I only care about the top byte.

Well, while I knew I needed to fix the output issue, the information was decreasing reasonably as I discharged the battery, I know there was just a units or conversion issue. That isn’t why I’m reading the datasheet. I need to know how to tell it that my battery is full. But I should only do it in a manufacturing mode or something, definitely not on every boot or even on every power cycle.

Happily, the next table is about the MODE register which mentions the Quick-Start command. That references the “Quick-Start description section”, what I read before that mentions there is a Quick-Start mode but not how to use it. Searching through the document for Quick-Start leads to nothing.

The MODE register section says the only valid setting is the quick-start setting. I feel like I’m reading an Escher print turned into words.

Ahhh, the version register is next to be described. What could possibly go wrong? Well, for one, it doesn’t tell me what to expect. I read the register and get a value. Is it a good value? Many (most!) vendors suggest what to expect, reading the version register (or whoami) is a great way to verify that I’m communicating properly with the chip. Alas, not for this IC monstrosity. (Ahh, it isn’t that bad, I’ve read far worse datasheets but this one is remarkably easy to pick on.)

I mean, in the next section, it goes over the CONFIG register (which incidentally is where the sleep mode is set). There is a bit in CONFIG called X (Don’t Care).

This bit reads as either a logic 0 or logic 1. This bit cannot be written.

I suppose it is my scotch-and-ice-cream dinner or the last nine pages of nonsense, but this statement strikes be as funny. “This bit cannot be written”, wanna see me try? Because I can write it. The IC may ignore it but I can so write it if I want to.

Next there are some applications of this chip, how to use it for multiple LiPo cells. That’s all very interesting but actually not.

Then there are several pages describing the communication method (two-wire so they don’t have to license from whoever holds I2C’s patent, how can you patent such things?). I don’t care about this as I have that part working.

And then the end. It includes an address only about five miles away. I want to go and ask them to explain to me if there is a way to tell their chip that the battery should be pretty full since I just finished charging it during my hokey manufacturing process.

Instead, with the data format fix, I’ll just plug in another battery and see if it is recognized as full and discharges normally. It is supposed to converge, might as well let it.

And the next time I see a MAXIM part, I will (once again) read the internet-supplied example code and not bother with the datasheet until I absolutely have to. Though, I’d still rather buy MAXIM than Infineon parts.

But that’s a separate rant, for another day.