PWM input/output Due -

Hi,

I have a pwm signal with one positive leading and then 16 impulses:

Here you can see the size of impuls 1,3 and 4 is smaller and that is because the inputs are aktive

My goal is to have the arduino due listen on 6 input, and then sending the result to a raspberry pi.

Furthermore I need be able to output similar pwm signals to 9 outputs.

My code today is:

int inputpin0 = A0;


unsigned long duration;
int duration_channel[16]; 
int channel[16];
int checksum;
int checksum_old;


void setup()
{
pinMode(inputpin0, INPUT);

Serial.begin(9600);
}

void loop()
{
duration = pulseIn(inputpin0, HIGH);

if (duration > 3000) 
{
for (int x = 0; x < 16; x++)
{
duration_channel[x] = pulseIn(inputpin0, HIGH);
}

for (int x = 0; x < 16; x++)
{
if (duration_channel[x] > 250)
channel[x] = 0;
else
channel[x] = 1;
}

checksum_old = checksum;

checksum = 0;

for (int x = 0; x < 16; x++)
{
checksum = checksum + channel[x];
}

if (checksum != checksum_old)
{
for (int x = 0; x < 16; x++)
{  
Serial.print(inputpin0);
Serial.print("/");
Serial.print(x);
Serial.print("/");
Serial.print(channel[x]);
Serial.println();
}

}
} 
}

On my pi I listen to on the serial console for my print, and handle the actions with node.js.

But my code doesn't scale very well, can anyone point me in the correct direction?

Is the only way to solve this with 6 Arduino Gemma? connected to eatchother

Your signal is not a typical (library supported) PWM signal. You have to determine the start of a pulse train, then the length of each single pulse. It looks to me like your code does this already.

The checksum computation can become more "binary", by shifting the pulse values into a byte or int variable (bit count depending on the number of pulses per burst).

I'm not sure what you mean by "output similar pwm signals to 9 outputs".

apologies for reviving this topic...

Can this sketch be adapted to use multiple pwm inputs?
I want to connect multiple IHC input modules so I can get a value from each of them.
If someone could point me in the right direction.

What exactly are you trying to do with the digital input signals ? ( if that's a PWM signal, detect frequency and duty cycle ?)

If you make the receiver code a function, it can be called with any input pin and return the signal from that pin.

uint16_t reader(const byte inPin) { ... };

Original code lacks conversion of the bits into one value which can be returned by the function.