Shop OBEX P1 Docs P2 Docs Learn Events
Problems with programming accelerometer and gyroscope with BS2px — Parallax Forums

Problems with programming accelerometer and gyroscope with BS2px

trannhtrannh Posts: 24
edited 2010-04-26 14:10 in BASIC Stamp
Can any body help me with programming the BS2px stamp? I've been look at What's a Microcontroller and all the datasheets for the bs2px, as well as datasheets and test codes for the accelerometer and gyroscope I am using and I can't figure it out. I'm using the LISY200 Gyroscope and the MMA7455 3-axis accelerometer. I want to be able to get graphs for about 5 seconds of testing. Can anybody help me with this problem? I don't know where to start here.

Post Edited (trannh) : 4/21/2010 8:17:31 PM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2010-04-21 17:06
    Make sure you've adjusted the Baud constants and other timing constants in the demo programs. They're usually for the BS2 and need to be changed for other Stamp models like the BS2px. The supplementary datasheet for the BS2px has the proper constants. The help files in the Stamp Editor also have them.

    Use the Attachment Manager (from the Post Reply button dialog) to attach a copy of your program to a message. If you don't have a program yet, you'll have to start with the demo programs for the gyroscope and accelerometer and write your own program first.

    It's also important to add a subject to your thread. Use the pencil icon in the upper righthand corner of your first message.
  • trannhtrannh Posts: 24
    edited 2010-04-21 19:43
    So if I attach my program, will you will help me find out the problems?
  • Mike GreenMike Green Posts: 23,101
    edited 2010-04-21 20:12
    That's not how things work here. Most of the people who provide expertise here do it strictly on a volunteer basis and they have other demands on their time like a paying job and a family. You need to make their efforts easier by providing what information is asked for, by being polite, respectful, and thankful, and by thinking about what advice is offered and trying what's suggested. In my case, I've got other things to do in the next few days. If you do what I asked, I will probably have time to take a quick look at your program and make some suggestions. Others may have more time to look in more detail than I can now.
  • trannhtrannh Posts: 24
    edited 2010-04-22 00:58
    I appreciate all the advice people have given me on these forums and I am thankful that they take time out of their day to help me. As for your request, I have attached the program that I have been working. It would be wonderful if you could take a look at it and give me any helpful hints.


    The problems that I have with the program is that the accelerometer I am using, the MMA7455 3-axis accelerometer module, does not have a pin for the x axis data, the y-axis data, and the z-axis data. I'm not sure how to get data from those three axes since the sensor only has one output data pin. Could somebody help me solve this problem? Also, how to do open .spin files? Thank you so much

    Post Edited (trannh) : 4/22/2010 1:03:25 AM GMT
  • SRLMSRLM Posts: 5,045
    edited 2010-04-22 02:27
    Mike Green said...
    That's not how things work here. Most of the people who provide expertise here do it strictly on a volunteer basis and they have other demands on their time like a paying job and a family.

    And school!

    @trannh

    Spin files are for the Propeller. They won't work on the BS2, and you should probably ignore them. If you really want to open them, then you can just use a text editor.

    Look at the sample code provided on each of the pages for the sensors that you're using. Assuming that you're using the modules from Parallax, they provide plenty of bs2 code to get started.

    I would put each of the sensor interface blocks of code into their own subroutine, and call that from your record method. Also, I'd get rid of the whole menu option thing. All that you need is to wait for a keystroke to get started, and then just start streaming the data. When you start programming, start with something simple and slowly add complexity, all the while testing it to make sure that you haven't broken it.

    Finally, never post a program that doesn't compile (ctrl+T). It indicates that you aren't willing to solve even the simple problems.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Powered by enthusiasm
  • FranklinFranklin Posts: 4,747
    edited 2010-04-22 02:28
    On the product page www.parallax.com/Store/Sensors/AccelerationTilt/tabid/172/CategoryID/47/List/0/SortField/0/Level/a/ProductID/585/Default.aspx there is demo code for the bs2. You should download that and look at it for help.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    - Stephen
  • Mike GreenMike Green Posts: 23,101
    edited 2010-04-22 02:46
    Have you looked at the BS2 demo code? There's a link on the product page to both a Propeller demo and a Stamp demo. Propeller code has a .spin extension and you need the Stamp code (.bs2). The links are to .zip files and you have to un-zip them. Both Windows and the MacOS can do that if you open the file. The demo programs have extensive comments and show how to read and write data to the MMA7455L3.

    You asked how the x, y, and z data get out through only a couple of pins. If you read the documentation, you'll see that the data is held in several registers within the MMA7455L3. Your program sends a register address and a byte of data to write to one of the registers or sends a register address, then reads a byte of data to read from one of the registers.

    You should be able to take the demo programs and incorporate part of them into your program to read the x,y, and z values.
  • trannhtrannh Posts: 24
    edited 2010-04-22 15:55
    Thank you all for your help. The demo codes has helped a lot. I have another problem that I hope you can help me with. I'm having a tough time recording those acceleration values and gyroscope values and displaying them onto a graph. My idea is to create a list and copying it to excel where I can then create a graph? Does anyone have an idea on how I could achieve that?
  • SRLMSRLM Posts: 5,045
    edited 2010-04-22 18:46
    Send them to a terminal (using the DEBUG command, and the Parallax Serial Terminal would work fine on the computer). If you send it in a comma separated format then you can copy and paste the data from the terminal into a blank text file, and from there import the text file into excel. You may also want to look at Stampplot software, but I don't have any experience with that. As always, it's well documented on the Parallax website.

    Data sample format. I have index numbers in the first slot, then three acceleration channels, then two gyro channels.
    9,1023,595,696,22,999
    10,1029,569,640,54,957
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Powered by enthusiasm
  • trannhtrannh Posts: 24
    edited 2010-04-22 20:34
    I'm not exactly sure what those numbers mean. Could I do something like this:

    FOR eeIndex = Records TO RecordsEnd STEP 1
    READ eeIndex, XAccel
    XAccel = XAccel - 100
    READ eeIndex + 1, YAccel
    YAccel = YAccel - 100
    READ eeIndex + 2, ZAccel
    ZAccel= ZAccel - 100
    READ eeIndex +3, value
    value= value -100

    DEBUG DEC eeIndex, CRSRX, 7, SDEC XAccel, CRSRX, 14, SDEC YAccel, CRSRX, 21, SDEC ZAccel, CRSRX, 28, DEC5 value, CR

    Also, when I try to run my program, this message pops up: Data occupies same location as program. What does this mean and how can I fix it?

    Post Edited (trannh) : 4/23/2010 12:02:52 AM GMT
  • SRLMSRLM Posts: 5,045
    edited 2010-04-23 15:38
    You don't want to store your measurements in EEPROM (READ, WRITE). EEPROM is used to store your program and long term data. You should probably five WORD sized variables to hold your five values. Also, I'm not sure why you are subtracting 100 from the numbers that you're sending out. If you're going to adjust the offset, then you want to do it by n/2, where n is the number of bits of the ADC that the gyro/accelerometer modules use.

    The message means that you're trying to store data where there the program data already. Look up the READ and WRITE commands in the BS2 manual if you want to know more, but you don't really need it for this project.

    The data that I showed in my previous post was entirely fictitious. It was merely meant to show how you could format it.

    Finally, a little forum support hint. If you're going to post code in the body of your post then a) make sure it isn't a whole lot of code and b) use the [noparse][[/noparse] code ] tags (without the spaces) or the code block option to put the code in a special box that keeps the formating. The sample data that I posted above is an example.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Powered by enthusiasm
  • trannhtrannh Posts: 24
    edited 2010-04-23 16:56
    So how do you suggest i gather all 5 pieces of information so that a list can be created. I would like the list to display the values like this:
    index x-axis y-axis z-axis gyro




  • trannhtrannh Posts: 24
    edited 2010-04-26 14:10
    Here is the program that I have. I think that it collects the data write, but I can't get it to display the values correctly. Could someone look over it and help me figure out what's wrong. I would really appreciate it.
Sign In or Register to comment.