Baby-O UART Serial Transmitter problem solved


I am struggling getting the UART serial transmission going on my Baby-O, there is communication but the baudrate does not seem to match.

For testing I used the Pololu Library example, as I do not have any buttons I moved the “Hi there!” outside the push button action and created a 1 sec interval.

[code]/* uart3 - an application for the Pololu Baby Orangutan B
*

#include <pololu/orangutan.h>

/*

  • serial1: for the Orangutan controllers and 3pi robot.
  • This example listens for bytes on PD0/RXD. Whenever it receives a byte, it
  • performs a custom action. Whenever the user presses the middle button, it
  • transmits a greeting on PD1/TXD.
  • The Baby Orangutan does not have a green LED, LCD, or pushbuttons so
  • that part of the code will not work.
  • To make this example compile for the Orangutan SVP, you
  • must add a first argument of UART0 to all the serial_*
  • function calls.
  • Pololu AVR C/C++ Library User’s Guide
  • https://www.pololu.com
  • https://forum.pololu.com
    */

// receive_buffer: A ring buffer that we will use to receive bytes on PD0/RXD.
// The OrangutanSerial library will put received bytes in to
// the buffer starting at the beginning (receiveBuffer[0]).
// After the buffer has been filled, the library will automatically
// start over at the beginning.
char receive_buffer[32];

// 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;

// send_buffer: A buffer for sending bytes on PD1/TXD.
char send_buffer[32];

// wait_for_sending_to_finish: Waits for the bytes in the send buffer to
// finish transmitting on PD1/TXD. We must call this before modifying
// send_buffer or trying to send more bytes, because otherwise we could
// corrupt an existing transmission.
void wait_for_sending_to_finish()
{
while(!serial_send_buffer_empty());
}

// process_received_byte: Responds to a byte that has been received on
// PD0/RXD. If you are writing your own serial program, you can
// replace all the code in this function with your own custom behaviors.
void process_received_byte(char byte)
{
switch(byte)
{
// If the character ‘G’ is received, turn on the green LED.
case ‘G’:
green_led(1);
break;

    // If the character 'g' is received, turn off the green LED.
    case 'g':
        green_led(0);
        break;

    // If the character 'c' is received, play the note c.
    case 'c':
        play_from_program_space(PSTR("c16"));
        break;

    // If the character 'd' is received, play the note d.
    case 'd':
        play_from_program_space(PSTR("d16"));
        break;

    // If any other character is received, change its capitalization and
    // send it back.
    default:
        wait_for_sending_to_finish();
        send_buffer[0] = byte ^ 0x20;
        serial_send(send_buffer, 1);
        break;
}

}

void check_for_new_bytes_received()
{
while(serial_get_received_bytes() != receive_buffer_position)
{
// Process the new byte that has just been received.
process_received_byte(receive_buffer[receive_buffer_position]);

    // 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()
{
// Set the baud rate to 9600 bits per second. Each byte takes ten bit
// times, so you can get at most 960 bytes per second at this speed.
serial_set_baud_rate(9600);

// Start receiving bytes in the ring buffer.
serial_receive_ring(receive_buffer, sizeof(receive_buffer));

while(1)
{
         wait_for_sending_to_finish();							//send repeatingly without buttons
         memcpy_P(send_buffer, PSTR("Hi there!\r\n"), 11);
         serial_send(send_buffer, 11);
		 delay_ms(1000);

    // Deal with any new bytes received.
    check_for_new_bytes_received();

    // If the user presses the middle button, send "Hi there!"
    // and wait until the user releases the button.
    if (button_is_pressed(MIDDLE_BUTTON))
    {
        wait_for_sending_to_finish();
        memcpy_P(send_buffer, PSTR("Hi there!\r\n"), 11);
        serial_send(send_buffer, 11);

        // Wait for the user to release the button.  While the processor is
        // waiting, the OrangutanSerial library will take care of receiving
        // bytes using the serial reception interrupt.  But if enough bytes
        // arrive during this period to fill up the receive_buffer, then the
        // older bytes will be lost and we won't know exactly how many bytes
        // have been received.
        wait_for_button_release(MIDDLE_BUTTON);
    }
}

}[/code]

For reading the serial I use the Pololu programmer attached to GND, TX and RX of my Baby-O

I tried some other examples but nothing was successful.

I created this with Atmel Studion 6.2 and after creation of a new project I copied the software from the library description documented on the pololu website. Does this create an omission. Is it possible to open this example directly from Atmel Studio?

Looking further I noticed that Hi there! is actually there, the 48 represents the ASCII code for ‘H’

Can I prevent that from happening?

How do I send numbers?

Serial data transmission is working as expected. What is it that you really want to do?

I want a list of MPU6050 sensor values. It appears that when the motor is running the noise is too much for my logic to handle. In order to solve this I need some filtering. I read a lot about KALMAN filtering and wondered if I could extract my sensor values and put them in an Excel simulation sheet so I can test my logic and determine the output before putting it into my program.

The following code allows me to grab a value from the sensor and send it out by serial logic. In this case I prefer PUTTY as this gives a clean column of values which can be copied directly into Excel.

The Serial Transmitter just give too much information of the received message.

This test program shows the functionality to send a series of values in a column. Now I have to put that into my prototype and get me some real data.

[code]/* uart_tx_poc - an application for the Pololu Baby Orangutan B
*

#include <pololu/orangutan.h>
#include <stdio.h>

//-----------------------------------------------------------------------------
// ATmega328P Baby-O
//-----------------------------------------------------------------------------

#define F_CPU 20000000UL
#define BaudRate 9600UL
#define UBRR F_CPU/16/BAUD-1

//-----------------------------------------------------------------------------
// Initialize USART0
//-----------------------------------------------------------------------------
void uart_init (void)
{
uint16_t ubrr = (uint16_t) ((uint32_t)F_CPU/(16*BaudRate)-1);
UBRR0H = (uint8_t)(ubrr >> 8);
UBRR0L = (uint8_t)(ubrr);

UCSR0B = (1<<RXEN0)|(1<<TXEN0);
UCSR0C = (1<<UCSZ01)|(1<<UCSZ00);

}

void uart_putchar(unsigned char c)
{
while ( !( UCSR0A & (1<<UDRE0)) );
UDR0 = c;
}

void uart_write(char * str)
{
while (*str) {
uart_putchar(*str++);
}
}

//-----------------------------------------------------------------------------
// Main
//-----------------------------------------------------------------------------

int main (void)
{
uart_init();
unsigned int avg;
avg = 0;

while (1)
{
	char buffer[30];
	sprintf(buffer, "%d", avg);
	uart_write(buffer);
	uart_write("\r\n"); //for the line feed

	avg = ( avg + 1 ); // Raise avg by one
	delay_ms(1);
}

return 0;

}[/code]