Much Ado About Logging...

philf

1 kW
Joined
May 28, 2008
Messages
332
Location
Burlington, ON (Canada)
So...

We've all seen it mentioned in various places throughout the forum. The latest versions of the Cycle Analyst firmware support it. And even without it, attempts have been made to gather empirical data from the operation of an e-bike just the same.

Yup. We're talking about logging.

When Justin started out on his Cross-Canada trek, he'd intended to continuously collect data from his rig (all the time it was operating) for future analysis. The telemetry system was nothing more than a laptop computer connected to his Cycle Analyst via a serial connection - but before he got too far into his trip, the laptop failed and there were electrical issues with the way the power supply was hooked up, to boot.

The idea, at least, was interesting to me - though the rudimentary data you can get from the CA's view of the world seemed a bit incomplete for doing anything more than comparative work. Observing consumption figures without knowing what the terrain was like, for example (are we going uphill?), would only tell us that we're using "more" - without indicating "how come".

Whatever one does with the data, the point is that a moving e-bike is no place for a full-fledged personal computer. Its bulk notwithstanding, the energy requirements make it impractical. I'd wondered if some handheld device, like an iPAQ or something, might somehow be made to work - but this still seemed inappropriate (or expensive). Commercially available purpose-built data loggers exist, but these get REALLY expensive for anything that gives you an ability to customize what it does.

Being the kind of guy who likes to play with microcontrollers, I'd wondered if some simpler solution might be cobbled together. Something that could take the incoming serial data and stash it on some form of memory device for later upload to a PC. I quickly learned that reading and writing from a variety of memory devices was no problem - but, if one wanted to do it "conveniently", one had to go through a few hoops. As an example, it's not that hard to build something that would write raw data to an SD memory card - but, if one wanted to put the data on the card in a fashion that was meaningful to a PC (i.e. - using some form of known file system), the coding overhead became quite huge, as did the memory requirement of the microcontroller utilized.

Then, while looking for something else entirely, I stumbled across GHI Electronics and one of their particularly interesting products. http://www.ghielectronics.com/product/1. The uALFAT ("Micro AL FAT") is actually just an NXP (Philips) microcontroller into which they have toasted firmware with a very specific purpose - to allow simple devices to perform operations on files stored in the FAT16 or FAT32 file system (with long filenames!) through a high-level interface, thus alleviating the need for the host application to understand ANY kind of file system at all!

I had to have one.

So, looking at the available options, I went for one of their "modules" that contains the uALFAT chip, as well as an SD card socket. Communications with the core of the thing is through a handful of pins brought out on a 16 pin header. The device understands regular serial (you can actually talk directly to it through a regular serial port - albeit, at TTL levels - using nothing more than Hyperterminal), as well as SPI and I2C. I was hooked!

Grabbing the microcontroller of choice (yup, the Microchip PIC16F690 of which I have too many), I quickly breadboarded a system to talk to the uALFAT. Having just ONE serial input wasn't enough, though. I had originally envisioned up to FOUR serial inputs - streaming data to four different files concurrently from different sources (with tagging to help line the data up after the fact), and the PIC only has a single port on it. So, I settled on using an exteral dual UART that would give me two serial ports in addition to the one built-in, and which used the same SPI or I2C interface to address it as the uALFAT - thus eliminating a lot of un-necessary interfacing complexity (this adds complexity to the firmware one must write to control the things, though).

After some hacking about, THIS took shape:

logger%20breadboard.jpg


One of the problems one runs into with most modern chips is that they only come in packages which are suitable for surface mounting, so to work with the dual UART of choice, I had to make an "adaptor" board. The extra components are the crystal circuit for the baud rate generator, and a couple of discretes that are used to interface to the inbound 5V serial signals - this thing is a 3.3V part....

loggeruartcu.jpg


After some fooling about, I quickly had a "proof of concept" that clearly showed me that this was feasible. So, with some further "hardware doodling", and a desire to make this thing fit into a package that was as small as possible, I drew up the final circuit in Eagle and mapped a printed circuit board for the thing. The added "flying" components pictured on the breadboard, above, have to do with some differences in the interfacing requirements of the uALFAT versus the UART if they are to share the same communications bus (I used SPI to simplify the software somewhat), and to permit a particular non-standard signal I was anticipating to be passed in as readily as the signal from the CA. More on that later.

