hardward device

I need a mux and a demux attached to my arduino.
Question one:
It is possible to use the same device for mux and demux or it will be complecate becase the pin can be all time too full of signal?
question two.
If I need to use 2 devices, for the control with S0, S1, S2 do I need to use other digital pin with arduino or I can put them connect in the same pin and somehow the multiplexer undersand that the pin of the second device are counted summed the one of the first?
Like I put the first multiplexer in parallel with the second one and as to select pin 13 of the first that is 000 pin 13 of the second will be 1000 (8 channel mux)

my code is like this.

 buttonPin = digitalRead(A1);
  if( buttonPin==HIGH ) 
   {
   
   r0 = 0; //bitRead() -> parameter 1 = binary sequence, parameter 2 = which bit to read, starting from the right most bit
   r1 = 0; //channel 7 = 111, 1 = 2nd bit 
   r2 = 0; // third bit
   transmittedSignal();
   delay (1000); // time to read the values
   }
   else 
   {
voltage = ((pulseIn(9, LOW, 1280) * 100) / T) >> 1; //here I will put some code for demux in COM IN to devide the signal in three differen output
voltage = map(constrain(voltage, 0, 100), 0, 100, 0, 255);
dac.output(voltage);
    Serial.println(digitalRead(A1));
   }

Hi,
What is your application that needs mux and demux?

Tom..... :slight_smile:

three different tx and rx where tx1 , tx2 and tx3 are sent togethere andd the other part rx1 , rx2 and rx3 :slight_smile:

This sounds like another XY problem

Never mind rx1 rx2 rx3 etc

Just tell us what the actual project is about (what the user will see when it is complete) - not how you think it might be implemented

...R

You can not multiplex serial signals because you never know when they are going to arrive. Unless that is you know exactly when they will and you are not saying.

I am not multiplexing a serial signal.
I used serial only to see the output of the multiplexer (to see if it was working) but i will analyse the signal with arduino analogRead.
it is this my proget.

I have three analog signal 2.7V offset of 1.3 so it is positive and smaller then 5. this signal can have a variable frequency from 0 to 50Hz.

What I am doing is I put this three signal in the mux,
I send them in arduino only if the push button is HIGH (I put the push button in analog input and I used them as digital because using the mux require a lot of digital pin).
Then from arduino I send this signal in a PWM form out from digital pin 3 and I let them pass in a optic fiber, after I received them in another arduino where after going to the DAC will be separete by a DEMUX. this is my idea of my project.

I didnt use serial because I don't know the time and I didn't really understand how I can decode them. I don't know for example if I use Manchester to send by serial then I don't know how I can get the original signal.
my code for now is this I am still working in the receiver part. and both arduino have to be transmitter and receiver.
They need to be receiver if the button is high and receiver if the button is down. but I hqve three receiver and three transmitter so they hqve to work independently.
what do I mean is if only button a is high it is arduino 1 have one transmitter and two receiver and arduino 2 have two transmitter and one receiver.

#include <SPI.h>         //
#include <DAC_MCP49x1.h>
#define SS 10
// Set up the DAC.
// First argument: model (MCP4901, MCP4911, MCP4921)
// Second argument: SS photodiodo (10 is preferred)
// (The third argument, the LDAC photodiodo, can be left out if not used)
DAC_MCP49x1 dac(DAC_MCP49x1::MCP4901, SS);
int incomingSignal;//storage for A0 data
const int T = 128; //period in microsecond
int  voltage;
long lasttime;;
long debounceDelay = 0.0005;
byte buttonPin;    // the number of the pushbutton pin
byte buttonPin1;
int r0 = 0;
int r1 = 0;  // the three digital pins for the bits
int r2 = 0;

void transmittedSignal()
{
  digitalWrite(4, LOW); // I am using device CD4051B as mux
  digitalWrite(5, r0); // send the bits to the digital pins
  digitalWrite(6, r1);
  digitalWrite(7, r2);
  incomingSignal = analogRead(A0) >> 2;//get new value from A0
  analogWrite(3, incomingSignal); //assigned value to the LEDs
  digitalWrite(4, HIGH); //I disable the device CD405 //I am not sure if it is correct or it is necessary pag 3 data sheet CD4051B
  Serial.println(incomingSignal);
  
}

