Author Topic: Reading two sensor at the same time  (Read 3388 times)

tmsio

  • RFduino Jr. Member
  • **
  • Posts: 37
  • Karma: +0/-0
    • View Profile
Reading two sensor at the same time
« on: August 13, 2016, 08:43:11 AM »
Hi, i would u like to read two flow sensors from pin 2 and pin 3
This is my code
Code: [Select]
#include <RFduinoBLE.h>
volatile int wCnt = 0;
volatile int cCnt = 0;

int wISR (uint32_t ulPin) {
  wCnt++;
  return 0;
}

int cISR(uint32_t ulPin) {
  cCnt++;
  return 0;
}

void setup() {
  Serial.begin(9600);
  pinMode(2, INPUT);
  pinMode(3, INPUT);

  RFduino_pinWakeCallback(2, HIGH, wISR);
  RFduino_pinWakeCallback(3,  HIGH, cISR);
}

void loop() {

  RFduino_ULPDelay (1000); //loop 1 second interval
  {
    Serial.print(wCnt);
    Serial.print(' ');
    Serial.println(cCnt);
    wCnt = 0;
    cCnt = 0;
  }
}

Reading is good, only when all the sensors send signals, if one sensor stop sending the other stoping to.
Code: [Select]
0 0
0 0
0 0
0 0
0 0
2 3
20 2
15 2
0 0
0 0
0 0
0 0
0 0
0 0
10 2
13 12
31 12
25 18
24 22
25 26
29 21
12 46
16 35
17 33
12 35
12 29
26 23
22 27
23 17
20 22
9 28
9 28
9 29
18 22
22 20
26 28
43 59
42 33
43 31
33 21
21 11
12 4
0 1
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0
0 0

I attach my schema.

I have to manipulate my port?
If yes, can somone explain to me?

Thak You
Regards
« Last Edit: September 21, 2016, 09:21:07 AM by tmsio »

tmsio

  • RFduino Jr. Member
  • **
  • Posts: 37
  • Karma: +0/-0
    • View Profile
Re: Reading two sensor at the same time
« Reply #1 on: September 12, 2016, 05:43:16 AM »
Someone, can help me please?

Thank You

:)

tolson

  • Global Moderator
  • *****
  • Posts: 866
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: Reading two sensor at the same time
« Reply #2 on: September 12, 2016, 09:38:55 AM »
Hi tmsio,

It is hard to follow your resistor chain for your two sensors.
You've got R7,8 pullups. Where do the lines go from there up and to the left of your schematic? And down to the bottom of schematic.
You have R1,4 pulling down at same time.
You have R2,5 serial resistors.
Then you have R3,6 pullups again.
What is that all about?

What are your sensors?
I assume it is a 5V device and that is why you are trying to do level shifting with R2,R1 and R5,R4.
But then I assume they have open collector outputs and that is why you are using pullups R3,6 to 5V.

If they do have open collector outputs then they do not need pullups to 5V, just to 3.3V.  And therefore you don't need to attempt to do level shiftingl

But, I would really need to know what are your sensors to say for sure.

And for the lines going off the image to the upper left and down below, I assume those are I2C circuits. Those will not be compatible with what you are trying to do for your open collector sensors which I assume, based on your sketch, are pulsing type sensors.

« Last Edit: September 12, 2016, 09:42:24 AM by tolson »

tmsio

  • RFduino Jr. Member
  • **
  • Posts: 37
  • Karma: +0/-0
    • View Profile
Re: Reading two sensor at the same time
« Reply #3 on: September 13, 2016, 02:26:16 AM »
Hi Tolson, the sketch posted is only for testing two sensors reading.
I have a i2c fram module on pin 5 & 6 and work fine, i have not problem writing and reading data to the i2c.
I attached to te message, flow sensor s datasheet.

The board work fine with one sensor, i tested too much hours no problem detected.
But if i can improve it i ll be happy.

See the attach please.

If you need i can post the entire schema.... (this evening, i m at work now :))  )
Thank You

Regards
Emiliano
« Last Edit: September 13, 2016, 02:28:01 AM by tmsio »

tmsio

  • RFduino Jr. Member
  • **
  • Posts: 37
  • Karma: +0/-0
    • View Profile
Re: Reading two sensor at the same time
« Reply #4 on: September 13, 2016, 05:43:22 AM »
My entire schema....

There is one error in the code posted...

My RFduino_pinWakeCallback is ...

  RFduino_pinWakeCallback(2, LOW, wISR);
  RFduino_pinWakeCallback(3,  LOW, cISR);
It s correct?

Thank You.
Regards

Emiliano

« Last Edit: September 21, 2016, 09:21:46 AM by tmsio »

tolson

  • Global Moderator
  • *****
  • Posts: 866
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: Reading two sensor at the same time
« Reply #5 on: September 13, 2016, 09:29:16 AM »
And for the lines going off the image to the upper left and down below, I assume those are I2C circuits. Those will not be compatible with what you are trying to do for your open collector sensors which I assume, based on your sketch, are pulsing type sensors.

I mistakenly thought those I2C lines were on the same ports as your other sensors. Those are OK and will not interfere with your pulsing sensors. But, if you pulled up your sensors to 3v3 instead of 5v, you wouldn't need the extra resistors to do level shifting.

It would seem that if you have one sensor holding off and interfering with the other sensor, you might have a solder short between the two channels.



tmsio

  • RFduino Jr. Member
  • **
  • Posts: 37
  • Karma: +0/-0
    • View Profile
