interfacing an accelerometer with a 08m

elios

Senior Member
Hi all...

I am trying to interface an accelerometer with a 08m mcu then i want to move onto a 28x2. At the moment, i have a 08m doing readadc 1,b1 reading the x axis and then doing a sertxd to the computer.

At the moment i cannot get any data out, or even getting the 08m reading the data being outputted by the accelerometer.

im using this accelerometer:
https://www.sparkfun.com/commerce/product_info.php?products_id=252

datasheet here:
http://www.sparkfun.com/datasheets/Accelerometers/MMA7260Q-Rev1.pdf

cheers for any help
 

Dippy

Moderator
Odd, it looks a nice simple A2D.

Post your exact circuit and your exact code.

Describe the power supply and connections.
We can only assume you have double-checked all your connections.

Have you checked your ADCing with a simple pot?

PS. I take it you haven't got the top view and bottom view muddled for the pinout?
 
Last edited:

elios

Senior Member
argh

ARGH im a douche... nobody panic... i read the datasheet wrong and put the chip into sleep mode... argh.....

if you lot still want the schematic im using... then ask and ill draw it up in eagle then post it...

Cheers anyway guys
 

Dippy

Moderator
Excellent.

Tip: Read Data Sheet ten times before posting - saves a red face huh :)

Schematic for us lot?
I can't speak for the rest of 'us lot' but it doesn't look too tricky - apart from the sleep mode apparently ;)
 

hippy

Ex-Staff (retired)
Welcome to the PICAXE forum.

Glad you solved your problem. It's often the way that as soon as you post about it the mistake becomes crystal clear :)
 

elios

Senior Member
well...

well.... im making an autonomous helicopter for the BrightSparks Hitech competition this year....

question: im having trouble with my 28x2 it doesnt want to sertxd to the computer... any ideas?

im new to the x2 series so im stumped in general with trying to get all the outputs etc, as i dont understand the ports

i had the readadc correct with the 08m, but now i cant get the 28x2 to readadc 3 inputs and sertxd back to the comp. heres the code im using:

loopa:
readadc 1, b0
readadc 2, b1
readadc 4, b2
sertxd ("testing accelerometer: ",9,#b1,44,9,#b2,44,9,#b3,13,10)
goto loopa

cheers
 

elios

Senior Member
Welcome to the PICAXE forum.

Glad you solved your problem. It's often the way that as soon as you post about it the mistake becomes crystal clear :)
thanks hippy, didnt see your post here. Its great you guys have a forum like this here. Its a great help
 

eclectic

Moderator
@elios
A few points.

Manual 1, p. 30
The 28X2 has ADC inputs 0 – 3

Your code
Code:
loopa:
readadc 1, b0
readadc 2, b1
readadc 4, b2
sertxd ("testing accelerometer: ",9,#b1,44,9,#b2,44,9,#b3,13,10)
goto loopa
won't show b0.
So, change to something like this:
Code:
#picaxe 28x2

loopa:
readadc 1, b0
readadc 2, b1
readadc 3, b2
sertxd ("testing accelerometer: ",9,#b0,44,9,#b1,44,9,#b2,13,10)
goto loopa
Then, use
PE > PICAXE > Wizards > X2 conversion, to produce

Code:
#picaxe 28x2

' Converted by X2 Conversion Wizard Version 1.0.2

let dirsB = %11111111
let adcsetup = 4  '  change to %00001110 on 3V parts

loopa:
readadc 1, b0
readadc 2, b1
readadc 3, b2

sertxd ("testing accelerometer: ",9,#b0,44,9,#b1,44,9,#b2,13,10)

goto loopa
A long post, but, next time,
it'll be much faster. :)

e
 

elios

Senior Member
okay, thanks eclectic.

Just at the moment the x2 wont sertxd, and wont run through the program. And what version of proggy editor are you using cos i dont got that wizard, and this is the latest version?

also, it gives me syntax error after adcsetup but before the =.

cheers
 

hippy

Ex-Staff (retired)
question: im having trouble with my 28x2 it doesnt want to sertxd to the computer... any ideas?
eclectic's post may help but if it really is a case that you are not seeing any SERTXD data at all, try running a program to test and debug the particular issue you are having ...

#Picaxe 28X2
#Terminal 9600
#No_Table
Do
SerTxd( "I'm alive !", CR, LF )
Pause 1000
Loop

That should display on the Terminal in Programming Editor. Let us know if not.

And what version of proggy editor are you using cos i dont got that wizard, and this is the latest version?
The latest version is 5.2.6 ( Help -> About ) and the Wizard should be there; PICAXE -> Wizard -> X2 Conversion.
 
Last edited:

elios

Senior Member
Im getting syntax error with your program hippy, im going to reinstall my editor.


eclectic's post may help but if it really is a case that you are not seeing any SERTXD data at all, try running a program to test and debug the particular issue you are having ...

#Picaxe 28X2
#Terminal 9600
#No_Table
Do
SerTxd( "I'm alive !", CR, LF )
Pause 1000
Loop

That should display on the Terminal in Programming Editor. Let us know if not.
 

elios

Senior Member
yip. i got the terminal window going correctly. But alas, parents are making me go to bed.

so i'll post tomorrow. And the update also fixed the readadc probs with the 08m.

Cheers,
 

elios

Senior Member
thanks, i tested it this morning. it worked fine. i also had all readings from the accelerometer.

then

it stopped. it just stopped. i get the readadc from adc3, but thats it. im still playing around to figure out what has happened
 

BeanieBots

Moderator
Might be a good idea to post your circuit and describe in detail your power supply.
Could be something simple like a floating reset, enable or similar.
 

elios

Senior Member
okay here is my circuit i drew up for the PCB development.

Ignore the voltage regulator circuit and the serial comms header.

from side 1, of the accelerometer header, the pins are:
1) Vcc
2) GND
3) X
4) Y
5) Z
6) GS1
7) GS2
8) SLP