int receivedSignal()
{
  digitalWrite(8,LOW); // I am using device CD4051B as demux
  voltage = digitalRead(9); //for now I am sending from the other arduino only a digital signal 1 0 to see if I am receivng something, after it will be a PWM
  //voltage = ((pulseIn(9, LOW, 1280) * 100) / T) >> 1; //here is how i can get after the dac the original signal
  //voltage = map(constrain(voltage, 0, 100), 0, 100, 0, 255);
  //dac.output(voltage);
   digitalWrite(8, HIGH); //I disable the device CD405 //I am not sure if it is correct or it is necessary pag 3 data sheet CD4051B
}

void setup() {
  ADMUX |= (1 << ADLAR); //left align the ADC value- so we can read highest 8 bits from ADCH register only
  ADCSRA |= (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0); //prescaler 128 STO FACENDO UNA CONVERSIONE OGNI 0.104MS

  TCCR2A |= (1 << WGM20);

  bitClear(TCCR2B, CS20); //set prescaler to 8
  bitSet(TCCR2B, CS21);
  bitClear(TCCR2B, CS22);

  dac.setSPIDivider(SPI_CLOCK_DIV128);
  dac.setPortWrite(false);

  pinMode(3, OUTPUT); // tx
  pinMode(4, OUTPUT); // mux enable
  pinMode(5, OUTPUT);  // r0
  pinMode(6, OUTPUT);    // r1
  pinMode(7, OUTPUT);    // r2
  pinMode(8, OUTPUT); // demux enable
  pinMode(9, INPUT); //rx
  pinMode(A1, INPUT);    // button
  pinMode(A2, INPUT);    // button
  pinMode(A3, INPUT);    // button
  pinMode(A0, INPUT); // input mult
  digitalWrite(4,HIGH); //inizialization for the mux
  digitalWrite(8,HIGH);//inizialization for the demux
  Serial.begin(9600); // fire up the serial
  while (!Serial);
}


void loop () {

  buttonPin = digitalRead(A1);
  if ( buttonPin == HIGH )
  {
   
    r0 = 0; //bitRead() -> parameter 1 = binary sequence, parameter 2 = which bit to read, starting from the right most bit
    r1 = 0; //channel 7 = 111, 1 = 2nd bit
    r2 = 0; // third bit
    transmittedSignal();
    delay (1000); // time to read the values
  }
  else
  {
    receivedSignal();
    Serial.println(voltage);
  }

  buttonPin1 = digitalRead(A2);
  if (buttonPin1 == HIGH)
  {
    
    r0 = 0; //bitRead() -> parameter 1 = binary sequence, parameter 2 = which bit to read, starting from the right most bit
    r1 = 1; //channel 7 = 111, 1 = 2nd bit
    r2 = 0; // third bit
    transmittedSignal();
    delay (1000); // time to read the values
  }
  else
  {
    receivedSignal();
    Serial.println(voltage);
  }

  byte   buttonPin2 = digitalRead(A3);
  if ( buttonPin2 == HIGH )
  {
    r0 = 1; //bitRead() -> parameter 1 = binary sequence, parameter 2 = which bit to read, starting from the right most bit
    r1 = 0; //channel 7 = 111, 1 = 2nd bit
    r2 = 0; // third bit
    transmittedSignal();
    delay (1000); // time to read the values
  }
  else
  {
    receivedSignal();
    Serial.println(voltage);
  }
}

Hi,

Can you please post a copy of your complete circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Tom..... :slight_smile:

I hope is understandable. I had only one pen

http://img11.hostingpics.net/pics/395023photo.jpg

Giulialiuyi:
What I am doing is I put this three signal in the mux,
I send them in arduino only if the push button is HIGH (I put the push button in analog input and I used them as digital because using the mux require a lot of digital pin).

Still sounds like an XY problem - and the diagram confirms it.

Then from arduino I send this signal in a PWM form out from digital pin 3 and I let them pass in a optic fiber, after I received them in another arduino where after going to the DAC will be separete by a DEMUX. this is my idea of my project.

It makes no sense to send a PWM signal to another Arduino. Just send the value that is required by analogWrite() and let the receiving Arduino create the PWM signal.

...R

@Robin2

It makes no sense to send a PWM signal to another Arduino. Just send the value that is required by analogWrite() and let the receiving Arduino create the PWM signal.

What do you mean by that? whe there is no sense?

Can you do a code example to explain me what you mean?
I have the signal in A0 and I do for example

incomingSignal=analogRead(A0);
analogWrite(A4,incomingSignal);//A4 attached in the fiber?

I just read more carefull you requist

Just tell us what the actual project is about (what the user will see when it is complete) - not how you think it might be implemented

you should see the three signal coming from one side in the other side exactly the same :slight_smile:

