Society of Robots - Robot Forum

Software => Software => Topic started by: Stephanie on July 22, 2009, 10:36:58 AM

Title: [Solved] Code problem, UART okay (edit: dirt problem)
Post by: Stephanie on July 22, 2009, 10:36:58 AM
Okay. So I just got my Axon microcontroller and a Sharp IR rangefinder GP2D12 and I want to test them out.

I followed the Getting Started tutorial and it's all okay.

Then I wanted to code a simple program to read data from the sensor on port 9 and output it to UART1 (USB).

I downloaded the Axon source code and edited control.c to the following:

Code: [Select]
void control(void) {
rprintfInit(uart1SendByte);
int reading;
while(1) {
delay_ms(50);
reading = sharp_IR_interpret_GP2D12(a2dConvert8bit(9));
rprintf("Reading: %d", reading);
}
}
...but it doesn't work. What did I do wrong? Do I have to include header files or something? My whole control.c is described above.

Solved. Read my last post. Don't laugh.
Title: Re: [Axon] Noob Programming Question
Post by: Webbot on July 22, 2009, 12:37:34 PM
Does it just give a constant value. If so - then it looks like you've commented out the line that reads the sensor by using //
Title: Re: [Axon] Noob Programming Question
Post by: Stephanie on July 22, 2009, 01:07:27 PM
Ah, sorry, it's not that. I commented it to test "Hello World" and forgot to remove when posting. Still didn't see anything.

It prints absolutely nothing. I think I'm editing the wrong file or forgetting something.
Title: Re: [Axon] Noob Programming Question
Post by: Canabots on July 22, 2009, 03:04:18 PM
Try changing the int to unsigned int.

Also, you don't have to initialize the UART 1 rprintf. I've done it many times without having to use that.

And just a quick note, you don't neccessarily have to use the sharp_ir_interpret_GP2D12. Just simply using reading=a2dConvert8bit(9); works completely fine.

Hope this helps. :)
Title: Re: [Axon] Noob Programming Question
Post by: Stephanie on July 22, 2009, 03:26:30 PM
Hmm. I did everything, but it still doesn't print anything! I think I'm using wrong files.

Could someone make a ZIP/RAR with the files I need to use (already with the code to print the Sharp reading from port 9) or tell me what to write on control.c to get the desired result? Thanks in advance!
Title: Re: [Axon] Noob Programming Question
Post by: Canabots on July 22, 2009, 03:53:57 PM
Try this (code goes in control.c):

Code: [Select]
unsigned int GP2D12=128;



void GP2D12_refresh(void);



void control(void)  //Run Hyperterminal Program

{

while(1)

{
delay_ms(50);

rprintf("Sensor_Value=%d\r\n", GP2D12);
 //Print in Hyperterm.
}

}



void GP2D15_refresh(void) //Sensor Refresh Subroutine

{

GP2D12=a2dConvert8bit(9);

}

The required files are the hardware, SoR_Utils, control, and Axon.

Let me know if this works.
Title: Re: [Axon] Noob Programming Question
Post by: Stephanie on July 22, 2009, 04:02:52 PM
Same thing, Canabots. I think the error isn't in the programming part, I think I'm doing something wrong. What I did was:

1. Download Axon source code.
2. Replace control.c wih your code.
3. Connect UART1 to my PC through USB.
4. Open cmd.
5. cd C:\Documents and Settings\Stephanie\Desktop\Axon
6. FBOOT17.EXE -b115200 -c3 -pAxon.hex -vAxon.hex
7. Transfered successfully to my Axon.
8. Turn Axon off.
9. Turn Axon on and check HyperTerminal (COM3).

But nothing happened, again.

Did I do something wrong?
Title: Re: [Axon] Noob Programming Question
Post by: Canabots on July 22, 2009, 04:23:48 PM
Well, a couple possible issues...

1.
Quote
Make sure there are NO spaces in the file name.

For example, do not do 'C:\Documents and Settings\User\Desktop . . .'

From part 1 installing software on the getting started guide  :P
This may or may not be your problem. Perhaps something to look into though.

2. Have you successfully programmed the Axon before? Has a program worked? Have you managed to get something up in HyperTerm?

3. Is the "Call" button pushed?

4. Is command prompt closed when using hyperterminal? I've had some issues with it not working in the past...
Title: Re: [Axon] Noob Programming Question
Post by: Stephanie on July 22, 2009, 05:13:36 PM
1. Moved it, still not working.
2. I've never done it, actually it's my first attempt. "System Warmed Up... Initialization Complete" appears, but nothing else.
3. Yes.
4. Yes.

It's definitely on my program. I'm doing something wrong, because the pre-compiled .hex files work.

Any more ideas?
Title: Re: [Axon] Code problem, UART okay
Post by: Admin on July 24, 2009, 12:01:09 PM
Program the LED to flash. And then program it to turn on the LED only when you push the button.

If that works, that means your code is fine, but you're messing up the UART.

Then, get a multimeter and put it on the frequency setting. Tell the Axon to repeatedly transmit data to UART1, and see if you get a frequency reading on any of the USB header pins (only one should be doing something).

Let us know what happens, and we can go from there.
Title: Re: [Axon] Code problem, UART okay
Post by: airman00 on July 24, 2009, 05:14:41 PM
I've had a similar problem. The culprit was the push button - it was faulty, and therefore would never actually be "pushed-down".
Try commenting out the pushbutton code at the beginning.
Title: Re: [Axon] Code problem, UART okay
Post by: Stephanie on July 24, 2009, 08:45:05 PM
Solved. It was so simple that I'm embarrassed: my desk is dirty (I eat here sometimes), and something got into the button in such a way that I couldn't activate anything but would feel like I was pushing it.

The dirt was easily removed and, well, now it works like a charm! Thanks (and sorry) for everything!

I'm really happy with the Axon --- it's an amazing product. I'm very impressed with its incredible customer support: look, a dirt-in-the-button problem moved a lot of great people! I would never imagine that my first attempt at robotics would be successful - and it's going great.
Title: Re: [Solved] Code problem, UART okay (edit: dirt problem)
Post by: Admin on July 24, 2009, 09:59:04 PM
If anyone wants a new button to fix a misbehaving one, I'll mail you one for free. But you'll have to solder it :P