Single Pin Binary Data Transmission (w/ Baby-o 328)

We have a baby-o 328p, and we are in need of sending a serial transmission through one of the Baby-o’s pins if possible…for example:

We would like to transmit the binary value “0001” from PORTD pin 3. How would we go about doing this? We are really looking for an example in C language; the examples are hard to follow.


The examples we provide with the Pololu AVR Library are in C, and they rely on Pololu AVR Library functions that are written in C (with the source code freely available), so I’m not sure what you’re asking for. I also don’t know what you mean when you say “transmit a binary value 0001”. Are you just trying to send the number 1? Are you trying to send a sequence of numbers or ASCII characters, each one of which represents a digit of your binary value? Finally, you talk about a serial transmission, but the pin you want to use is not the Baby Orangutan’s UART TX pin. If you want to do asynchronous serial, you will need to use PD1 to transmit, or you will have to write code to do serial in software or find a software serial library.

- Ben

i apologize for the confusion, but that is the main loop, and I will b sure to put the proper quotations. I don’t think it would run if it were not in a main loop. As far as the values go, we are trying to transmit a specific hex or binary value. Each value corresponds to a saved “.wav” file on the sound module. Example:

".wav" file number Value in hex
1 00h
2 01h
3 02h
256 FFh

We would just like to see a quick example code on how to send either a hex or binary value from one of the transmission pins. Once the transmission is made, the sound module will play a recording based on the value received.

I think the first two sentences of your post do not apply to this thread.

What do you mean by “transmit a specific hex or binary value”? Phrased like this, it makes it sound like you are either omitting key details about what you are trying to do, or you are fundamentally misunderstanding something. It doesn’t make sense to say you want to send a serial byte in hex or binary, as those are just different ways of representing the same byte value. What you are sending is the value of the byte, and how you represent it is just an implementation detail, not something that affects the value sent. Do you understand the distinction between a value and the way you represent it? For example, if all I want is to communicate a value, it does not make sense to say “I want to send the number ten, not 10, 0xA, or 0b1010”. If, on the other hand, I am trying to communicate a particular representation so, for example, it prints out nicely in a terminal window or because the device I’m talking to uses an ASCII interface, then I could talk about wanting to send the number 10 as the ASCII string {‘1’, ‘0’} instead of {‘0’ ‘x’ ‘A’}. For many applications, however, the recipient will just be using the data for internal calculations, so the representation is irrelevant, and if it will be displaying the data, it can choose for itself what representation to use.

Is this a case where your target device is expecting an ASCII string representation of a value?

Using the UART on the AVR is not necessarily “simple”, but there are a ton of applications out there that do it, so you should try googling around. Our library makes it relatively easy to send serial data, however, so I think that’s the way you should go. If something about the serial part of our library is confusing, you should ask specific questions about what you don’t understand. Your code might be as simple as:

serial_set_baud_rate(115200);  // set baud rate to 115.2 kbps
char buffer[1];  // create an array with one element to hold the byte we're going to send
buffer[0] = 0x01;  // set the value of the byte we're going to send
serial_send_blocking(buffer, 1);  // send the byte

- Ben

transmit…serial communication…regardless what you sent me seems to do what I need it to. I only have 3 questions:
1.) can we send more than 1 byte, and if so is there a limit?
2.) can you send me an example of receiving as well (one that is as simple as the previous one)
3.) what pin is this “0x01” being sent from?

Please note that the issue is not your use of the word “transmit”, it’s the use of the phrase “transmit a hex value”.

Questions 1 and 3 are answered in the Pololu AVR Library command reference. For question 2, please see the serial1 example in the Pololu AVR Library and look through the command reference documentation. All the information you need is there. If there is something specific you don’t understand, please ask.

- Ben