Teensy receiving serial data from PIC16F873 microcontroller - how to unpack?

Status
Not open for further replies.

zalterman

Well-known member
Hey guys - I'm new to the teensy platform, but so far am finding it more efficient and understandable than other microcontroller packages I've used - and this community seems awesome! Excited to dig in.

I'm a drummer and built a 'wing' for my floor tom drum that has 16 buttons, 4 linear potentiometers, and a soft pot (https://www.sparkfun.com/products/8680 )
These sensors are all used to control the sound of the drum (using a mic, audio interface, and MAX/MSP on a laptop). Recently, I had a friend help me package all of this data (16 digital inputs, 5 (preferably 8 bit) analog inputs) into a serial data stream using a PIC16F873. Here is the structure of the repeating 10 bytes of the 'loop' of information

1 2 3 4 5 6 7 8 9 10
[sync byte, sync byte, AnalogInput 0 (8bit), AI1,AI2,AI3,AI4, DigitalInputs1(8 bits for 8 buttons), DI2, EndOfMessage byte]

I am trying to figure out how to unpack this serial stream and translate it to 21 controlChange MIDI messages. I understand how to use the usbMIDI library and can transmit MIDI when each sensor is direct into individual teensy pins - its just the serial unpacking that is stumping me.

I have read this
https://www.pjrc.com/teensy/td_uart.html
but cant seem to find any information on how HardwareSerial() works. Maybe my confusion is just that I don't understand serial data flow very well - Is serial data packaged into full bytes rather than a series of bits? Is what is happening is that every (1/baud rate) of a second, a new byte is replaced, and every (1/baud rate) of a second, HardwareSerial().read() must be called and assigned? What is keeping the length of the loop() in the code 1/baud rate? I am confused as to how everything is being synced.

Maybe someone could point me in the right direction? Let me know what I need to read up on and where to find it?

Thanks so much!
Zach
 
Status
Not open for further replies.
Back
Top