Re: Reading two sensor at the same time
« Reply #6 on: September 14, 2016, 11:33:21 AM »
Thank for your reply,  eliminated all the resistors ( R1, R2, R3,R4, R5, R6)   and i have activated internal pullup:

pinMode(SensorPin1, INPUT_PULLUP);
pinMode(SensorPin2, INPUT_PULLUP);
RFduino_pinWakeCallback(SensorPin1, HIGH, wISR);
RFduino_pinWakeCallback(SensorPin2, HIGH, cISR);

No solder short detected.
Sensors work fine separatly... but if i enabled all two "RFduino_pinWakeCallback" at the same time the output was  0  0

You can see the attached file.

Any idea?

regards


« Last Edit: September 21, 2016, 09:22:22 AM by tmsio »

tolson

  • Global Moderator
  • *****
  • Posts: 866
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: Reading two sensor at the same time
« Reply #7 on: September 14, 2016, 12:50:03 PM »
I don't know why it doesn't work for you then. Your sketch works for me.

Quote
0 0
0 3
2 1
2 5
6 4
6 0
8 0
0 0
0 0
0 7
0 9
0 6
0 4
3 3
5 1
3 3
5 4
5 4
0 0
0 0


tolson

  • Global Moderator
  • *****
  • Posts: 866
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: Reading two sensor at the same time
« Reply #8 on: September 14, 2016, 01:42:20 PM »
Hi tmsio,

Ugh! If I change your sketch like you implied with the triggers being LOW instead of HIGH, then I can reproduce what you say that neither counter counts.

I have no idea what that is about. Need to examine the RFduino/Simblee source code to see what BUG there may be.

Can anybody else reproduce this issue?

Hopefully, someone from RFdigital will chime in on this.

In the meantime, can you just trigger off HIGH. That works for me.


tolson

  • Global Moderator
  • *****
  • Posts: 866
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: Reading two sensor at the same time
« Reply #9 on: September 14, 2016, 02:01:50 PM »
So trying different combinations.

If both channels are set to trigger on HIGH, then both channels work as expected. Independently and together.

If both are set to trigger on LOW, then neither channels work independently. If pulsing both at same time then both counts same.

If one is set to trigger on LOW and the other on HIGH, then only the LOW trigger counts. The other stays 0.

Hmm!

tmsio

  • RFduino Jr. Member
  • **
  • Posts: 37
  • Karma: +0/-0
    • View Profile
Re: Reading two sensor at the same time
« Reply #10 on: September 14, 2016, 02:56:25 PM »
Exactly what appen to me
Im not a luky man :(((
I have too much board like this... Tomorrow i ll try another one....
Thank you Tolson.
Regards
« Last Edit: September 14, 2016, 02:58:32 PM by tmsio »

tolson

  • Global Moderator
  • *****
  • Posts: 866
  • Karma: +20/-0
    • View Profile
    • Thomas Olson Consulting
Re: Reading two sensor at the same time
« Reply #11 on: September 14, 2016, 03:00:27 PM »
So you are saying with your resistor network and pullups to 5V doesn't work when triggering both on HIGH instead of LOW.

tmsio

  • RFduino Jr. Member
  • **
  • Posts: 37
  • Karma: +0/-0
    • View Profile
Re: Reading two sensor at the same time
« Reply #12 on: September 14, 2016, 03:19:28 PM »
my output if i set both to HIGH:
Code: [Select]
0 0
3 0
4 1
0 0
0 0
0 0
4 9
8 14
2 12
5 10
0 2
0 0
0 0
0 0
4 0
17 10
19 16
21 7
23 7
18 0
54 0
13 1
4 0
0 0
10 10
13 9
5 10
7 6
1 6

It work only if all two sensor send data... if one stopping the other stoping to.


tmsio

  • RFduino Jr. Member
  • **
  • Posts: 37
  • Karma: +0/-0
    • View Profile
Re: Reading two sensor at the same time
« Reply #13 on: September 14, 2016, 03:22:01 PM »
SensorPin1 to HIGH
SensorPin2 To LOW
Code: [Select]
0 0
0 0
1 1
0 0
1 1
46 46
77 77
90 90
95 95
97 97
95 95
73 73
50 50
31 31
15 15
2 2
0 0
0 0


SensorPin1 to LOW
SensorPin2 To HIGH
Code: [Select]
6 0
65 0
85 0
89 0
73 0
41 29
34 28
24 22
12 12
1 1
0 0
6 6
46 46
35 35
32 32
22 22
5 5
0 0
0 0
0 0
0 0
0 0
5 3
53 41
34 26
27 25
15 10
6 0
0 0
35 24
33 27
26 24
16 16
4 4
[\CODE]

I don t undestand....   :(
« Last Edit: September 14, 2016, 03:25:09 PM by tmsio »

tmsio

  • RFduino Jr. Member
  • **
  • Posts: 37
  • Karma: +0/-0
    • View Profile
Re: Reading two sensor at the same time
« Reply #14 on: September 14, 2016, 03:50:29 PM »
Maybe the internal pullup?

If i set:
pinMode(SensorPin, INPUT);
pinMode(SensorPin2, INPUT_PULLUP);

only SensorPin2 work fine...
So if i change to:
pinMode(SensorPin, INPUT_PULLUP);
pinMode(SensorPin2, INPUT);

only SensorPin work fine...

If i set  both internal pullup to ON  the sensors work only if all two send data at the same time.

i try  external pullup... but i have the same issue...



 

anything