This is my first Arduino project. I am making a weather station. I have a rain bucket attached to my Arduino Uno through the number 1 interrupt (Digital Pin 3). I have it connected to a pull-down resistor as well. My problem is that when I have the Arduino connected via my Raspberry Pi, the number increment on their own.
Got it. Didn't want to overload you guys too much.
Henry_Best:
Wnt2bsleepin:
This is my first Arduino project. I am making a weather station. I have a rain bucket attached to my Arduino Uno
Is that a 240V AC bucket or a 12V DC bucket? It runs off the 5v line from the Arduino
through the number 1 interrupt (Digital Pin 3).
Why are you using interupts? Are you trying to count each individual drop of rain? Yeah, that's how the rain bucket works. Every 5cm or so of rain, it tips and triggers a switch. I am keeping a count of the amount of tips every minute.
I have it connected to a pull-down resistor as well.
100Meg Ohms? It's a 10K resistor. I use the same resistance for every resistor.
My problem is that when I have the Arduino connected via my Raspberry Pi,
How is it connected to your Pi? USB? Wireless? WiFi? BlueTooth? Magic? It's connected to the Pi's USb port.
the number increment on their own.
I am stumped as to what is causing this.
Without your sketch and some clues, so is everyone else.
Here is my current sketch
int interrupt = 1;
float value = 0.21896551; //Need to find my own calibration value.
volatile int count = 0;
long debouncing_time = 500;
volatile unsigned long last_millis = 0;
float convert(){
return value * count;
}
void rainIncrement(){
if((long)(micros() - last_millis) >= debouncing_time * 1000){
count++;
last_millis = micros();
}
}
void setup(){
attachInterrupt(interrupt,rainIncrement,FALLING);
Serial.begin(9600);
}
void loop(){
Serial.print("Count: ");
Serial.print(count);
Serial.println();
Serial.print("Millimeters: " );
Serial.print(convert());
Serial.println();
delay(2000);
}
Sounds like a power supply issue to me. Perhaphs the pi is struggling to provide enough current, or the usb power is noisy or the voltage a bit low. Your detector is connected to a digital pin, but what else? 5V from the uno? Maybe a smoothing cap would help.10uF accross the uno's 5V and gnd pins.
Is the detector connected to the uno by a long cable? Does the problem go away if you connect a short cable? If so, try a stronger pull-down resistor like 4K7 or 1K.
You could try connecting the detector to an analog input and write a short sketch to continually display the analogRead value. See what you get with pi and laptop and whether the smoothing cap helps.
The cable for the sensor doesn't seem to change anything. I was thinking that it was power, so I added a power supply to the UNO's power jack. Does the UNO automatically select that as the power source as opposed to the USB port? I am still going to use the USB port for communication. I do have two more sensors running off of the 5V line.
Wnt2bsleepin:
Got it. Didn't want to overload you guys too much.
Henry_Best:
Wnt2bsleepin:
This is my first Arduino project. I am making a weather station. I have a rain bucket attached to my Arduino Uno
Is that a 240V AC bucket or a 12V DC bucket? It runs off the 5v line from the Arduino
So it's a 5V bucket. Where can I buy one of those?
through the number 1 interrupt (Digital Pin 3).
Why are you using interupts? Are you trying to count each individual drop of rain? Yeah, that's how the rain bucket works. Every 5cm or so of rain, it tips and triggers a switch.[/quote] So it's NOT the bucket that's connected to your arduino, it's a switch.
I am keeping a count of the amount of tips every minute.[/color]
Are you expecting your bucket to tip every microsecond? If not, then why use interupts?
I have it connected to a pull-down resistor as well.
100Meg Ohms? It's a 10K resistor. I use the same resistance for every resistor.
Why did I have to drag that information out of you?
My problem is that when I have the Arduino connected via my Raspberry Pi,
How is it connected to your Pi? USB? Wireless? WiFi? BlueTooth? Magic? It's connected to the Pi's USb port.
the number increment on their own.
I am stumped as to what is causing this.
Without your sketch and some clues, so is everyone else.
[/quote]
Here is my current sketch
int interrupt = 1;
float value = 0.21896551; //Need to find my own calibration value.
volatile int count = 0;
long debouncing_time = 500;
volatile unsigned long last_millis = 0;
Get rid of the interupt. Get rid of micros(), use millis() instead. Give last_micros a value of millis() instead of 0 in setup(). You haven't declared which pin your switch is on, or whether it's an input or an output. Watch the pin for a change of state. If bucket tips (within one minute), increment count, and after 1 minute do the maths and output result.
Your problems with the Pi are because, during an interupt, serial comms are effectively disabled.
Henry_Best:
Your problems with the Pi are because, during an interupt, serial comms are effectively disabled.
But is that not also true when the Arduino is connected to the laptop? Yet the OP's problem does not happen when connected to the laptop, only when connected to the pi. Thats why I suspect power issues.
The uno's product page says that it switches automatically between power sources (usb vs external), but it does not seem to say which is used if both are connected, or if it is even safe to connect both at the same time.
Henry_Best:
Your problems with the Pi are because, during an interupt, serial comms are effectively disabled.
But is that not also true when the Arduino is connected to the laptop? Yet the OP's problem does not happen when connected to the laptop, only when connected to the pi. Thats why I suspect power issues.
The uno's product page says that it switches automatically between power sources (usb vs external), but it does not seem to say which is used if both are connected, or if it is even safe to connect both at the same time.
Paul
If they are both connected, then the Arduino will use external power (from Vin or the power jack).
Have you tried monitoring the +5V pin with a multimeter?
Wnt2bsleepin:
I have not. What should I be looking for when I hook the multimeter up?
Well I would guess you would see if the voltage is any different between the Pi and Laptop.
It could be a grounding issue rather than a power supply issue. Are you sure the ground on your sensor is connected to the ground on the arduino and it is not going through the computer some how.
I have used the arduino and Pi together and not had any problems of this sort.
I tested everything, and the 5V line is outputting 5.01V under all power situations. I have a feeling that it is my wiring that is causing the errors, although it was seemingly working for a while.
Here is my current wiring diagram, although I am new and not very good at making them
I tried to make it so that Green is 5V, Yellow is ground and some data. Black is also Data. I have a black and red wire coming out of the Arduino to power the 5V and GND rails on the breadboard though.
I assume where it says V1 1V it is actually the 5V supply.
Apart from that I can't see anything obviously wrong, although I would use pull up resistors rather than pull down but it should still work.
The wind vane bit looks wrong however. I assume that it gives you a variable resistance, connected like that it is not going to give you anything but a maximum reading. You need a pull down on the analogue input pin as well. Use approximately the same value resistor as the middle resistance of the vane.
Here is a picture with the rewiring. The black area is where the wind vane is hooked up. 5V comes in from the resistor, and is split off to go to the A0 input and the other goes to the weather vane. Hopefully I didn't wreck this too bad.
Hey, that is the same ISR code I'm using in a project, and I am experiencing the same counting issue with the ISR on my LCD (most likely for a very different reason though). I hope that use of an ISR does not preclude the use of any serial comm or LCD, since ISR's disable those comms. I thought that would not matter as long as there was no comms happening during the ISR.
The Wind Vane is a variable resistor, I just didn't know how to represent that with the diagram I had.
A resistor with an arrow through it is the normal way of representing a variable resistor.
What was the result of your rewiring?
The counter is going up by itself now.
Here is a picture of the connector for the rain bucket. I measured 4.95V between the + and GND wire. I don't know how much of a difference this makes, but I haven't soldered the wires to the protoboard just yet. Here is what they look like on the back.
PaulRB:
I still think it would be worth trying a 10uF cap across the power rails on your breadboard.
I'll do that. Nothing wrong with having some smooth power.
Not soldering those wires could be causing problems. The stripboard tracks look tarnished also. Not sure why you started on the stripboard yet, as it looks like those connectors have pins that could have plugged into breadboard? Doesn't explain the different behavour of the curcuit when plugged into pi vs laptop though.
I think that of soldering is your problem it will cause intermittent operation and the fact that it appeares to work on a laptop is just a result of the diffrent mechanical strains thw wire are under.
You guys were correct about the connections being the issue. When I soldered everything together, it ended up working much better. I let it run overnight and there were no erroneous reports for the most part. However, out of the 12,000 entries that I acquired in that time period, one of them had an erroneous interrupt input. The device wasn't touched overnight. Could this have been caused by the power supply being interrupted? It is plugged into my computer right now, but I have no capacitors on there to smooth the flow.