How to program 2 Baby-O with 2 bluetooth module with atmel studio

Hello,

I need to program 2 baby-o with 2 bluetoth module. 1 Baby o will send an value and other one will do something with that data. I saw a video link below, and i am interesting after 5:00 min. with Atmel.

I know how to configure the bluetooth modules, I am not asking AT commands. I just want to know how to communicate on atmel (With C Codes).

On arduino just checking :

void setup {} (
Serial.Begin(...//baud rate) .);
)


void loop () {
if (serial.available {} >0) {

//do something....

}
}

How can i configure that codes on Atmel with C code on baby o.

Thank you.

(This is smular my project but this one with arduino uno)

Thanks.

Hello.

There is an OrangutanSerial library, which is part of our AVR C/C++ Library, that can help get you started with accessing the USART on the Baby Orangutan. For more information on the library’s serial port communication functions and how to install the library, see the Pololu AVR C/C++ Library User’s Guide.

Alternatively, since it sounds like you are more familiar with the Arduino environment, you can configure the Arduino IDE to allow you to program the Baby Orangutan from it. You can find the instructions in the Programming Orangutans and the 3pi Robot form the Arduino Environment guide.

- Amanda

Hello Amanda,

First, using the Arduino enviroment is not an option for me. I have already a project with baby-o and using Atmel AVR C/C++ library. So, I just want to add bluetooth to my project.

Anyway, is that so complicate to do this job witv AVR libraries ? Because the example on Pololu AVR C/C++ Library User’s Guide is not working with baby-o cause of green led.
I think i can configure that part, but i dont understand why it is so complicate to do this job with AVR?

I can synchronous the bluetooth modules on Arduino it is ok. And With using PD1/PD0 (TXD/RXD) on baby o, how can i send a simple data to the other one. Or recieve a data from cell phone or PC.

Thank you.

What exactly are you having trouble understanding?

Please note the comments in the serial1 example code for the OrangutanSerial library explicitly states that parts of the code will not work for the Baby Orangutan here. Did you try modifying the example code, particularly the process_received_byte(char byte) function, to work for your setup? If you did, can you please post your entire code here?

Instead of trying to understand and modify the example code, it might be easier for you to just create a simple program from scratch using the OrangutanSerial functions. You can see the documentation for those functions in the “Orangutan Serial Port Communication” section of the Pololu AVR Library Command Reference.

- Amanda

Hello Amanda,

NOTE : BOTH HC05 bluetoth module connecting each other when turn on. I configure them by using arduino serial monitor. ant they are sencronised now on 38400 baud rate.

You can see my schematic attached files.

I have 2 baby orangutan, one of will only send Data (0 or 1 is enaugh for me)
and the other one will only recive data, as you can see the picture.
When i push the button, i want to power on the led which connected to Slave Baby o.
So i need to write 2 different code for 2 baby-o.

Can you help me about this ?
Here is my master code,

//MASTER
#define F_CPU 20000000UL	
#include <pololu/orangutan.h>

//#define	LED PORTB1    //THİS WİLL BE ON SLAVE
#define BUTTON PORTB0

char send_buffer[32];
char receive_buffer[32];



int main( void )
{
	serial_set_baud_rate(34800);
	
	while ( 1 )
	{
		
		if(PINB & (1<<BUTTON))
			{
				
				serial_send(send_buffer,1);  //HERE I AM WRONG OR I DID NOT UNDERSTAND
					
			}
		else{
				serial_send(send_buffer,0);
			}
	return 0;
	}
}
// AND HERE İS THE SLAVE 

//SLAVE
#define F_CPU 20000000UL	//Baby Orangutan frequency (20MHz)
#include <pololu/orangutan.h>


#define	LED PORTB1    //THİS WİLL BE ON SLAVE
//#define BUTTON PORTB0

char send_buffer[32];
char receive_buffer[32];



int main( void )
{
	serial_set_baud_rate(34800);
	
	while ( 1 )
	{
		
		if (serial_receive(receive_buffer,1))
		{
			
			PORTB |= (1<<LED);
			
		}
		else{
			PORTB &= ~(1<<LED);
		}
		return 0;
	}
}

Could you please help me about this. My project is simple. But i have to use ATMEL STUDIO,
So i could not modify the arduino code.

It looks like you do not understand how the OrangutanSerial function serial_send() works. The last parameter of the serial_send() function expects a value of unsigned char called size, referring to the number of bytes of the buffer (e.g. send_buffer) that will be transmitted. This is all explained in the documentation for serial_send() under the “Orangutan Serial Port Communication” section of the Pololu AVR Library Command Reference guide, which I linked in my previous post. Also, you should remove return 0; in both the master and slave code. You should never return from main() on an AVR.

Have you ever gotten the two Baby Orangutans to communicate with each other without the Bluetooth modules? If not, I suggest focusing on getting the two Baby Orangutans to work together by connecting their UARTs together directly before adding other devices. Here’s a quick snippet of code showing how to detect a button press and sending a byte using the OrangutanSerial library:

#include <pololu/orangutan.h>

#define BUTTON (1 << PORTB0)

char send_buffer[32];

int main()
{
	DDRB = 0x00;	//set port b to be an input
	PORTB = 0x01;	//set pin B0 to be an input pull up
	
	serial_set_baud_rate(9600);
	
    // constantly sending 1 or 0 to slave Baby Orangutan
	while(1)
	{
		// Check if button is pressed and send 1.
		// Otherwise, send 0.
		if (!(PINB & BUTTON))	//pushing button makes input low - invert logic
		{
			send_buffer[0] = 1;	//set first index of send_buffer to 1
		}
		else
		{
			send_buffer[0] = 0;	//set first index of send_buffer to 0
		}
		serial_send_blocking(send_buffer,1);
	}
}

For your slave, you could do the following:

#include <pololu/orangutan.h>

#define LED (1 << PORTB1)

// receive_buffer_position: This variable will keep track of which bytes in the receive buffer
// we have already processed.  It is the offset (0-31) of the next byte
// in the buffer to process.
unsigned char receive_buffer_position = 0;

char receive_buffer[32];

void check_for_new_bytes_received()
{
	while(serial_get_received_bytes() != receive_buffer_position)
	{
		// Process the new byte that has just been received.
		if (receive_buffer[receive_buffer_position] == 1)
		{
			PORTB |= LED;	//turn on LED
		}
		else if (receive_buffer[receive_buffer_position] == 0)
		{
			PORTB &= ~LED;	//turn off LED
		}
		
		// Increment receive_buffer_position, but wrap around when it gets to
		// the end of the buffer.
		if (receive_buffer_position == sizeof(receive_buffer)-1)
		{
			receive_buffer_position = 0;
		}
		else
		{
			receive_buffer_position++;
		}
	}
}

int main()
{
	DDRB = 0xFF;	//set port b to be an output
	PORTB = 0x00;	//set all port b pins to output low

	serial_set_baud_rate(9600);
	
	// Start receiving bytes in the ring buffer.
	serial_receive_ring(receive_buffer, sizeof(receive_buffer));
	
	while(1)
	{
		// Deal with any new bytes received.
		check_for_new_bytes_received();
	}
}

- Amanda