Showing posts with label hacks. Show all posts
Showing posts with label hacks. Show all posts

Saturday, 22 August 2015

Getting the BMP085/BMP180 pressure sensor working with EMFCamp's Tilda MKe badge

So I've been looking at making something useful out of my Tilda MKe badge from last years EMF Camp for some time now. With its nice (backlit) graphical LCD, I decided it'd be excellent to use as a temperature and atmospheric pressure display for my workshop at work. When you're calibrating these or these or these, you need to compensate for both to get an accurate distance measurement.

I bought a cheap as BMP180 sensor (it's a pin & software compatible updated version of the BMP085) from eBay for £1.19 and hooked it up to the first working Arduino I could find (which was about the third one I tried - really need to fix the others) and got out glorious pressure and temperature data over the serial port with the help of the Adafruit library.

Great! Getting this going on the Tilda should be easy as. I knew from a bit of tinkering with the badge I did on site over the EMF Camp weekend that they were using an RTOS and they'd helpfully added a 'Hello World' app in the firmware for hacking purposes. I quickly modified the Hello World app to display the temperature.

It didn't work.

Huh. Somewhere in the back of my mind, I recalled that the Arduino Due (which the Tilda is based on) has two I2C interfaces. My first thought, confirmed by a quick look at the schematic, was that perhaps the Tilda's SDA and SCL pins that were brought out on the Arduino header weren't connected to the first I2C interface, which is what would be referred to when you normally use the wire library.

No worries. I just had to modify the Adafruit library to use wire1 instead of wire. A bit of find/replace and I was getting temperature data displayed on the LCD. Yay.

From here, it should just be a case of adding in the call to read and display the pressure.

It didn't work.

But not in the way I had expected. I was geting some pressure data, but it was way, way too low. Like it thought I was up at 40,000m kind of atmospheric pressure.

I spent a bit of time futzing about with various things. I knew it had to be related to the Tilda somehow so I looked into the RTOS and delved deep into the BMP085 datasheet. 

To measure the pressure with the BMP085 takes three steps:
  • Firstly, each unit is individually calibrated at manufacture. The various calibration registers need to be read and their values saved for later calculations.
  • The pressure value is temperature sensitive as well, so the (uncompensated) temperature needs to be read from the chip and the true temperature calculated with the calibration data.
  • Lastly, read the uncompensated pressure value and, with the aid of the calibration data and the compensated temperature, you can go through a 15-step calculation to arrive at the correct pressure.
I read in the datasheet that after requesting the pressure the chip can take up to 25ms for the ADC to convert the reading. I had a look in the Adafruit library:
  if (oversampling == BMP085_ULTRALOWPOWER)
    delay(5);
  else if (oversampling == BMP085_STANDARD)
    delay(8);
  else if (oversampling == BMP085_HIGHRES)
    delay(14);
  else
    delay(26);
I knew that doing this kind of blocking delay would stop background tasks in the RTOS from working so I changed them all to Tilda::delay() as suggested, and crossed my fingers.

It didn't work. I was getting a little bit annoyed at this point, so decided to take a little several week break.

When I came back to it I continued looking at the way the Tilda was reading in the pressure data from the BMP085. Since the temperature was being calculated correctly it didn't point to an error in the calibration data or temperature reading.

To confirm that it wasn't a hardware problem with my Tilda, I decided to try programming it as an Arduino (ie, without the RTOS). Unfortunately, if you try this in the latest Arduino software (currently 1.6.4) you'll get a heap of errors like this:
/home/peter/Downloads/Mk2-Firmware-master/hardware/emfcamp/sam/variants/tilda_mke_v0.333/variant.cpp:342:55: note: candidates are:
In file included from /home/peter/Downloads/Mk2-Firmware-master/hardware/emfcamp/sam/variants/tilda_mke_v0.333/variant.h:43:0,
                 from /home/peter/Downloads/Mk2-Firmware-master/hardware/emfcamp/sam/variants/tilda_mke_v0.333/variant.cpp:24:
/home/peter/.arduino15/packages/arduino/hardware/sam/1.6.4/cores/arduino/UARTClass.h:45:5: note: UARTClass::UARTClass(Uart*, IRQn_Type, uint32_t, RingBuffer*, RingBuffer*)
The easiest solution was to use an older version of Arduino. I had a guess at which one they'd used to write the Tilda software in the first place and picked version 1.5.7, which worked fine.

I used the test sketch from the Adafruit BMP085 library (after modifying it to use wire1 again) and I was getting the correct temperature and pressure data out of the serial port!

Now I knew it wasn't a hardware problem, I needed to see the communication between the Tilda and the BMP180, and I had exactly the tool for the job, having recently acquired a Rigol DS1054Z Oscilloscope.

I fired it up and was quickly able to probe the SCL (clock, top in yellow) and SDA (data, bottom in blue)


Zooming in on the last burst, we can use the DS1054's decode function to see what all these blips actually correspond to:


This is with the Tilda in Arduino mode - the data being read is 0xA26C20 (decimal 10644512). 


Here's with the Tilda back running my HelloWorld app in the RTOS. The data read here is 0xA277C0 (decimal 10647488). The difference is only about 0.03%. Surely not enough to account for my massive error.

Obviously I was now going to have to delve into the calculations. Here's the page in the datasheet that describes the procedure:


Err... that looks complicated. I ended up making a spreadsheet to help. I plugged both uncorrected pressure values into the spreadsheet and got consistent pressure values out. Well fuck. I was pretty sure now that the bug was somewhere deep in the RTOS and I really didn't think I was going to be able to find it. Unless.... 

I'd been working on the assumption that the calibration data was being read ok because the temperature was being calculated correctly. However, after working through the calculation in my spreadsheet I knew that most of the calibration data doesn't get used until the pressure calculation.

I got the Tilda to spit out the calibration data in both Arduino mode and the RTOS and lo and behold, the values for AC1 and AC5 differed markedly. I guessed that some background task in the RTOS was interfering with the read. I had a stab at fixing it by adding in a delay into the library:
  Wire1.begin();

  if (read8(0xD0) != 0x55) return false;
 
  Tilda::delay(5);

  /* read calibration data */
  ac1 = read16(BMP085_CAL_AC1);
  ac2 = read16(BMP085_CAL_AC2);
  ac3 = read16(BMP085_CAL_AC3);
  ac4 = read16(BMP085_CAL_AC4);
  ac5 = read16(BMP085_CAL_AC5);
  ac6 = read16(BMP085_CAL_AC6);
Which worked perfectly! All of that time and frustration was fixed by a 5ms delay in the right place, apparently. 


Niiiiiiiice! I'm not exactly convinced the temperature is 100% correct. It seems to be a couple of degrees warmer than I think it should be. The pressure looks to be correct though. 

Next time: Making it into a usable barometer.

Wednesday, 14 March 2012

Big Muff clone completed

I've finished my clone of the well-known Big Muff distortion pedal. I painted it with some grey primer and then with a design of Cardiff Bay as I have a vague notion of making myself a range of Cardiff-themed effect pedals. Total cost in parts was around £16-17 and a lot of that is because I bought the extortionately expensive switch from Maplin instead of pretty much anywhere else.

It sounds quite a lot like the original as far as I can tell. It is REALLY LOUD, and is unfortunately not very useful for playing in our apartment as I get the feeling I must be annoying the hell out of the neighbours, even at low volumes.

Next up will be a Small Clone clone. A clone2 I guess. It's a chorus pedal that was used by Kurt Cobain on Nevermind apparently. I've ordered up the parts from far-flung ebay sellers across East Asia, so they'll take at least a couple of weeks to get here, which gives me plenty of time to change my mind and start and abandon another several projects.

Sunday, 11 March 2012

Big Muff clone



 This weekend I've been down at Cardiff Hackspace building a clone of the well known Big Muff distortion pedal, first getting it working on a solderless breadboard:


Then I built it on some copper stripboard, but for some reason couldn't get it working. After checking, rechecking and re-rechecking, I finally spotted the problem:

See the problem? No?

There it goes - at one of the points where I'd used a drill bit to break the copper track I hadn't quite broken it completely. Those holes are 2.54mm apart so the bit of copper that was left couldn't have been much more than 0.2mm wide, but it was enough for electrons to squeeze through and stop it producing any sound.


Once that and several other problems were sorted, I brought it home and tried it out. It doesn't sound exactly like the original, but it has a nice tone with loads of gain. Hopefully this week I'll put it in a nice enclosure.

Saturday, 3 March 2012

Soldering iron power LED

 For xmas a couple of years ago my parents bought me a nice temperature-controlled soldering station which I've been using to build all my half-completed projects. It works great, but it has one small problem: the LCD display isn't backlit so, at a glance, it isn't obvious that the power is on. This isn't normally a problem but if I'm working on something that means I'm soldering something and then going back and forward to the computer to program an Arduino or whatever, it's possible to forget the soldering iron is on.

And then go to bed.

And then go to work.

And then come home and find out that there's been a 50W desk-mounted heater on for 24 hours and somehow we still have a home and not a smouldering ruin.

The solution to this problem is trivially easy - mount an LED on the front to make it obvious that the iron's on. First thing we need to do is open up the soldering iron and find a power source to hook our LED up to.

 This is the main PCB for the iron, and at the top left is an LM7805 linear voltage regulator that supplies the 5v to power the control circuity. Perfect and has long leads that we can solder to. If you're looking at the front of the LM7805, the three leads are Vin - GND - Vout.


 A quick check with the multimeter to confirm. 

I come to a small problem here - how am I going to solder on the inside of my soldering iron? I briefly consider using the soldering iron itself and then remember that I have a butane powered soldering iron for just these sorts of occasions:


I dig out a 5mm red LED and find my LED calculator to work out what current limiting resistor I need. Looks like 150 ohms will do the trick, which is one of the several values I have. 10 minutes and some dremel action later and we have this:


I should have used some heatshrink, but I couldn't find any. It should be ok like this though. The LED fits in pretty snugly but for peace of mind I might stick some hot glue on the back to hold it in. But does it work...?

Power off

Power on!
Success! And all done before breakfast on a Saturday. Quite good fun in the end, and if it stops me from accidentally burning down the house, well that's just a bonus.

Wednesday, 29 February 2012

Oscilloscopes


This is a nice 20MHz analog scope that was donated by UWIC to Cardiff Hackspace. It's awesomely retro but works great. I don't know how I ever managed to do any electronics without access to an oscilloscope. I keep meaning to use it to display some graphics. I even got around to getting some DACs (Digital to Analog Converters):


Yeah, soldering that onto the breakout board was quite tricky. The main body of the chip (the black bit) is only 1.75 by 1.3mm big. I haven't got around to doing any more than that, so it's in the pile of ideas and half-completed projects.

Tuesday, 28 February 2012

LED forest


 Yes, that is quite a lot of LEDs. I did this for a test of my still-in-progress sunrise alarm clock that I started back in October and now will almost certainly not get around to finishing before winter is over rendering the whole thing completely unnecessary.


Ahh, but it looks so pretty.

Monday, 27 February 2012

Reprap Heated Bed Testing


 This is the heated printbed from Iain's reprap being tested after he'd replaced the nichrome wire based heater with some chunky high powered resistors:


Once all soldered together and attached to the build platform with metalised epoxy, we fired it up and checked it out with a thermal imaging camera graciously loaned by my work:


Interestingly, the parts where there isn't any Kapton tape show up as much cooler - not because they are any cooler but because the bare metal is reflecting an IR image of the cold window. Anyway, the heater seems to work pretty well as Iain's reprap is churning out all sorts of interesting stuff.

Sunday, 26 February 2012

Mintyboost clone


This is a clone of Adafruit's Mintyboost that I made to take to Glastonbury last year to keep my phone charged. It's basically the suggested schematic and layout from the LT1302 step-up converter. It turned out pretty well - I like that its not much bigger than the two AA cells it runs on. Could do with a nice 3D printed case for the component side perhaps.

Performance wise, it was a bit disappointing. I think that was quite a lot to do with the crappy batteries we took with us and that were available on the site. I didn't actually test it very much. At some point, I'll get around to doing a proper test with various batteries.

Friday, 24 February 2012


Unnecessarily robust reclaimed pallet-wood table, built for our allotment.

Thursday, 23 February 2012

Replacement beer fridge thermostat


This is an Arduino-based thermostat I made for the beer fridge that Tina found in the rubbish outside our flat. It worked fine for a few months and then stopped - the mechanical thermostat had crapped out.

Coincidentally, I had a thermocouple and a MAX6675 thermocouple amplifier hanging around that I'd purchased with my Sparkfun free day winnings so I threw this together and installed it into the space where the old thermostat had been. Since I had heaps of I/O pins left I added a 7-segment display to display the temperature on the front of the fridge.

It works great, and is currently installed at Cardiff Hackspace, cooling our beers.

Monday, 22 February 2010

GPS: Working! (well, nearly)

So I got my GPS module working.. sort of. After stuffing around with it for ages it turns out I was just being daft, and after fixing several obvious problems in both hardware and software I was getting lovely NMEA codes out:
$GPGGA,202429.009,0000.0000,N,00000.0000,E,0,00,0.0,0.0,M,,,,0000*08
$GPGSV,3,1,12,27,89,000,33,16,66,000,,15,54,000,,25,50,000,*7C
$GPGSV,3,2,12,14,31,000,,19,28,000,,13,24,000,,17,21,000,*7F
$GPGSV,3,3,12,23,18,000,,05,08,000,,29,01,000,,02,-2,000,*68
The $GPGGA line is positioning data and the $GPGSV lines are data about the satellites we can see. Unfortunately from the flat we don't have enough sky view to be able to get a fix. The GPS is only tracking one satellite which is only good enough to give us the current time as shown in the first line (20:24:29).

Next plan is to write some software to do something useful with the data...

Wednesday, 17 February 2010

Homemade Toner transfer PCBs

We've just recently bought a laser printer so I've been trying to make some decent printed circuit boards with the toner transfer method, where you take a reversed printout of your circuit and iron it on to plain copper-clad board, then etch the board and the toner resists the etchant, and the circuit remains in copper on the board.

That's the theory anyway, but finding the right paper is a problem. You need a glossy, waxy paper that will easily come away from the toner when you are done ironing, but most papers just fall apart and you are stuck with half a sheet of paper firmly attached to your circuit-board-to-be.

Many people on the internet seem to use magazine pages, but I have found them to be uniformly rubbish for fine-pitched traces.

For future reference, the following papers don't work:

Buzz (Cardiff gig guide)
Guardian Weekend Magazine
New Scientist
Look Magazine
Cotswolds catalogue
Domino's Flyer.
Tesco "Value" glossy photo paper
and regular Kitchen Paper, which I thought would work well, but doesn't seem to want to release the toner onto the copper.