Sending a Binary code out through a digital pin?

Heya folks! I am trying to send a signal to an adjustable desk controller, and to do that I need to send a couple binary values out. I am attempting to clone what a controller is doing, which is a series of off and on signals at 100us each.

For example, I would want to send out [0 1 0 0 0 1 0 0 1 0 0 1 0 1 0 1 1 0] with each bit lasting 100us each.

I could do a dirty method of creating an array, setting HIGH or LOW the pin depending on the value, but even the delay() function can only go at 1ms, and that includes the processing time of the loop and digital write function.

Any thoughts on how I can send a patterned pulse, like above, at the timing I am seeking?

Take a look at the micros() function

May use delayMicroseconds()
Look :
" Arduino - delayMicroseconds () function

and use bitRead(x, n) to read and send a bit.

Look : " https://www.arduino.cc/reference/en/language/functions/bits-and-bytes/bitread/

Is there the slightest possibility that the controller actually ouputssome kind of traditional serial communication?

Do you have any tech info on the device to be controlled?

a7

Would I constantly check the micros() to do the next step of my pulse? Would the concept below be what you are thinking?

quick version of code without correct style:

array1 = [0 1 0 0 0 1 0 0 1 0 0 1 0 1 0 1 1 0];
array2 = [0 1 0 0 1 1 0 0 1 0 0 1 0 1 1 0 1 1];

void loop(){
Code to wait for input waiting to know what code to send

//function for sending pulses:
reset micros() somehow
for(not gone through entire array of numbers){
while (micros < 40us * stage of array) {loop here}
digitalwrite (value of current stage of array)
}

It is sending out 4 binary numbers, the first 3 declare the type of desk, and the last is the height. I don't have a serial communication module to the controller, so trying to do it over a pinout. I have looked up how others have done this, or at least their analysis of the data being sent, and confirmed using an oscilloscope. Unfortunately I don't have a tech or spec sheet for the controller.

There's nothing wrong with just using delayMicroseconds().

Put the bit on the pin, delay, repeat.

The exact delay factor might need a bit of tweaking, but the inter-bit overheard time should be very consistent, so delay should be able to time pout the sequences.

Can you share links to the device to be controlled, and any useful sites that have hacked or attempted to hack this?

a7

and

Looking at this:
image
I can't help but wonder if it's just 8 bit serial, no parity. You can see what looks like a repeating stop bit. What is the exact pulse width (again?).

If it is UART serial at 9600 Baud, the bit width is 104 usec.

1 Like

That 104us does line up better with my scoped values.

Approx 100us, more likely 104us. It's default value is high, with this value code you posted coming after 3 other values declaring what I assume is limit / max values. It is a consistent pattern followed by the pulse pattern.

Tomorrow (no more time today to do computer stuff) I will mess with it, make a test code, and see what happens!

Serial default value is also HIGH. Look to see if the pattern repeats and contains

  1. a start bit, always 0
  2. a fixed number of data bits, usually 8
  3. a stop bit, always 1

It would be pretty funny if two different hacks never discovered such a simple thing!

1 Like

Yeah I don't know much about Serial comm but I even clued in on that!

If I get anywhere I will def update.

Two stop bits is an option, but that rarely matters.

The sender is always allowed to stay in stop state (HIGH = idle) as long as it wants.
"Two stop bits" means the receiver needs such a pause to deal with the complete byte, and the sender has to wait that time before it is allowed to switch to LOW to signal the start bit.

If you can always identify a stop bit HIGH 9 *104 usec after a start bit HIGH->LOW, I'm confident you can use UART hardware to produce such data.

You might target a serial receiver (or logic analyzer with serial protocol decoder) at that controller.

How do you synchronize to the start of such a bit stream, how long does it take?

Haven't gotten to syncing, but will cross that bridge when I get there.

Is there a guide I can follow to send UART values out of the Tx pin? Wanting to keep from having to use additional hardware, just want to give a value and have it sent out to the controller from the Arduino.

Depends on which Arduino you have.

For the Uno, Serial.write() sends one data byte, with Baud rate, start, parity and stop bits determined by the Serial.begin() parameters.

Pick an Arduino with more than one hardware serial port for fewest difficulties.

Congrats to @anon57585045 and @jremington: They have quickly recognized what's going on!!!

If you carefully read the linked "Nerves At Home ..." article from your post #8 you can see

Quote:

Then it clicked: Serial data can be framed differently. And Circuits.UART can handle framing.

The author of that article is using this

https://github.com/elixir-circuits/circuits_uart

with the programming language Elixir but is linking in his article to a wrong page:

yet another fancy library, Circuits.UART. From there,

goes to circuits_gpio ...

The nice thing is this if you look into the library there ...

void uart_default_config(struct uart_config *config)
{
    config->active = true;
    config->speed = 9600;
    config->data_bits = 8;
    config->stop_bits = 1;
    config->parity = UART_PARITY_NONE;
    config->flow_control = UART_FLOWCONTROL_NONE;
   // ...
  }

So, it is serial comms and ... thanks to luck (and defaults) ... worked immediately without any changes of parameters ... :wink:
ec2021