The resulting proto-board...

logger%20unpopulated.jpg


It's actually two sided, with about twenty manual "througplates" required to get it working. Once populated the, the uALFAT module plugs in to a header and piggybacks on top of the whole affair. The result fits in a package about the size of a deck of cards. I had originally intended to have jacks on the back of the case for the inputs, but even these required more real estate than I had, so wound up being "dangling" connectors. I used mouse/keyboard connectors for these.

logger%20populated.jpg


You'll notice a bunch of loose wirewrap wires on there... After fully populating the board, I made the horrible discovery that I'd flipped the header when doing the PCB layout. The circuit would work, if the uALFAT was mounted backwards, but this was obviously no good - I cut the traces on the 8, or so, signals that needed to be reworked and wired them back u correctly by hand. The revision has already been made to the PCB layout for the NEXT time. Doh. Hey. I *did* label the board as version 0.1a :).

So, with everything together, and the proof-of-concept code still running, the device does this... It watches the two serial ports (I reserved the third, on-board one, for debugging/monitoring during development), and if it sees incoming data on either of them it opens a file on the SD card and starts streaming the data to that file. Each port creates its own file, and (assuming that the incoming data is plaintext with a carriage return after each line), I've added a "serializer" field to the data that allows the two files to be merged into one representation of real-time events.

What's on the second port that required a little bit of additional circuitry?

One of these...

gps%20puck.jpg


This GPS Puck from Garmin is an OEM device that, once powered, continually streams data (NMEA format) about where you are, how fast you're going, elevation, how your fix was calculated and by how many satellites, etc., etc.. It's damned sensitive. I can get a fix IN MY BASEMENT with this thing! I've set it up to give me output every second, to match the CA - the data stream from the puck includes the real time (VERY accurate), too, which is something else that nicely augments the data from the CA.

The whole thing wound up quite tidy - couldn't resist using the "Bicycle" card deck as a size reference..

Logger%20cards.jpg


I can't put the cover on the front with my diagnostic connector hanging out, but that didn't stop me from going for a run with it... There's a long way to go on the firmware (and some software to massage the raw log data), but I thought I'd share all this as I've had a few conversations about this with others on the forum, in private, and there does some to be some interest in projects like this...

Logger%20Operating.jpg
 
Great !
Have a look at
http://www.b-icycle.com/home.html
hook-up a CA with something like : http://tme.pl/dok/a04/btm222_datasheet.pdf
and use your Iphone as:
GPS, Maps, Music, Video, Data Logging, setting speed limit, current limit...
 
PhilF, This is very nice !!.. besutifull and helpfull project!! you shold contact Justin for the V2.0 of his next voyage!!

This is a must to have you on this forum Phil ! :wink:

Thanks for every descriptions you did of your project!

Doc
 
I haven't posted much follow-up to this, and my reasons for this installment are unfortunate...

I've taken this device out for a number of runs over the last few weeks - logging REAL data about energy consumption using myriad controller/battery/motor configurations. And I've had a great deal of fun mapping the data (thanks to the GPS feed!) with the CA output to come up with some interesting findings that, frankly, I haven't been able to fully process (still working on some code to filter the data). This exercise has been useful in making me consider what I REALLY want to run as my "normal" setup.

Today has been brilliant, weather-wise, and I'd arranged to go out geocaching (http://www.geocaching.com for anyone who doesn't know what that's about) with some of the family - who were driving in from nearby Toronto and Caledonia. We'd targeted "11ish" as a starting time, just to scope the maps and get a quick lunch before heading out.

Unfortunately, when my nephew and his girlfriend arrived, I had lost track of time and was in the middle of swapping the rear wheel on my test bike - taking off a GM 500W 36V unit and replacing it with a wheel with a Crystalyte 406 mounted in it. I got caught up in the "how ya' bin?" and "good to see ya" stuff, and neglected the fact that I had dismounted the datalogger from the pack, along with the GPS puck, and placed them - *gulp* - on the rear deck of my car out in the driveway before I had started the swap - fully intending to have the bike back out there in short order before anyone showed up. It didn't happen.

