Selfmade BUS-system with arduino mega

Right now im working on a project to create a BUS system.

I have two wires which work as both, energy and data transmission (the power/data line switches from +9V to -9V, where +9V is high and -9V is low).

I then have a circuit to power the arduino board and another to get the voltage to +5,2V (from +9V) or +0,2V (from -9V).

Now what i want to do is sending a bitcode to the arduino, lets say 8 bits: 10101100
This will represent in +9V -9V +9V -9V +9V +9V -9V -9V and then the line goes back to +9V constant.

The voltage on the line without a message send is constant +9V, so when i send something i want to "activate" the arduino to listen, like i send 4 bits (0000) and then want to monitor the incoming message to process it later.

I know i can read a analog pin with digitalRead() to get the result (high or low) and i know the timing how the pulses will come ( lets say 1Hz, but later i want to go up to 50kHz).
This means i should be able to use digitalRead(PIN), wait the frequence time, digitalRead(PIN) again, wait again and so on.

I have something in mind like:

read Pin;

write binary to variable X;
(variable X shall have 4 "digits", so when a new read comes the value before should go to the next place
X at start: 1111, now the first low comes in, so X should be 1110, then 1100, 1000, 0000)

wait frequence time;

if X == 0000;
loop until counter reaches 8;
read Pin;
counter +1;
write binary to variable Y;
wait X time;

Now the variable Y shall be monitored the same, except i know its 8 bits long, so i can use a counter. After that the arduino goes back to its waiting mode, +9V on the line, until the next 0000 is monitored.

My most urgent problem atm: how can i write those digitalReads to a variable in bit format?

Im new with the arduino so im asking for the syntax i could use to achieve this. Can i use bitWrite() for this? For the second part with the 8 bits i assume i can, but i know the message lengh. How can i monitor the line and watch if four times 0 is send?

I dont need or want a full code or something like that, i just want a tap in the right direction.

EDIT: Corrected some errors
EDIT2: The "code" i gave as example is only to show how it should work, i know that its completly missing any functionable syntax. Its only as example.

It sounds like you just re-invented RS232. Welcome to the 1960s!

RS232 uses +/-12V and small devices such as mice are powered from the data lines exactly like you suggest.

Look up how RS232 works. It has 'mark' and 'space' represented by the two voltage levels. The first bit of any transmission is called a 'start bit'. When the receiver sees that start, it starts an internal clock. It waits for 1.5 bit times so that it samples the middle of the next bit (the first data bit). Then it waits 1 bit time to find the middle of the next bit...

There can be stop bits and other details but that is basically it.

If you condition your incoming power+data to give data at 0-5V then you can wire this directly to the Arduino Rx pin and use the hardware Serial to do this for you. You can transmit by just amplifying the Tx up to the +/-9V you want.

A MAX232 chip (there are a lot in that family) can even create the +/- voltages from 5V for the transmitter. It just can't drive a lot of power at that voltage however.

MorganS:
It sounds like you just re-invented RS232. Welcome to the 1960s!

RS232 uses +/-12V and small devices such as mice are powered from the data lines exactly like you suggest.

Look up how RS232 works. It has 'mark' and 'space' represented by the two voltage levels. The first bit of any transmission is called a 'start bit'. When the receiver sees that start, it starts an internal clock. It waits for 1.5 bit times so that it samples the middle of the next bit (the first data bit). Then it waits 1 bit time to find the middle of the next bit...

There can be stop bits and other details but that is basically it.

If you condition your incoming power+data to give data at 0-5V then you can wire this directly to the Arduino Rx pin and use the hardware Serial to do this for you. You can transmit by just amplifying the Tx up to the +/-9V you want.

A MAX232 chip (there are a lot in that family) can even create the +/- voltages from 5V for the transmitter. It just can't drive a lot of power at that voltage however.

