Show Posts
Pages: 1 ... 22 23 [24] 25 26
346  Forum 2005-2010 (read only) / Interfacing / Re: MPL115A1 reading consistantly low on: November 27, 2010, 12:25:21 am
Ok, I've only just started using the Arduino platform, but seriously how many ways are there to hook up an SPI device?

Am I missing something?

MPL115A1 is a very specific part, the example code was to big to post here, the algorithm to extract the corrected pressure reading is also very specific.
Unless you have an MPL115A1 there is no way you would need to wade through the Freescale data sheet.

Here are the pin connections for a Mega, plus the register defs.
This come straight from the example sketch on the SparkFun sit, modified for the Arduino Mega.

MPL115A1 Breakout ------------- Arduino Mega
 -----------------               -------
         SDN ------------------- D49
         CSN ------------------- D53
         SDO ------------------- D50 *
         SDI ------------------- D51 *
         SCK ------------------- D52 *
         GND ------------------- GND
         VDD ------------------- VCC +
         * These pins physically connect to the SPI device so you can't change them
         + 5V board use 5V VDD, 3.3V board use 3.3V VDD
 License: CCAv3.0 Attribution-ShareAlike (
 You're free to use this code for any venture, but I'd love to hear about what you do with it,
 and any awesome changes you make to it. Attribution is greatly appreciated.

// Includes
#include <SPI.h>

// Get your current altimiter setting from from the National
// Weather Service -
// This value is often labeled "Barometer" or "Barometric Pressure" or just "Pressure"
#define NWS_BARO 30.04

// Pin definitions
#define MPL115A1_ENABLE_PIN 49
#define MPL115A1_SELECT_PIN 53

// Masks for MPL115A1 SPI i/o
#define MPL115A1_READ_MASK  0x80
#define MPL115A1_WRITE_MASK 0x7F

// MPL115A1 register address map
#define PRESH   0x00    // 80
#define PRESL   0x02    // 82
#define TEMPH   0x04    // 84
#define TEMPL   0x06    // 86

#define A0MSB   0x08    // 88
#define A0LSB   0x0A    // 8A
#define B1MSB   0x0C    // 8C
#define B1LSB   0x0E    // 8E
#define B2MSB   0x10    // 90
#define B2LSB   0x12    // 92
#define C12MSB  0x14    // 94
#define C12LSB  0x16    // 96
#define C11MSB  0x18    // 98
#define C11LSB  0x1A    // 9A
#define C22MSB  0x1C    // 9C
#define C22LSB  0x1E    // 9E

Here is the temperature calculation

float calculateTemperatureC() {
    unsigned int uiTadc;
    unsigned char uiTH, uiTL;
    unsigned int temperature_counts = 0;
    writeRegister(0x22, 0x00);  // Start temperature conversion
    delay(2);                   // Max wait time is 0.7ms, typ 0.6ms
    // Read pressure
    uiTH = readRegister(TEMPH);
    uiTL = readRegister(TEMPL);
    uiTadc = (unsigned int) uiTH << 8;
    uiTadc += (unsigned int) uiTL & 0x00FF;
    // Temperature is a 10bit value
    uiTadc = uiTadc >> 6;
    // -5.35 counts per °C, 472 counts is 25°C
    return 25 + (uiTadc - 472) / -5.35;

And the pressure calculation, this is the heavy bit!

float calculatePressurekPa() {
    // See Freescale document AN3785 for detailed explanation
    // of this implementation.
    signed char sia0MSB, sia0LSB;
    signed char sib1MSB, sib1LSB;
    signed char sib2MSB, sib2LSB;
    signed char sic12MSB, sic12LSB;
    signed char sic11MSB, sic11LSB;
    signed char sic22MSB, sic22LSB;
    signed int sia0, sib1, sib2, sic12, sic11, sic22, siPcomp;
    float decPcomp;
    signed long lt1, lt2, lt3, si_c11x1, si_a11, si_c12x2;
    signed long si_a1, si_c22x2, si_a2, si_a1x1, si_y1, si_a2x2;
    unsigned int uiPadc, uiTadc;
    unsigned char uiPH, uiPL, uiTH, uiTL;
    writeRegister(0x24, 0x00);      // Start Both Conversions
    //writeRegister(0x20, 0x00);    // Start Pressure Conversion
    //writeRegister(0x22, 0x00);    // Start temperature conversion
    delay(2);                       // Max wait time is 1ms, typ 0.8ms
    // Read pressure
    uiPH = readRegister(PRESH);
    uiPL = readRegister(PRESL);
    uiTH = readRegister(TEMPH);
    uiTL = readRegister(TEMPL);
    uiPadc = (unsigned int) uiPH << 8;
    uiPadc += (unsigned int) uiPL & 0x00FF;
    uiTadc = (unsigned int) uiTH << 8;
    uiTadc += (unsigned int) uiTL & 0x00FF;
    // Placing Coefficients into 16-bit Variables
    // a0
    sia0MSB = readRegister(A0MSB);
    sia0LSB = readRegister(A0LSB);
    sia0 = (signed int) sia0MSB << 8;
    sia0 += (signed int) sia0LSB & 0x00FF;
    // b1
    sib1MSB = readRegister(B1MSB);
    sib1LSB = readRegister(B1LSB);
    sib1 = (signed int) sib1MSB << 8;
    sib1 += (signed int) sib1LSB & 0x00FF;
    // b2
    sib2MSB = readRegister(B2MSB);
    sib2LSB = readRegister(B2LSB);
    sib2 = (signed int) sib2MSB << 8;
    sib2 += (signed int) sib2LSB & 0x00FF;
    // c12
    sic12MSB = readRegister(C12MSB);
    sic12LSB = readRegister(C12LSB);
    sic12 = (signed int) sic12MSB << 8;
    sic12 += (signed int) sic12LSB & 0x00FF;
    // c11
    sic11MSB = readRegister(C11MSB);
    sic11LSB = readRegister(C11LSB);
    sic11 = (signed int) sic11MSB << 8;
    sic11 += (signed int) sic11LSB & 0x00FF;
    // c22
    sic22MSB = readRegister(C22MSB);
    sic22LSB = readRegister(C22LSB);
    sic22 = (signed int) sic22MSB << 8;
    sic22 += (signed int) sic22LSB & 0x00FF;
    // Coefficient 9 equation compensation
    uiPadc = uiPadc >> 6;
    uiTadc = uiTadc >> 6;
    // Step 1 c11x1 = c11 * Padc
    lt1 = (signed long) sic11;
    lt2 = (signed long) uiPadc;
    lt3 = lt1*lt2;
    si_c11x1 = (signed long) lt3;
    // Step 2 a11 = b1 + c11x1
    lt1 = ((signed long)sib1)<<14;
    lt2 = (signed long) si_c11x1;
    lt3 = lt1 + lt2;
    si_a11 = (signed long)(lt3>>14);
    // Step 3 c12x2 = c12 * Tadc
    lt1 = (signed long) sic12;
    lt2 = (signed long) uiTadc;
    lt3 = lt1*lt2;
    si_c12x2 = (signed long)lt3;
    // Step 4 a1 = a11 + c12x2
    lt1 = ((signed long)si_a11<<11);
    lt2 = (signed long)si_c12x2;
    lt3 = lt1 + lt2;
    si_a1 = (signed long) lt3>>11;
    // Step 5 c22x2 = c22*Tadc
    lt1 = (signed long)sic22;
    lt2 = (signed long)uiTadc;
    lt3 = lt1 * lt2;
    si_c22x2 = (signed long)(lt3);
    // Step 6 a2 = b2 + c22x2
    lt1 = ((signed long)sib2<<15);
    lt2 = ((signed long)si_c22x2>1);
    lt3 = lt1+lt2;
    si_a2 = ((signed long)lt3>>16);
    // Step 7 a1x1 = a1 * Padc
    lt1 = (signed long)si_a1;
    lt2 = (signed long)uiPadc;
    lt3 = lt1*lt2;
    si_a1x1 = (signed long)(lt3);
    // Step 8 y1 = a0 + a1x1
    lt1 = ((signed long)sia0<<10);
    lt2 = (signed long)si_a1x1;
    lt3 = lt1+lt2;
    si_y1 = ((signed long)lt3>>10);
    // Step 9 a2x2 = a2 * Tadc
    lt1 = (signed long)si_a2;
    lt2 = (signed long)uiTadc;
    lt3 = lt1*lt2;
    si_a2x2 = (signed long)(lt3);
    // Step 10 pComp = y1 + a2x2
    lt1 = ((signed long)si_y1<<10);
    lt2 = (signed long)si_a2x2;
    lt3 = lt1+lt2;
    // Fixed point result with rounding
    //siPcomp = ((signed int)lt3>>13);
    siPcomp = lt3/8192;
    // decPcomp is defined as a floating point number
    // Conversion to decimal value from 1023 ADC count value
    // ADC counts are 0 to 1023, pressure is 50 to 115kPa respectively
    decPcomp = ((65.0/1023.0)*siPcomp)+50;
    return decPcomp;

I was NOT sniping, I was objecting to the tone.
This is not a syntax or basic electronics question, it IS very specific to this chip.
I was previously not aware there was a "drill" here.
I apologise for any offence
347  Forum 2005-2010 (read only) / Interfacing / Re: MPL115A1 reading consistantly low on: November 26, 2010, 08:14:41 pm
Here is the link to the Sparkfun page.

And the revalent Freescale doc

Here is a link to the example code, it seems there is a limit to mow big a sketch we can post

I'm using the SPI version of this device on a Mega.

So again, has anyone else tried using this sensor on a Sparkfun breakout board.

And PaulS, please, if you don't know what I'm talking about, don't reply.
It was a fairly specific question about a specific sensor.
Anyone who has used it would recognise the the part number, even if you don't.
As to my 16 posts, the replies, besides yours have been really helpful.
Although I will give you credit for questioning why I was trying to use software serial on a Mega, my latest creation is using all 4 UARTS and they work very well indeed.
348  Forum 2005-2010 (read only) / Interfacing / MPL115A1 reading consistantly low on: November 26, 2010, 10:20:55 am
One of the sensors I'm using in my tricorder/navigator/environmental monitor/dog tracker thingy is a MPL115A1 Sparkfun break out.

I'm using the example code, I've checked out the Freescale data sheet and I'm pretty sure the example code implements the hideously complicated calculation to read the temperature and barometric pressure.

But it is reading at least 10C low on temperature and about 100 KPa low on the pressure sensor.
Has anyone else used this sensor?

One thing I can think of is round off error, converting between fixed point math and floating point might explain this.
What do you guys think?
349  Forum 2005-2010 (read only) / Interfacing / Re: Hyundai HG12602NG LCD display - HELP!!!! on: January 15, 2011, 06:07:00 pm
if its a mystery module you may just have to take a chance.

Yeah, I've been thinking that!
From looking at the board I've been able to identify the power anf ground pins.
So far it does look like the HG12605NG data sheet is close, if not the same.
350  Forum 2005-2010 (read only) / Interfacing / Hyundai HG12602NG LCD display - HELP!!!! on: January 13, 2011, 09:31:47 pm
I was buying components the other day and right next to the cash register there were a stack of these great looking LCD modules and they were only AUS$10!.
As I was on one of my spending spree's I grabbed a couple.
It's 128x64, blue on white, 95mmx70mm, and I can't find a data sheet for it!
Closest I got was HG12605NG, it kinda looks the same, but I don't want to damage the module.
As far as I can tell the controller is a S1D13700.
Is this controller compatible with the KS0107B/KS0108B library?
I really need to get this barn data logger and alarm system running, like a week ago.
351  Forum 2005-2010 (read only) / Interfacing / Re: How to use the whole 8 bits of a port? on: December 09, 2010, 05:02:52 pm
Thanks Lefty!
The Arduino documentation needs a little beefing up!
I thought I'd seen some reference to what I was trying to do!
I keep looking at the 1280 data sheet and thinking, "How do I do that in a high level language?"

I guess I've spent too much time coding in mnemonics!  smiley

In case you're wondering I have a few "rails" of 32K static CMOS RAM, like a few meg worth and a whole bunch of 6545 and 6845 CRTC display chips.
I just got a TellyMate shield and thought I'd have a crack at designing a graphics shield, say 280x191x8 colours, Apple II hi-res or maybe even 320x200x256 colours CGA resolution.

Castle Arduinostien!

(insert evil laugh here!) smiley-wink

Just for the record, is there any way to have inline machine code or assembler in a sketch?
352  Forum 2005-2010 (read only) / Interfacing / How to use the whole 8 bits of a port? on: December 09, 2010, 10:54:17 am
I've been pouring over the Arduino documentation trying to figure out how to use a whole port on my Mega.
The 2 examples I have in mind are -

- writing to 2 8 bit D to A converters that drive my laser X/Y scanner or CRO for debugging, I'll need to use a couple of other pins for latching the data and controlling the "Z" axis.

- using 2 ports to supply a 16 bit address to static CMOS RAM, then another 8 bits to read/write data, obviously the R/W and CS will have to come from a third port.

Can you actually do this in the Arduino environment or do I need  to go to assembler?

I was looking at the Atmel site just then and was left wondering which version of AVRStudio I need to download.
353  Forum 2005-2010 (read only) / Interfacing / Re: Bit Banging with a pair of photoresistors (LDR's) on: December 09, 2010, 04:51:21 pm
No problem!
The circuit for combining clock and data is pretty simple, just a few nand gates and a shift register from memory, the receiver is as easy with only a 74LS121 mono-stable and a few nand gates, 74LS00's and a shift register.

It's less involved than building a UART from scratch, which isn't that had.
If you embed the clock with the data, you don't have to worry about the 1 1/2 stop bits of asynchronous serial.
354  Forum 2005-2010 (read only) / Interfacing / Re: Bit Banging with a pair of photoresistors (LDR's) on: December 09, 2010, 11:13:20 am
I would suggest you investigate Bi-phase data modulation/demodulation.
In short it's away to combine both data and clock into a single signal.
It's the way pretty much every computer used to read and write data to cassette tape.
The other conspicuous example is ADB or Apple Desktop Bus on Macintosh machines with ADB.
I've got a few circuits in some old issues of Byte magazine around here somewhere I could dig up.
On Mac's with ADB they used T2 on the 6522 VIA chip to generate the timing.

Here is the Rockwell example from way back when

Also the other example is the way Apple II's implemented "soft sectoring" on 5 1/4" floppy disks.

If there is programming getting done @25 or 30 fps on a TV this would be the most obvious way to do it.
355  Forum 2005-2010 (read only) / Interfacing / Re: detecting obstructions on the sea on: December 08, 2010, 09:10:03 pm
356  Forum 2005-2010 (read only) / Interfacing / Re: detecting obstructions on the sea on: December 08, 2010, 08:24:23 pm
The 6502 was the first REAL RISC!
Only 157 instructions!
Z80 twits used to brag about how many registers they had, oh, and that damn block copy!
6502 had so many different ways to do indirect and indexed addressing, it made it hard to port code to anything other than 6809 or 68000!

What's this programming in assembler?! I used to hand assemble!
Still do! (I like to suffer)
My first contact with the Atmel processors was hand assembled code on the AT90S8535.
357  Forum 2005-2010 (read only) / Interfacing / Re: detecting obstructions on the sea on: December 08, 2010, 11:04:35 am
I bought a Micromega uM-FPU-V3, not only does it handle NMEA sentance parsing, but the Micromega site has a whole bunch of application notes about stuff like bearing and distance between 2 waypoints.
The chip was cheap and it's really fun to play with, not only that but there is a whole uM-FPU library for the Arduino.
You should grab one from Sparkfun or where ever and have a play with it.
358  Forum 2005-2010 (read only) / Interfacing / Re: detecting obstructions on the sea on: December 08, 2010, 10:05:47 am

I have to stop getting sidetracked as well!
Said $20 rover now has GPS and an HMC6352 digital compass.
When I do have spare time I've been working on getting the thing to travel between 2 GPS way points.
Ultimately I want all this in my UAV, I figure a slow moving ground vehicle is a much more "forgiving" environment than a 'plane in the air.

The other, but related project is a GPS/navigator/"tricorder" thing.

One thing I should warn you, if you are going to do much work with ultrasonics, you ARE going to need a decent CRO.
Working with op-amps without a CRO is just plain frustrating, especially if you are using a single rail supply for op-amps like the TL081.
Not only that but just "keying" your ultrasonic transmitter and watching the return echoes on the CRO will give you all kinds of ideas on how to process the data.
The amount of detail you can see on the CRO screen will amaze you.
Just get you Arduino to send regular pings and watch the returns.

Also don't overlook doing stuff in analog with op-amps, THEN digitising the signals.
For ultrasonic receivers don't mess about with instrumentation amps like 741's, LM3900's and the like, you need to use a JFET op-amp that has a high input impedance and low noise.
I use TL081's or NE5534's, these are single amp/package devices.
The 2 and 4 amp versions, the TL082 and TL084 are ok, but you will get cross talk @40Khz.
That's why I said to use 2 stages of X10 gain, you get WAY less noise than a single stage of x100 gain.
359  Forum 2005-2010 (read only) / Interfacing / Re: detecting obstructions on the sea on: December 08, 2010, 09:13:17 am
I started out using an LM386 @12V, then went to 2 LM380's in bridge configuration.
The receivers have 2 TL081 JFET op-amps, each with a gain of 10.

Originally I was using my SYM-1 (that's a 6502 single board computer with 32K of RAM, running @ 1Mhz) to process the data, using 3 ADC0804's.
That was kinda "iffy", so I gave each A/D converter it's own 2K static CMOS RAM, with a counter stepping @ 10khz, which is the max sampling rate of the ADC0804.
That only gives you a minimum of 1 foot/sample, as sound travels @1ms/foot.
I then went to TL0831 ADC's, those are 8 bit serial converters that let you clock data @600K, I divided the 6502's 1Mhz clock by 2, to give me a 500khz clock, which gives 62.5ksample/sec.
Thats a minimum range of around 5mm! Which was too tall an ask for a 1Mhz processor.
So I started using the same 40khz clock I was using to drive the ultrasonic transducer, which gives you a minimum resolution of 6cm, which was still pushing the envelope for a single 6502.
I started using the SYM simply to control the sonar, then passed the data on to an Apple II, that was kinda slow as well, but a friend gave me my first Linux system, a DX-4/100 and I transferred all my Pascal code over to the Linux box.
That's as far as I got until a couple of months ago when I got my first Mega.
As I said first thing I did was put a Mega on a $20 radio controlled car, with a Pololu H-Bridge module and an XBee module.
I'm using the first 3 analog inputs on the car's Mega for the 3 ultrasonic receivers.

My second Mega is receiving the data and I'm displaying it either on my eee or my desktop machine, just as simple vertical bar graphs.

It's all pretty crude right now, but when work calms down a bit I'll refine the circuit and code.

I'll draw up the circuit if you want and post it.

There is not much to it, just the LM380's driving the transmitter, I got the circuit straight from the National Semiconductor application note.
The receivers are just 2 JFET op amps each with a gain of 10.

Even if you want to use normal ranging you can still use the same setup.

I should mention I really like building big, complex circuits out of 7400 series chips, normal 74LS series can clock at a maximum of 25Mhz, which was pretty darn fast when I only had access to 1Mhz processors.
The craziest/most complex thing I ever built was a "Life" engine, that could do 25 generations/second.

So if this idea for "sonar illumination" sounds complex that's why.
Using a modern microcontroller will make it a lot simpler, even if you need to add external RAM as a buffer.
Besides if bats can do it, so can we!
360  Forum 2005-2010 (read only) / Interfacing / Re: detecting obstructions on the sea on: December 08, 2010, 01:48:06 am
If you use one of the waterproof ultrasonic receiver/transmitter pairs and really drive the transmitter, by that I mean don't mess around with 5V, use an amplifier chip, 2 LM380's in a bridge configuration or an STK module.
Those sealed ultrasonic transmitters will produce a >105dB and take a maximum input voltage of 140V!
That is enough to hurt, so don't put your ears anywhere near it when it's operating, you wont hear it, but believe me you will feel it, like somebody sticking a knitting needle in your ear.
Here in Australia you can buy a kangaroo scaring device that mounts on your front car bumper, I've seen 'roo's react to them at distances of over 100M! Again it's not something you can safely stick your ear in front of, it really hurts!
Same goes for ultrasonic "intruder" detectors, some of those have a VERY high output.

Bat's, rat's dolphin's and whales have been "imaging" like this for ever!
Dolphin's can stun fish with a concentrated pulse of sound.

I've been experimenting with a continuous output ultrasonic system.
Rather than a pulse I've been trying to "illuminate" the area in front of a small rover, then using multiple receivers to "watch" the reflected sound.
With 3 receivers I "fill" in the gaps between them by summing the outputs of the outer receivers with the centre one, sort of like synthetic aperture radar.
I started out just watching the output on my CRO, as soon as I got my Mega and XBee modules I started visualising the A/D converters output as simple vertical bar graphs.
You can drive around quite well without running into stuff.

Another thing I've tried is a few different shaped "reflectors" for the transmitter and receivers.
A simple plate at 45 degrees above a horizontally mounted transmitter widens the field of the beam produced, as well as flattening it out.
Building small horns for the receivers also is something to try.

You can definitely tell the difference between various materials and textures, grass has a different texture to gravel, bark and wood return a different sound texture to concrete, which is different to bricks.

Pages: 1 ... 22 23 [24] 25 26