Am I using baby orangutan's lib in a right way or not?

Hi
I am trying to write a code to for serial communication between a module and my baby orangutan. For now I am trying to test my code first with HyperTerminal to make sure it is working. I am using baby orangutan 328p lib for serial communication. All what I need for now is to send bunch of char to baby orangutan. If the right char received in a particular position in an array, LED will be ON otherwise it will be OFF.

#include <avr/io.h>
#include <util/delay.h>
#include <pololu/orangutan.h>

int main ()
{
	char receive_buffer [2] = {'R','D'};
	DDRC = 0xFF;
	serial_set_baud_rate(115200);

	while (1)
	{	
		serial_receive(receive_buffer ,sizeof(receive_buffer));

		if (receive_buffer [2] == 'A');
			PORTC &= (1 << PC0);
		_delay_ms(5000);		 
	}
}

Anyone can tell me what is wrong with my code? I will be really grateful.

No reply :open_mouth:
really guys I need to know or at least I need a hint. I already check another code just to send a char from the baby orangutan to the HyberTerminal and it work. but the reciving part is not working yer…

please Help.

Hello,

You are not doing things the right way at all. For one thing, your buffer only has two elements, so index 2 (the third element) is out of bounds. Do you not get some kind of warning when you compile it? Also, you said “a bunch of char”, but your program will only be able to receive a maximum of two characters. Another potential issue is that you have not said how you are connecting your computer to your baby orangutan - but that is essential information if you want help debugging the connection.

-Paul

Hi paul
Thank you for replying
seems I post the wrong code I already change that to 1. I am examine the second char. I sent only two just to smplify my code. I am connecting my computer using the USB from this link smileymicros.com/download/VS … 0Guide.pdf. I am using the wiring of 5 V. As I said I already tried to send char to the USB and I got the char on the screen but I could not recive anything.

Okay, a good first thing to try would be to remove your baby orangutan, connect RX to TX on the smileymicro adapter, and see whether characters you send get echoed back to you. Can you try sending a few bytes using our serial transmitter application and tell me exactly what happens?

By the way, _delay_ms has a maximum delay of 13 ms. You might have better luck with the Pololu delay_ms function.

-Paul

Hi paul
I did the loop test for the USB and I got the char on the screen using the hyperterminal before connecting the baby orangutan. Thank you for the application I will use it and I will tell U what will happen.

[quote]By the way, _delay_ms has a maximum delay of 13 ms. You might have better luck with the Pololu delay_ms function.

[/quote]
Really _delay_ms() has a max of 13 ms :open_mouth: this is a new information for me.

Hi paul

I tried serial transmitter application and that what I got.

and this is the code I am using.

#include <avr/io.h>
#include <pololu/orangutan.h>

void wait_for_sending_to_finish() 
{ 
    while(!serial_send_buffer_empty()); 
} 

int main ()
{
	serial_set_baud_rate(9600);
	char receive_buffer[2] = {'E' , 'S'};
	
	while (1)
	{	
		wait_for_sending_to_finish ();
		serial_receive(receive_buffer , 2 );

		if (receive_buffer [0] == 'A')
		{
				PORTC |= (1 << PC0);
		}	
		serial_send(receive_buffer, 2 );		
	} 
	return 0;
}

I assume from the image I am sending and receiving but still when I want to examine a particular char in the array LED didn’t blink.

One more silly question from the baby orangutan specification I saw each single i/o can provide max 40 mA but as I knew microcontroller can provide 100-120 mA for each port. so in baby orangutan can the port’s current consumption more than 100 -120 mA

Hello.

You never set PC0 as an output, and I’m worried you don’t have the LED connected properly (e.g. proper polarity and use of appropriate current-limiting resistor). Have you actually verified that you can turn your LED on PC0 on by, for example, writing a program that does nothing other than turn it on? Why don’t you simplify things by using the Pololu AVR library’s red_led() function to turn on the Baby Orangutan’s red user LED?

To answer your last question, the Baby Orangutan gives you direct access to the ATmega328P microcontroller, so limitations of the AVR are also limitations of the Baby Orangutan. The Baby Orangutan has limits on the current you can source/sink from a single I/O line, and it has additional limits on the total current you can source/sink from a port. See the Electrical Characteristics section of the ATmega328P datasheet for more information.

- Ben