Anyways, when we were all together and had gone through the preamble to the rest of the day's events, we headed out for a quick bite of lunch. We needed two cars, and the way the driveway wound up - it was my sister's... and mine. Owing to the way the house is set up, the descent from the front door down to the driveway does NOT force you to approach the car from the rear. I never walked past the back of my car at all before departing...

Long story short - it was while exiting the parking lot at the lunch spot that we caught the sound of a horn. Someone was trying to get someone's attention - but it was hard to discern exactly who. I kissed it off - the light went green - and we carried on in our two-car convoy.

I had been content to follow my sister most of the time, but passed her on the way up the Niagara escarpment to our geocaching destination. It wasn't until we got there, and she pulled up REAL close to the back of my car, that she started waving me down. I got out, had a look, and... P*H*U*C*K (sorry - I still haven't gotten over the STUPIDITY of this. I have a RULE about putting things down on cars, and I've LECTURED others about it passionately. But here it is)... There was the GPS puck, wedged in under my rear spoiler. My heart sank. The thing that had been there with it was... GONE.

My family know that I don't have gobs of spare time, and they could see by my face (filled with obvious "unhappiness" - I'm REALLY reserved in situations which would drive many to murder or self-destruction) that this was both a loss and an an internal exercise of self-flagellation over the breaking of a personal code. They offered to backtrack and look for it, which we did - but I had little hope. Either it had been crushed by another vehicle, or - being the enigmatic shiny aluminum device that it was - quite probably picked up by someone passing by. It was beautiful today. LOTS of people out on foot/cycle.

I'll try to compile something meaningful from the data I gathered in the last few weeks (and still have - some of the data went with the device). Dunno when I'll get to building another. I used actual vacation days from my "day job" to do this thing...
 
awh man, soso sorry. been there done that too, usually it was the gas cap and once a coffee cup. never something so valuable, did you go back and look? maybe it got hit by the side of a tire and spit out sideways outa the roadway.

but i was lucky, a trucker blasted at me until i stopped and got outa the car before driving away from the truck stop, at the beginning of another 1100 mile trip, the other time was coming back on another trip, heard the gas cap roll off the top, looked in the side mirror, and saw it roll down the freeway behind me off into the grass. was able to find it too. the coffee cup was on my front bumper, it rode there for 5 miles, then when i turned into a driveway, heard it hit and knew immediately..

your stuff is so cool too. you gotta go look, so sorry, i really am.
 
i use those keyboard connectors for my hall sensor connections
 
A truly beautiful build - I feel your loss and look forward to version 0.2 sometime in the future. Get out and ride while the weather holds.

I am no electronics genius - just a BSME that diverged into IT with delusions of grandeur but I am a data junky and want to log everything. The reason I found this relatively new thread is because I got sidetracked searching the forum on datalogging as I was installing my Cateye speedometer because the speed indication on my CA quit working when I changed controllers (one of three C'lyte controllers gave speed indication when wired as directed) and I didn't want to ride without speed indication and distance data.

What is the potential for using a MID, subnotebook, cell phone, netbook or the like at least as real-time interface. Many of these devices have built-in GPS which, added to Jason's interface gets you the CA data but it seems to me, using lithium batteries, an interface to the BMS would also be in order - some way to monitor individual cell voltages at a relatively high rate or a lower rate capturing excursions. All the action is going on at the cell level and I have no way of monitoring this other than by opening up the BMS and sticking in a DVM – somewhat impractical to do frequently while riding. I am also looking to do some long range stuff with multiple batteries where the data from each cell within each battery. Without searching every reference to BMS on this forum, would one of the existing BMS designs integrate into a complete data management system like this? I could see this device on board as datalogger but also having a USB connection for some external display device. Watching engadget (engadget.com), there are a slew of MID, touchscreen, GPS enabled handheld devices with open enough interfaces to allow for application coding, most of which have a serial interface. I love my cycle analyst, but in this day and age two alphanumeric lines of 32 characters each (or whatever) seems a bit limited.

Bring all this to an eight inch display running Ubuntu or Windows 7 and I'll write code to display it in realtime with graphs and energy overlays on maps and do predictive range estimates against historic load data and upload it to a mySQL database on a website every time the netbook connects 3G with webcam footage and...
 
Back
Top