not shown in this circuit is that GS1 and GS2 is grounded. The accelerometer is actually connected to a 3v lithium battery. SLP is high from the 3v. Also, eagle doesnt have a 28pin socket that i could find, so i have just used to 14 sockets.

So, my PSU. I am using three AA batteries to power the picaxe 28x2 at the moment, and i have a 3v lithium button cell powering the accelerometer.

Im checking the circuit again as i type.

Any help given is great, thanks.
 

Attachments

elios

Senior Member
i think my 28X2 is stuffed.... i have it working with datalink too, in the 08m. code:

loopa:
b0 = b0+1
readadc 1, b1
readadc 2, b2
readadc 4, b3
sertxd (#b0,44,9,#b1,44,9,#b2,44,9,#b3,13,10)
goto loopa

thanks,
 

hippy

Ex-Staff (retired)
i think my 28X2 is stuffed.... i have it working with datalink too, in the 08m. code:
Sorry, I don't follow - You have it working but it is "stuffed" ?

Run a simple program and see what that does ...

#Picaxe 28X2
#Terminal 9600
Do
SerTxd( "I'm alive !", CR,LF )
Loop

Make sure the batteries are new or it's runing from a regulated 5V supply.
 

elios

Senior Member
sorry about my english.... ill rephrase what i said.

i cant get the x2 working. but i can get the 08m working with the accelerometer. i can also get datalink working with the 08m too.
 

elios

Senior Member
that sertxd code works.

#Picaxe 28X2
#Terminal 9600
Do
SerTxd( "I'm alive !", CR,LF )
Loop

but im not sure with this code:

#picaxe 28x2

' Converted by X2 Conversion Wizard Version 1.0.2

let dirsB = %11111111
let adcsetup = 4 ' change to %00001110 on 3V parts

loopa:
readadc 1, b0
readadc 2, b1
readadc 3, b2

sertxd ("testing accelerometer: ",9,"x",#b0,44,9,"y",#b1,44,9,"z",#b2,13,10)

goto loopa

thats in the x2. in the 08m currently i have:

loopa:
b0 = b0+1
readadc 1, b1
readadc 2, b2
readadc 4, b3
sertxd (#b0,44,9,#b1,44,9,#b2,44,9,#b3,13,10)
goto loopa

and that seems to work perfectly fine
 
Last edited:

Dippy

Moderator
Eh?
Surely if that code works, then that means that the so-called 'stuffed' 28X2 is actually working ?

Are you saying that your code example which reads the ADC is not working?

What do you mean exactly by "not sure"?
That 28X2 code; is that the code that was working but suddenly stopped?
Did it stop running, or did it stop picking up ADC values and just sent rubbish to PC ?


If it was working and then just suddenly stopped, it could be:
1. A wire has fallen out or a connection failed.
2. Batteries failed or too feeble.
3. Something shorted (common with hairy/messy breadboarding).
4. Your code.

Have you got all this on some hairy old breadboard?
 

elios

Senior Member
well i got the code wokring again this morning... my 28x2 seems rather tempermental...

but now im stuck with serial communication between the 28x2 and the 08m.

Is there any coding trick i should know with the 28X2? could someone write me some code for serouting b1 out of pin B.2 and serin 1 at the 08m. My code seems incorrect, and im not getting the 08m reading the 28X2.

thanks

[edit] dont worry... i changed the internal clock speed of the X2 and now i have serial comms.

cheers,
 
Last edited:
Top