So if you think it is a XY problem...
The new auestion can beI will ever obtain the original signal after transmitte and received using one mux one demux and a dac? :wink:

Giulialiuyi:
@Robin2What do you mean by that? whe there is no sense?

Can you do a code example to explain me what you mean?
I have the signal in A0 and I do for example

incomingSignal=analogRead(A0);

analogWrite(A4,incomingSignal);//A4 attached in the fiber?

Rather than analogWrite() use Serial.println(incomingSignal);

I just read more carefull you requist you should see the three signal coming from one side in the other side exactly the same :slight_smile:

Just tell us what the project is. Is it for controlling a bread toaster ? Or is it a control for a CD player ? Or is it intended to measure the weight of new-laid eggs ? What is it ?

...R

No it is just to bring the three signals at 100meter of distance. Then how one will use those signals is not my concern. It is only important that after transmitted I can get again the same signal, frequency and amplitude. (you can see it as a message), sending a message by optic fiber; and this message is an analog signal. To be able to measure from faraway!

I want to send by tx0 the value of three devices.
I want to receve them in RX1 and separate the in three different pin.
sensor 1 write to pin A3
sensor 2 write to pin A4
sensor 3 write to pin 15

now, I have no Idea how I can make arduino anderstand which signal is which.

I though to send before the signal something like

Serial.print('a');
Serial.println(valuesensor1);
Serial.print('b');
Serial.println(valuesensor2)
Serial.print('c');
Serial.println(valuesensor3)

The problem is that I am not using serial monitor but I am wathcing the signal with an oscilloscope.

What do you think it is the best aproch?

Not clear what you are trying to do.
Is the same Arduino doing the sending and receiving?
What is it that is being sent? Where does valuesensor1, valuesensor2, valuesensor3 come from?
What are you putting out to pins A3, A4, 15? Just High & Low?

Giulialiuyi:
and this message is an analog signal. To be able to measure from faraway!

I have no idea why you are keeping the project a secret and it is getting frustrating. I am not inclined to give my time for free if you are working on a commercial project.

If you already have the information in digital form, why not transmit it as digital information. That is how the telephone system uses fibre-optics.

If you want to send information for 3 or 303 devices you can easily interleave the digital data.

...R

I would work backwards for a problem like this.

Design the system that is going to receive the data and then transmit it in the corresponding manner.

The examples in serial input basics are simple and reliable ways to receive data. The third example is best if you have the choice.

If you always send all three values and send them in the same order then you can identify them just by their order without needing to send a, b or c.

...R

Hi,
What are your 3 input signals to want to multiplex?
AC, DC, what frequency, PWM, Ampitude?

In what form do you want to send this multiplexed signal down the fibre, analog levels/signal or digital.

I think if you investigate fibre optic systems, you only need one fibre for duplex, half duplex operation.

Tom...... :slight_smile:

Hi,
Is this;

http://forum.arduino.cc/index.php?topic=336498.msg2319864#msg2319864

associated with this thread?

Tom..... :slight_smile:

I have no idea why you are keeping the project a secret and it is getting frustrating. I am not inclined to give my time for free if you are working on a commercial project.

Robin2, I am sorry if I am irritating you with my answers.
I think that our misunderstanding is that you think there is something after the tx and the rx but there is nothing! not motor, no washingmachine only one measure machine (oscilloscope) to see the signal.
I want to see if the signal pass.
My knowledge in communication is zero. I am Learning right now what is a modulation of a message ect. I know what fiber opitc are in the physical way. My education is in physics of particle, not arduino. But I want to learn so I take something that I know and something that I don't know.

The examples in serial input basics are simple and reliable ways to receive data. The third example is best if you have the choice.

I didnt see this tread. I am going to read it and learn it, thank you for your dedication.

If you always send all three values and send them in the same order then you can identify them just by their order without needing to send a, b or c.

here my dubt was that if the tx start to transmit before the rx is on the message can be messed up.
I guess there is a way to save or to understand when I need to start the transmission because the rx is
ready. I don't know, I am guessing right now.

thanks for your help!

Giulialiuyi:
my dubt was that if the tx start to transmit before the rx is on the message can be messed up.

The idea of the examples (especially the 3rd example) in serial input basics is to eliminate "messing up".

Obviously your receiving device needs to be "compatible" with the sending device. There are various ways that can happen. For example the sending device sends data whenever it wishes and then the receiving device must always be able to process a message fast enough so it is ready for the next one. Or the sending device will only send data after it receives a request from the receiving device. That puts the receiving device in control - which is generally simpler.

...R