Thanks for your reply.
I already have a possibility to create the +/-9V signal, done with a full bridge motor driver (since i also should be able to get up to 3A on the line.
The driver sends the +/-9V over the wire and i have a circuit to get the power for the arduino (power the arduino through Vin pin).
Another parallel circuit breaks down the +/-9V to +5/0V, thats my data input. This is all done so far, now im at the programming part. Will take a look on the Rx/Tx pins, thanks again.

Your description sounds like you want to send power and data over the same pair of wires. If so that is probably very like the way the the Digital Command Control (DCC) system for model trains works. It uses the width of the pulses to encode data.

People have made DCC encoders and decoders using Arduinos. Google should find them.

...R

I see several problems with this scheme:

  1. If you are using significant power at the receiver end (up to 3A) then it will load down the data being transmitted. Any capacitor you put at the receiver will round off the transitions badly and this will limit the maximum data rate

  2. If the receiver uses power intermittently, say PWM drive for a motor or heater, those pulses are going to interfere with the data just from the unavoidable resistance of the wires.

  3. This thing will radiate interference like crazy. +/-3A at high frequency will send out power proportional to the square of the frequency. AC power in your home uses 50 or 60Hz which is just terrible as a data rate. 50 bits per second? Put a memory card in an envelope and send it by the slowest post and you get a higher data rate.

  4. For bidirectional communication, is the receiver also expected to generate these high voltages? If it doesn't then the return data will be destroyed by the interference coming from the power wires.

There are many other systems that send power and data on the same wire. Look up "phantom power" "power over Ethernet" or "powerline networking". All of them send power at low frequencies (like zero) and modulate a low voltage data signal on top of that.

MorganS:
I see several problems with this scheme:

  1. If you are using significant power at the receiver end (up to 3A) then it will load down the data being transmitted. Any capacitor you put at the receiver will round off the transitions badly and this will limit the maximum data rate

  2. If the receiver uses power intermittently, say PWM drive for a motor or heater, those pulses are going to interfere with the data just from the unavoidable resistance of the wires.

  3. This thing will radiate interference like crazy. +/-3A at high frequency will send out power proportional to the square of the frequency. AC power in your home uses 50 or 60Hz which is just terrible as a data rate. 50 bits per second? Put a memory card in an envelope and send it by the slowest post and you get a higher data rate.

  4. For bidirectional communication, is the receiver also expected to generate these high voltages? If it doesn't then the return data will be destroyed by the interference coming from the power wires.

There are many other systems that send power and data on the same wire. Look up "phantom power" "power over Ethernet" or "powerline networking". All of them send power at low frequencies (like zero) and modulate a low voltage data signal on top of that.

For 1: The system should consist of multiple arduinos, one functioning as a master, the rest slaves. The current up to 3A is only for the supply of more boards, i wont use it for any motor or so, but in the task i got is stated that the maximum possible current should be 3A. Im nowhere near of using that, but it should be able to.

For 2: As said, i dont use any motors or heater or else, the system is only for the communication between the master and the slave. I know i could simply link the arduinos directly, but thats not what my task looks like. Its an experiment in which i shall use 2 wires for communication and power supply. The master sends a message, the slave decodes it an for example lights a LED on a output pin.

For 3: Have to take a closer look into that.

For 4: The communication is one-sided, the master sends a message via alternating voltage to the slaves, the slave which is adressed "answers" when he recived the message by increasing the current on the power line by 270mA for half a second. The slaves itself wont send anything back over the power/data line.

Robin2:
Your description sounds like you want to send power and data over the same pair of wires. If so that is probably very like the way the the Digital Command Control (DCC) system for model trains works. It uses the width of the pulses to encode data.

People have made DCC encoders and decoders using Arduinos. Google should find them.

...R

Thank you also for the reply, i will take a look into that aswell.

Florian_Morsch:
For 4: The communication is one-sided, the master sends a message via alternating voltage to the slaves, the slave which is adressed "answers" when he recived the message by increasing the current on the power line by 270mA for half a second. The slaves itself wont send anything back over the power/data line.

So all the other slaves have to pause what they are doing in case one of them actually uses a few mA to do something useful while the addresed slave replies?

What does the answering slave do with this power? Pumps it out as heat in a 3W resistor?

Why does the slave need to acknowledge at all?

MorganS:
So all the other slaves have to pause what they are doing in case one of them actually uses a few mA to do something useful while the addresed slave replies?

What does the answering slave do with this power? Pumps it out as heat in a 3W resistor?

Why does the slave need to acknowledge at all?

Basically the task was: Create a bus system consisting of one master and multiple slaves (arduino boards) which are connected with 2 wires only.
The power supply and communication is done over those 2 wires (the master has his own power supply via USB, the slaves shall be supplied by the power/comm line).
The signals should be generated by alternating the voltage between +9V (high) and -9V (low) and should be able to go up to 3A. The switch frequency is to be determined within the work, but not higher then 50kHz (if the System can only manage e.g. 500 Hz, then i have to explain why and done).
To create the power/signal the suggestion was a powerful MOSFET H-bridge, but the transistors have problems with such high frequency so i searched for a bridge driver, which could go up to 9V, +-3A at 50kHz.

The master should send a message to a slaves, like set analog or digital pins to input/output or so. When the adressed slave understood that message it should raise the current by 270mA over a 33Ohm resistor. The current is monitored at the master and if the raise is detected the communication is finished, if not the master sends the message again.

So the slaves wont do anything at all except set output pins digital or analog. Its simply a experimental work which is graded later.

So we are doing your homework for yoi?

MorganS:
So we are doing your homework for yoi?

May i point out what i wrote in the first post?

Florian_Morsch:
My most urgent problem atm: how can i write those digitalReads to a variable in bit format?

Im new with the arduino so im asking for the syntax i could use to achieve this. Can i use bitWrite() for this? For the second part with the 8 bits i assume i can, but i know the message lengh. How can i monitor the line and watch if four times 0 is send?

I dont need or want a full code or something like that, i just want a tap in the right direction.

I dont want anyone to do my homework, i asked for tips, nothing more. You gave me some points to work with in the first place and therefor im thankful. But you also kept asking and i just gave the answers to your questions. Since you seemed interested or asked more questions i just thought it would be useful to provide the information about the task. So please, and i mean no offence, dont confuse me giving answers to your questions with getting anyone to do "homework" for me.

I never ever said someone else should do it for me! I just thought since im new at working with arduinos someone here might have some useful information, which i also already got some.

Florian_Morsch:
The power supply and communication is done over those 2 wires (the master has his own power supply via USB, the slaves shall be supplied by the power/comm line).

[...]

When the adressed slave understood that message it should raise the current by 270mA over a 33Ohm resistor. The current is monitored at the master and if the raise is detected the communication is finished, if not the master sends the message again.

Leaving aside the question of programming how could a slave electrically raise the current in the line that is powering the slave.

That sounds like trying to lift yourself up by your bootlaces so the scales you are standing on gives a more favourable reading.

Why not save yourself a lot of trouble and add a third wire for data.

...R

Robin2:
Leaving aside the question of programming how could a slave electrically raise the current in the line that is powering the slave.

That sounds like trying to lift yourself up by your bootlaces so the scales you are standing on gives a more favourable reading.

Why not save yourself a lot of trouble and add a third wire for data.

...R

For the question why not a third wire: The task for me is to do it with 2 wires. I know it would be easy if i just connect the arduinos directly and let them communicate, but i have to try it in a different way.

The slave can use a 33 ohm resistor with a transistor. I get the +/-9V as input, lead it to a bridge rectifier (diode bridge) to get back a constant +9V and send that into a voltage regulator (L7805) which powers the arduino on Vin. Now i set a transistor before the regulator between the 9V and the other wire and add a 33 ohm resistor. When the slave has accepted the message it switches the transistor for .5 seconds, so i have a current of around 270mA over that resistor. Back on the master side i monitor the current on those 2 lines, when there is a raise of 270mA i just get a signal and i know the slave has answered.
I should point out: in a case with multiple slaves i dont know which slave has answered, just that some slave has answered (but thats totaly ok).

Florian_Morsch:
The slave can use a 33 ohm resistor with a transistor. I get the +/-9V as input, lead it to a bridge rectifier (diode bridge) to get back a constant +9V and send that into a voltage regulator (L7805) which powers the arduino on Vin. Now i set a transistor before the regulator between the 9V and the other wire and add a 33 ohm resistor. When the slave has accepted the message it switches the transistor for .5 seconds, so i have a current of around 270mA over that resistor. Back on the master side i monitor the current on those 2 lines, when there is a raise of 270mA i just get a signal and i know the slave has answered.

I'm finding it very hard to make sense of this.

Do you mean that there is normally a steady current in the two wires that is supplying power to all of the slaves and a slave can trigger a transistor to cause more current to be drawn by "shorting" a 33 ohm resistor across the power wires?

...R

Robin2:
I'm finding it very hard to make sense of this.

Do you mean that there is normally a steady current in the two wires that is supplying power to all of the slaves and a slave can trigger a transistor to cause more current to be drawn by "shorting" a 33 ohm resistor across the power wires?

...R

Yes to the second part, after the bridge rectifier i have a constant current which supplies the board and in between that i plan on "shorting" the 33 ohm resistor.
(Sorry, im a littly rusty with english and raising the current might not have been the right wording for it)

I have the Masterboard(Arduino) which controls a H-bridge/ motor bridge. Only i dont power a motor, instead where the motor would be in a H-bridge i have one or more slaves parallel. Those slaves have a circuit board before them. So im using the one line from the bridge as power/data line, the other as "ground" (this ground will never be connected to the master board ground nor will the the slaves get any other interaction outside their two wire system, i know that this would be catastrophic). Now if the master switches the bridge it can alternate between +/-9V.

The circuit board before the slave has 2 functions: power the slave arduino board and split the signal so i can read it with the slave arduino. The board power circuit is as described before. The other circuit is basically a diode clipping which sets the +/-9V to 5V or 0V. Thats the signal i play to read on a analog pin and convert it to 1 or 0.

From Reply #14 ...

after the bridge rectifier i have a constant current

I don't understand the role of this. Why are you bothering to create an alternating current just to rectify it?

You need to provide a diagram (not a detailed schematic) that illustrates the concept you have in mind.

And if the current in the pair of wires is alternating (as commanded by the Mega) then how will anything be able to distinguish the difference caused by the brief use of your 33 Ohm resistor?

And something I overlooked earlier...

If you connect a 33ohm resistor across a pair of wires supplied at 9v there will certainly be a 273mA current in the resistor. But the Arduino's ADC detects voltage and there may be no change at all in the voltage from the 9v supply. And if the voltage does fall a little then there won't be 273mA flowing in the resistor.

I guess you could flow the current through a small resistor (maybe 1 ohm) at the Mega end and allow the Mega to measure the voltage across that resistor. But 270mA extra would make a very small difference in the voltage across a 1 ohm resistor. The Mega does include an amplifier that can be used in conjunction with the ADC - but you will need to read the Atmega2560 datasheet for the details. It is not a feature that is part of the normal Arduino box of tricks.

...R

Robin2:
From Reply #14 ...
I don't understand the role of this. Why are you bothering to create an alternating current just to rectify it?

You need to provide a diagram (not a detailed schematic) that illustrates the concept you have in mind.

And if the current in the pair of wires is alternating (as commanded by the Mega) then how will anything be able to distinguish the difference caused by the brief use of your 33 Ohm resistor?

And something I overlooked earlier...

If you connect a 33ohm resistor across a pair of wires supplied at 9v there will certainly be a 273mA current in the resistor. But the Arduino's ADC detects voltage and there may be no change at all in the voltage from the 9v supply. And if the voltage does fall a little then there won't be 273mA flowing in the resistor.

I guess you could flow the current through a small resistor (maybe 1 ohm) at the Mega end and allow the Mega to measure the voltage across that resistor. But 270mA extra would make a very small difference in the voltage across a 1 ohm resistor. The Mega does include an amplifier that can be used in conjunction with the ADC - but you will need to read the Atmega2560 datasheet for the details. It is not a feature that is part of the normal Arduino box of tricks.

...R

Well, to power a arduino i need DC, right? So i could simply use the wire to get the +9V to the arduino, done.
But then i need to send a signal over the same wire, where +9V counts as 1 or high, and -9V represents a 0 or low. This means i cant connect the arduino directly to the wire pair since the voltage is alternating between +9V and -9V and i need a constant voltage at the Vin pin. Thats why i do it.

To the part with the detection, i never said i want to detect the current with the arduino. I have a seperat IC for current sensing which gives a signal to the arduino when it detects the change.

I will include a schematic tomorrow. But i have to say im amazed how far the topic drifted from the original question which i asked in the first post :smiley:

Florian_Morsch:
I will include a schematic tomorrow.

I suggested a diagram rather than a schematic - to give a clear overview rather than details.

But i have to say im amazed how far the topic drifted from the original question which i asked in the first post :smiley:

Having looked again at your Original Post I'm amazed that you are amazed.

...R

Robin2:
I suggested a diagram rather than a schematic - to give a clear overview rather than details.

...R

I hope this is ok for now:

General concept

Short description in a bit more detail

Master circuit board

Slave circuit board

EDIT: I already have the electronical parts (diodes, transistors, bridge, voltage regulator, capacitors). What i asked for in the first place was a way to get the slave to monitor the input from the message reciver constantly and as soon as there are four times LOW in a row, the message should be recorded and then the slave should do something (switch pins to in- or output for example)

Please make your images visible here. See this Simple Image Guide

...R