text:
Using XBee and OLED screens with Timer Interrupts
I have an Arduino board with a sensor, an OLED screen and an XBee module. I've setup the timer interrupts in timer1 to sample the sensor every one second.
I've done the following:

tried to update the OLED screen with the reading and it works.
tried sending the reading from inside loop over XBee and it works.
tried doing both of the above and the Arduino seems to shut down after a bit.
tried sending the reading from inside the timer interrupt handler and it doesn't work.

Are there limitations on what interrupt handlers can do that I'm not aware of? (Other than using time delays)
Source code
#include <XBee.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

XBee xbee = XBee();
ZBRxResponse response = ZBRxResponse();
ZBTxRequest sensorml_level_0_zbTx = ZBTxRequest(addr64, sensorml_payload_level_0,sizeof(sensorml_payload_level_0));
ZBTxRequest keepalive_level_0_zbTx = ZBTxRequest(addr64, keepalive_payload_level_0,sizeof(keepalive_payload_level_0));

union u_tag {
   uint8_t b[4];
   float fval;
}
u;

void setup() {
   display.begin(SSD1306_SWITCHCAPVCC);
   Serial.begin(9600);
   xbee.setSerial(Serial);
   noInterrupts();
   TCCR1A = 0;
   TCCR1B = 0;
   TCNT1  = 0;
   OCR1A = 62500;
   TCCR1B |= (1 << WGM12);
   TCCR1B |= (1 << CS12);
   TCCR1B |= (1 << CS10);
   TIMSK1 |= (1 << OCIE1A);
   interrupts();
}

ISR(TIMER1_COMPA_vect){
   reading =  analogRead(SENSORPIN);
   reading = (1023 / reading)  - 1;
   reading = SERIESRESISTOR / reading;
   reading = -0.15784 * reading + 305.17;
   sendObservation(reading,00);
}

void sendObservation(float value, int id){
   char idBuffer[] = "00";
   sprintf(idBuffer,"%02d",id);
   uint8_t frame[] = {'0','1','|','0','0','#','0','0','0','0'};
   frame[3] = idBuffer[0];
   frame[4] = idBuffer[1];
   u.fval = value;
   for (int i=6;i<10;i++){
      frame[i]=u.b[i-6];
   }
   ZBTxRequest request = ZBTxRequest(addr64, frame, sizeof(frame));
   xbee.send(request);
}

I skipped most variable declarations to keep the code short.

Just so you know, cross posting is not allowed.

Should I remove it then? Why is it not?

http://meta.stackexchange.com/a/64069/238586. The Stack Overflow one should be closed soon, so don't remove this one.

You say the arduino shuts down after a bit; How long is that? does anything get through before it stops responding? also, what is happening in loop during all this?

@BrettM I can't say for sure how long it takes. I will be able to on monday though. So I'll keep you posted.

I suspect send() is blocking.
XBee::send() calls _serial->flush() (see code). Serial.write() buffers data to be written, sets transmitting = true, clears TXC0 and enables the USART data register empty (DRE) interrupt. Bytes will be sent out when the DRE interrupt triggers. However, since you are currently in interrupt context, this will not happen until your ISR returns. flush() spins until TXC0 is set, but since the DRE interrupt never triggers, it spins infinitely. I am basing this on this code.

Yes, serial doesn't work in interrupts.


text:
Getting a random number for electronic dice
I am making a "Electronic Dice".
I have 7 LEDs to form the output, and this works fine.
My problem is getting a random result on the output.
int die_face = 1;

void loop()
{
    if (analogRead(BUTTON_PIN) == HIGH)
    {
        paintDieFace((die_face % 6) + 1);
    }

    die_face += 1;
}

The problem is, that roughly 95% of the time I get a 1.
Most of the time it's not a 1, it's a 2, or very rarely a 3.
I've tried paintDieFace() with millis()%6+1 too, but always get the same result.
When it's painted with random(1,7); I get 1, 2 or 3 100% of the time.
Is this some sort of timing issue?  I just don't get it.
Just to clarify - The paintDieFace() function is working perfectly, I'm logging the result to serial too.

This code is for a high-school student workshop, so it really needs to be kept simple.

I tested your code and I don't have this problem.

First of all, look at this line of code:
if (analogRead(BUTTON_PIN) == HIGH)

You probably want to use digitalRead(). Note that it is okay to use digitalRead() on an analog pin, just make sure to use the right pin number (A0, etc.)
From the Arduino Source:
#define HIGH 0x1
#define LOW  0x0

(Ignore the 0x, that is just specifying that it's hexadecimal. However, 0 and 1 are the same in any base)
So, really, this function is only activated when analogRead() returns 1, which could possibly cause a problem later if it doesn't check at the right time. Note: now is a good time to remind you about debouncing...
For your actual code, since you want it to be simple, I suggest you forget that code that you wrote. Arduino has a built in random library, which works unless you have some special need for a random number.
Your final code should look like something like this in the end:
void loop() {
    if (analogRead(BUTTON_PIN) == HIGH) {
        paintDieFace(random(1, 6);
    }
}

Note that you should also use this code here in your setup (make sure that analog pin is floating: nothing should be attached to it):
randomSeed(analogRead(A1));

It actually isn't random, just pseudo-random. That means it relies on an equation to generate what seem to be random numbers. Because there has to be a default value of where the equation starts (the seed), it will repeat the same numbers every time you run it.
If you're wondering how this works, know that the analog pin is affected by a ton of external factors when there is no other electric signal attached.

De...BOUNCING, not denouncing. 8)

@TDHofstetter thanks for that catch! My finger must've slipped...

Ah I didn't see the analogRead();  Of course I meant digitalRead().  Thanks for the heads-up.

for a HS project it doesn't matter, but in terms of security, randomSeed(analogRead(A1)); is terrible. random() is deterministic, and it's not hard to try all 1024 sequences. If you do that, run random() in the loop so that it's unpredictable how many times it's been called, and thus unpredictable in terms of the next result. randomSeed((analogRead(A1)+1)*millis()*micros()*(analogRead(A1)+1)) is better

@dandavis two issues with that: a) its stronger for sure, but still incredibly weak. You shouldn't be using a pseudorandom generator if it needs to be secure end of discussion. B) since seeding is traditionally at the start of the program, millis and micros are going to be very similar each time, if not the exact same. Of course, seeding when the button was first pressed may overcome this partially, but there are ways to overcome this (hold down the button before plugging it in so the first iteration of the loop reads HIGH, advanced cameras and timers, etc.)

@AnonymousPenguin: good point about the timing. i'm used to 8266s, where you can put that after the wifi connect part, which takes 1-3 seconds... a prior delay(analogRead(A0)%250) adds cheap entropy from micros(). an empty wire connected only to A0 collects noise and widens the sample range considerably, might be worth noting in the answer. "security" was probably the wrong word; i'm just suggesting  low-effort/cost ways to make a game (much) harder to cheat using an app...

@dandavis very true, although I'm sure the teacher would be pleased if the student did the work to reverse engineer the random functions and build a separate program that calculated sequences with the random seed and matched a sequence to the appropriate seed. :)

I've had better success with this version.
I did not work out the problem with the first version.  Although I did find the rear legs of the push-button were lighting up a LED - but only when pushed.  As the result is only displayed when the button is not pushed, I don't see how it could make a difference.
I believe the modulus of 6 is a problem, perhaps this does really output more ones than anything else.  Obviously looping the dice_number variable 1->6 removes the necessity for it.
#define LEDS_34_PIN 2  // Output pins used
#define LEDS_16_PIN 3
#define LEDS_25_PIN 4
#define LED_7_PIN   5

#define BUTTON_PIN  6  // Input

unsigned char dice_number  = 0;     // this is what will be shown on the die face

void setup()
{
    // Tell the Arduino we're writing to some pins
    pinMode(LEDS_34_PIN, OUTPUT);
    pinMode(LEDS_16_PIN, OUTPUT);
    pinMode(LEDS_25_PIN, OUTPUT);
    pinMode(LED_7_PIN,   OUTPUT);

    // ... and reading a button
    pinMode(BUTTON_PIN, INPUT);

    // Do a testing-dance first
    for (int i=1; i<=6; i++)
    {
        paintDieFace(i);
        delay(500);
    }
    paintDieFace(0);

}

// Show a dice-dot-style number
// based on LEDs laid out like
//    [1]     [4]
//    [2] [7] [5]
//    [3]     [6]
void paintDieFace(unsigned char number)
{
    // Turn off all LEDs
    digitalWrite(LEDS_34_PIN, LOW);
    digitalWrite(LEDS_16_PIN, LOW);
    digitalWrite(LEDS_25_PIN, LOW);
    digitalWrite(LED_7_PIN,   LOW);

    if (number == 1 || number == 3 || number == 5 || number > 6)
    {
        digitalWrite(LED_7_PIN, HIGH);
    }
    if (number >= 2)
    {
        // LEDs 3 & 4 are on for all numbers greater-than 1
        digitalWrite(LEDS_34_PIN, HIGH);
    }
    if (number >= 4)
    {
        // LEDs 1 & 6 are on for 4, 5 and 6
        digitalWrite(LEDS_16_PIN, HIGH);
    }
    if (number >= 6)
    {
        // LEDs 2 & 5 are only on for 6 (or more)
        digitalWrite(LEDS_25_PIN, HIGH);
    }
}

void loop()
{
    int button_pushed = digitalRead(BUTTON_PIN);
    if (button_pushed == HIGH)
    {
        // The user has pushed the button, change the die reading
        paintDieFace(dice_number);
        delay(20);  // flicker the LEDs if button held in
    }

    dice_number += 1;
    if (dice_number == 7)
        dice_number = 1;
}

Just as a sidenote. Remember that you need a pull-down resistor on the button pin, to get reliable data from digitalRead(BUTTON_PIN).

@Gerben: it's cheaper/easier to just set the pin mode to INPUT_PULLUP and hook button to GND...

source: Stack Exchange

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/

sort: votes


text:
Why am I getting "fatal error: SoftwareSerial.h: No such file or directory"
I downloaded the Adafruit_GPS library from Adafruit and I'm trying to compile the example code (due_parsing) but I can't seem to get past this silly error:
In file included from due_parsing.ino:15:

/Users/haddad/Documents/Arduino/libraries/Adafruit_GPS/Adafruit_GPS.h:24: fatal error: SoftwareSerial.h: No such file or directory
compilation terminated.

This is the location in the example Arduino Sketch where SoftwareSerial.h is mentioned:
#ifdef __AVR__
  #include <SoftwareSerial.h>
#endif

I noticed it's around an ifdef guard, so shouldn't it not even matter that I don't have this library?
I went into the .h and .cpp files and commented out the where it called SoftwareSerial.h, but I'm still getting that above error.
Does anybody know how to fix this?
I am using Arduino IDE v1.5.5

Update:
I didn't put the library in the library direct on my mac but I'm now getting tons of errors, all the errors are with SoftwareSerial.cpp. Is anybody else having similar issues when you go to compile?

You mention you are using a DUE, do you use Arduino IDE 1.5 with it?

yessir, Arduino IDE v1.5.5

What are the errors that you are getting after installing the library?

the errors were all in regards to SoftwareSerial.cpp, but after commenting out those ifdef guards, it worked...for now anyway

According to your comment:

after commenting out those ifdef guards, it worked

I would say that is a bug in the Adafruit_GPS library.
As a matter of fact, the DUE is not using the AVR architecture (it uses ARM), that explains why #ifdef __AVR__ in Adafruit_GPS.h never passes; but then something else should be done specifically for the DUE (missing #else or #elif).
After checking on github, there is an issue open for that; unfortunately, as of April 2014, it has not moved for 10 months.
Your best guess would be to go there and try to "reactivate" this issue.

Yes, you're right. That library and software for the Due in general seems to be in continual development, not as mature as the stuff out for the AVR boards out there

this is a "bug" in the arduino IDE pre-compilation process.
If you turn on the compiling verbositi in thge precerences menu, you will see that arduino has copied all file (with a rater "stupid" code that just look for include) into a temp folder (wiring lib are not copied, but the below still aplly). Until here, ugly but still fine.
Then, it will -force- compilation of every "included" file, one by one, the facto bypassing the #ifdef.. and this is why you get that problem.
Solution is to heavy change the ide so it will force compilation only in the main, and let the compiler include and compile needed libraries.
I still have no idea why every file is forced, but a change like this is really heavy and break-old-code prone..
Newest IDE to bypass this problem (and also some other problem, like depeency) use a "config" file that will tell the IDE if use the AVR or ARM or x86 library, probabily this file is missing and the ide see te lib as only AVR by default.
Double check if it is really usable on DUE

So I went into the interface file (.h) and removed all references to AVR and then went into (.cpp) and removed all references to AVR there as well. It now seems to be working, although sometimes it says "Not supported Architecture ARM" during compilation...very weird

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/3.0/


text:
Is it possible to connect 2 ultra sonic sensors to 1 arduino?
I am currently using the Arduino Pro Micro board and I want to connect 2 ultrasonic sensors to 1 board, whilst knowing which sensor is being triggered. The sensor I am using is a HC-SR04 Ultrasonic sensor.
Please help me thank you :)

Have a look at the newping library.

Yes, you can, as long as you serialize the send/receive pulse cycles, to avoid interferences.
basically, you attach the Trig/Echo lines to a different pair of pins, then do the reading on one sensor, then do the reading on the other.

Sorry i'm really really new and noob at this, so i really dont know what all these mean

What you need to do, for each sensor, is the following:

choose a GPIO that will drive the trigger line (make sure it is not a pin you are already planning to use, ex: TX/RX )
choose a pin that will receive the information from the Echo line, ideally using an interrupt driven implementation, instead of polling. The 328P supports exactly 2 independent interrupt lines: INT0 and INT1, so you could use one of them for each sensor.
have a time base and use it to time-stamp the Trig and Echo lines

Example for one sensor (for 2 just do the same and keep in mind that there might be interferences, like the OP said):

toggle the Trig line for the required duration (strobe)and save it
read the time
wait for the interrupt to occur (you can do other things in the meanwhile)
when the interrupt occurs, read again the time
subtract the timestamp taken after toggling Trig from the timestamp taken after the Echo interrupt
convert the delta time from the previous point into a linear measure, using the constant provided by the datasheet of the sensor

“The 328P supports exactly 2 independent interrupt lines: INT0 and INT1” is rather misleading.  Pin change interrupts suitable for sensing Echo lines are supported on about two dozen pins (ie on all pins except for Vcc, Gnd, ARef, AVcc, ADC6, ADC7)

@jwpat7 I think my comment is correct: it does indeed support 2 independent interrupt lines. What you mention is ORed within a port. Yes, one might choose only one pin per port and sort of simulate more independent interrupt sources, but it is bordeline a design trick and requires additional programming for the port masking. Given the level of knowledge implied by the question, it seemed more effective to give the answer that is simpler to implement and maps also to other architectures that do not have the concept of port.


text:
Setting serial number on CH340 USB-Serial device
Reading http://playground.arduino.cc/Linux/Udev there appears to be a way to write out to a FTDI USB-Serial EEPROM to set a given SerialNumber, allowing you to identify a given nano/other arduino to handle it specifically in UDEV.
I have a nano-style boad with a QinHeng Electronics HL-340 USB-Serial adapter, which clearly isn't an FTDI chip, and the FTDI programmer therefore doesn't work. Does anyone know of an alternative utility/where I can find information to do the same with this chip?
Currently the device identifies itself with:
[ 6850.608080] usb 2-1.2: new full-speed USB device number 7 using ehci-pci
[ 6850.701496] usb 2-1.2: New USB device found, idVendor=1a86, idProduct=7523
[ 6850.701505] usb 2-1.2: New USB device strings: Mfr=0, Product=2, SerialNumber=0
[ 6850.701510] usb 2-1.2: Product: USB2.0-Serial
[ 6850.702201] ch341 2-1.2:1.0: ch341-uart converter detected
[ 6850.704210] usb 2-1.2: ch341-uart converter now attached to ttyUSB0

Which is essentially useless, as I can't identify the given board attached (when I attach two, their details are the same).

possible duplicate of In Linux, how to identify multiple Arduinos connected over USB?

Unfortunately, this isn't really an answer to either: the question (as it doesn't answer whether there is a way to assign a new serial number as one can do for FTDI chips), or resolve the issue (as the udev serial for all these boards, like the Leonardo, is 0, therefore udev can't distinguish between multiple boards attached to the same computer.

My link is to my answer which talks about creating udev rules for each device.

If you can read chinese(I can't) this page might help: http://wch.cn/products.php?page=procontent&id=40

Yeah - I've seen that, but unfortunately, suffer the same linguistic issue!

Unfortunately @Phil Vallone the issue is that there is no unique serial to identify the device via udev. In order to detect and identify a unique device, you need something unique to differentiate them. These devices have the same iSerial, so you can't diff them on that, and they share the same Product and Vendor IDs - so there isn't a differentiator ... Thanks for your help, unfortunately it doesn't fix this issue!

Here's the english data sheet: http://www.wch-ic.com/downloads/file/79.html

There is no storage on the CH340 and family of UARTs where you could put a unique ID. This is also a problem for the PL2303 type. I have been trying to find solutions for this problem. First and easiest is the position of the device on the USB bus. It will be unique for each device. If you're using linux you can find each device under /dev/serial/by-path . There is also a /dev/serial/by-id but there will only be one entry there for this device because it shows the last one connected. FTDI chips will each have unique entries here. Cheap chips won't, but they each have an entry under /dev/serial/by-path.
This position, and the device names, should persist across reboots. If you have a lot of changes to your USB devices, plug all the CH340 devices into the same hub, then plug that in. The devices will enumerate in the order that they are plugged in to the hub. This one-hub trick should work for MacOS and windows too, they should come up in the same order.
Harder method- udev rules.
For devices with a unique ID such as FTDI you can set a udev rule that sees it's serial number and then creates a symlink to that device, it's straightforward.
For devices with the same or no Serial number, it's a lot more complex. I created a udev rule that looks like this:
SUBSYSTEM=="tty", ATTRS{product}=="USB2.0-Serial", RUN+="/usr/local/bin/cheapduino.py %k", ATTRS{idVendor}=="1a86", ATTRS{idProduct}=="7523", ENV{ID_MM_DEVICE_IGNORE}="1"
when the device matches the product and vendor of the cheap arduino, it runs the script 'cheapduino.py' with the device as argument, for instance
cheapduino.py ttyUSB0
Then the cheapduino script connects by serial to the device and sends the string 'ID' and the software on the device responds DEVID=THX1138 or whatever. The script then creates a symlink /dev/THX1138 that points to /dev/ttyUSB0
There are a lot of drawbacks to this method. The script must time out if the software on the cheapduino doesn't answer. Also this is not using the SYMLINK function of udev so it won't clean up dead links on disconnect, but it will overwrite them on reconnect. All of your cheapduinos must have this functionality in their software, with different device IDs set. They all must use the same baud rate as the script unless you want to write a very complex script that takes a long time. Finally, this method works much better at low baud rate than at high baud rate, which for timing reasons may not succeed every time. (cheapduinos are cheap!) 9600 works much better than 115200 which works after several tries. But since all your CH340 arduinos must be the same speed with this method, you can only go as slow as your fastest device.
This method DOES work though, and it's what I'm using because I bought way too many of these cheap things.
In the end, buy genuine Arduinos or at least ones with FTDI chips or something else that sends a unique device ID.
=Rich

If what you want is to tell apart 2 devices that are basically identical, you have 2 ways:

always plug them in the same ports and use the USB tree to differentiate them
create an handshake protocol, where each Arduino uses a code that you have previously stored in their respective EEPROMs. It might even be possible to write a helper function for UDEV, so that the helper function does the handshake and tells UDEV the serial that is stored in each EEPROM. That would allow to write a UDEV rule for your devices.

I hate to say it, but the answer is no, there is not way to uniquely identify multiple 340 based usb-serial converters.
I have the same problem, where I have multiple (4+) usb-serial converters, any one could be plugged into any port, and they were purchased at the same time and therefore are identical in every way (including iSerial of 0).
Basically, if I move things around, I have to connect by hand to see what's attached, peruse dmesg output, etc. It's a big pain.
tom

CH340B (not the G) has an EEPROM where you can store the serialnumber.
https://www.mpja.com/download/35227cpdata.pdf
There is a windows tool as well to read/write it:
http://www.downxia.com/downinfo/196126.html
Will try to install and see how the G version behaves...

Can you tell me where to click on that Chinese stuff to download that tool? I found some links to a RAR file but they time out.

Put a Maxim DS18S20 on your board, each has a unique serial number and are very inexpensive.  There are a lot of software examples on the internet using this device.  You could dead-bug it to the nano.  to operate it needs a 4.7K resister connected to +5 and a ground connection. You can connect both the 5V and Ground connections of the device to ground.  It would be easy to dead bug this to the nano then by simple communication via one pin you can get the serial number. There are several packages available.  With care you could use an input pin, read the serial and save it for future use.  When it Inits it will do this again. Just be sure the input is not driven low during the init process.
Good Luck,
Gil

Once you aren't solving the problem in the USB serial, but rather with something which requires the cooperation of the processor on the board to discover, you might as well just modify the bootloader to contain a serial number readable both there and in an application program (ie "sketch")

What a nonsense. The DS18S20 is a digital thermometer!

Yes it is a thermometer; Yes it has a unique serial number that does not require changing the code or eeprom on each board.  Inexpensive and simple. Drawback the micro has to respond. It will work with out changing IDE or any firmware etc however it requires a pin which can be worked around with a mux if needed.

Here is a software tool that I wrote which can be used to update serial number of WinChip Head CH340B. This will be useful for some one who wants to connect multiple CH340B Virtual COM Port devices to their Windows PC.
You can get the source code of this tool from the following github repository.
https://github.com/senthilnathant/tools-ch340b-configuration

Unfortunately the more-commonly used chip is the CH340G, which appears to not have storage for a serial number.

Yes, that's right.

does that source code work with the WCH9102 ?

all_licenses: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Not able to send SMS to Mobile using GSM900A and Arduino Uno
I tried the code shown below (found here)
void setup()
{
  Serial.begin(9600);  //Baud rate of the GSM/GPRS Module
  Serial.print("\r");
  delay(1000);
  Serial.print("AT+CMGF=1\r");
  delay(1000);
  Serial.print("AT+CMGS=\"+919449835011\"\r");    //Number to which you want to send the sms
  delay(1000);
  Serial.print("Test SMS -Jay\r");   //The text of the message to be sent
  delay(1000);
  Serial.write(0x1A);
  delay(1000);
}
void loop()
{
}

I interfaced my GSM SIM900A module to the Arduino UNO (connections - GSM Tx to Arduino Rx, GSM Rx to Arduino Tx, GSM provided with supply (12V) using external adapter, GSM gnd to Arduino gnd).
I dumped the code into Arduino and then opened the Arduino IDE serial terminal. In the serial terminal, I get AT+CMGF=1AT+CMGS="+919449835011"Test SMS -Jay\r being displayed and I am not receiving any sms to my phone. I am not sure if its a problem with the code or connections.

looks like you should be using Serial.begin(2400);
also, I'm assuming your sms phone number isn't actually 919449835011 and that that's not actually the number you used in your code

Yes that is the number i used in the code, +91 is country code and the rest is the number to which i want to send the sms. I will change the baud rate to 2400 and check.

Sorry for the delayed response. This problem was fixed long ago and like you said, I had to just change the baud rate. Thank you.


text:
Do Arduinos meet military standards?
Do Arduinos meet military standards?
If not, where does it fall short? Is it something internal to the chip which might be corrected via external circuit? How could I evaluate the potential of a device I'm building?

It depends on the application. For something like a rechargeable torch, Arduino might exceed the specifications. For a weapons system, NEVER (and this is one of the specific prohibitions in the license agreement - see section 1.5 note: link currently broken). You also have to consider that there's literally thousands of armies in the world and they all have different standards. What might be acceptable to one might not be acceptable to another. Hamas uses rockets I wouldn't consider safe for anything, and they use them effectively - the Qassam rocket would never meet US military standards but it works great for Hamas.
US military standards are so complicated, nobody can answer this question for you. You're gonna need an army of lawyers to do that... here's a link to some documents to get started though...
Please note there are multiple standards which may apply to a given device. For example, you will see common off the shelf desktop computers (running Windows) used for some things in a military installation, but they could never be used to control a vehicle. Bottom line - you're gonna need a lawyer to navigate this. (You are better off selling your devices directly to soldiers, if you can live with that if it fails.)
http://www.dsp.dla.mil/ - Terrible site - get used to that if you want to deal with govs.
OH BTW... if you want to use Arduino to prototype something, and you plan to remove "Arduino" later, running straight from the ATMega - that's the whole point of Arduino! It is a prototyping system, not intended to be used wholly in products. Arduino is very little more than a break-out board for the ATMega processor, a robust (kinda) power supply, and a runtime environment in C++.

"... an army of lawyers ..." BADUM-TSH!

@Jasmine, that link didn't get me to any license agreement.  Can you please update the link to something that shows the section you are talking about.

Ugh, it seems they have updated the site, and the hardware license agreement is something I can't find any more. I've made as much effort as I want to make, but if anyone finds it, just reply here and I'll update the answer. Sorry about that.

Your question is broad. My first reaction is to say No.  But in order to be very accurate (or fair), your should find the application standard. Military has an extensive library of standards ranging from manufacturing and testing.  Therefore, take a look at the standard regulating your application. Only after this assessment, the question of whether Arduino will suffice a military application will be accurately answered.

Defiantly not. If you wanted to use it for very early prototyping then I think it would be fine. However, it really depends on the use because lets admit it Adriuno boards don't have huge amounts of processing power and are somewhat limited to capabilities.

Not every application requires a quad-core 1.8GHz CPU.

@IgnacioVazquez-Abrams, performance isn't the issue. The main issue is ruggedness and hardening against things like EMP. Stuff that is rated for the military needs to be able to survive being dragged behind a humvee through a swamp for 5 miles. (Ok, I exaggerate, but that's the general idea.)

@DuncanC: Sure, but that's completely independent of what this answer mentioned.

Do Arduinos meet military standards?

it meets some military standards but fails the others.

It is not mil spec. Making something comply with milspec is a big, complex subject. (A subject I know very little about.)

In Military.. everything has to do with standard military specifications.


text:
Turn Arduino on only by double tapping switch?
I don't have much experience with electronics. I was wondering if it is possible to create a push button switch, which will turn on the device only if it is tapped twice in quick succession?
If it is tapped only once, then the device should behave as if nothing happened (i.e. tapping the switch again after a specified duration should have no effect).

Create something which uses an interrupt to wake from sleep on a single button press, and return to sleep if a second is not detected within a short window of time.

You can use something like the ATtiny25/45/85 then have a button cell battery to power it, make it a sleeper that listens to the button, and when clicked it activates the Arduino.
The Arduino is then turned on keeping a capacitor alive holding a transistor active, then add another button that drains the capacitor, thus closing the transistor and turning the Arduino off. Or you can program the ATtiny to drain the capacitor if the button is held down.
A button cell on an ATtiny in sleepmode should last around a year or so.
Just some information to get you going further:
http://playground.arduino.cc/Learning/arduinoSleepCode : The sleeper code, it is power saving using interrupts.
http://www.instructables.com/id/Program-an-ATtiny-with-Arduino/ : How to burn an ATtiny using Arduino. Fairly simple, did it myself a few times.

The ATtiny isn't necessarily needed - it should be possible to get either the ATmega328p or the 16u2 to do the low-power wakeup role, and keep the other asleep until needed.

Yes, it would be the same principle, but he specifficly stated that the arduino would be turned off and then turned on, and not put in some kind of sleep mode. So thats what i went with.
Ofcause i could have elaborated other posibilities, but since the feedback from the questioneer was lacking i didn't think i should spend more time on this question :)

Thanks! I don't know what any of this means. But i will try it!

@John feel free to ask questions i have a little experience in the ATTiny's mostly blink examples and sirens made of used 8ohms speakers. But a bit more in burning the chip, it can be a bit tricky but follow the guides and it will get you far!


text:
Functions with string parameters
Inside my main loop there is this string:
String string1;

I have a function that will take string1 as parameter, and use it to send this string as SMS.
sendSMS(string1);

This is the sendSMS() function (without parameters):
void sendSMS()
{ sms.beginSMS(remoteNumber);
  sms.print(finalstr);
  sms.endSMS();
  lcd.setCursor(0, 0);
  lcd.print("Message sent!");
  delay(10000);
}

My questions are:

How do I put the string input parameter in sendSMS?
Do I also need to use a function prototype for sendSMS()? (so that it appears three times, 1 in the prototype, 1 in the declaration and one in the call). Or I don't need to use function prototype before the main loop()?

Just change
void sendSMS()

to
void sendSMS(const String& thisIsAString)

You can then access the parameter inside the function with thisIsAString.
No, you do not need a prototype.

I would rather advise to pass the String by reference, to avoid additional code to be executed for nothing (copy-constructor, destructor): void sendSMS(String& thisIsAString) or even better, a const reference, if the string argument is not to be modified by the function: void sendSMS(const String& thisIsAString)

I'd say to never use String again. When code gets bigger and memory usage will be critical you'll hit a dead-end. I know it's more convenient, but give char arrays a shot. Something like:
bool sendSMS(int remoteNumber, char *finalstr){
  bool isFinished = 0;
  sms.beginSMS(remoteNumber);
  for (int i=0;i<sizeof(finalstr);i++){
      sms.print(finalstr);
  }
  sms.endSMS();
  lcd.setCursor(0, 0);
  lcd.print("Message sent!");
  delay(10000);
  isFinished = 1;
  return isFinished;
}

I changed the function to bool. It means that you can use it inside an if statement, where you would want it completed before continuing with your code.
You will need to allocate memory yourself for the array; declare it like this:
char stringArray[33] = {'\0'};

Here, I allocate 32 bytes for data and one additional byte for the character that means "end of string" (it's that \0).

You can change
void sendSMS()
to
void sendSMS(String myinputstring)
you can use
myinputstring in your code.

That's just a repeat of the other answer.

Not a repetition of the other answer. This one is by copy, not by reference. Prefer the other answer to avoid copying of the object.


text:
ICP Accelometer Arduino
I need to connect piezoelectric accelerometer to Arduino. Precisely, it's this one: http://www.pcb.com/Products.aspx?m=352C34
Specs show that it generates 100 mV/g, but when I connected it between ground and analog input with 1M pulldown resistor, analog input stays at 0.
Arduino analog input resolution and accuracy is absolutely fine for now.
Could someone point me to right direction in connecting this kind of sensor to Arduino?

How do you provide power to the device?

Can you show your exact circuit?

That device appears to both require a non-trivial interface circuit, and to be intended for measuring vibration, not steady accelerations such as gravity.  It has a minimum frequency of one cycle every 2-3 seconds.  Also note the series capacitor in their sample setup.


text:
Can a 433mhz receiver receive data from a 433mhz tag/fob?
If I use a 433mhz receiver on an Arduino Nano, will it detect a 433mhz tag? I'm not talking about the transmitter that is shown below but a tag/key fob.

Example of 433mhz tag

Nothing in the receiver can power the fob.

@IgnacioVazquez-Abrams the fob has its own power from a battery.

It might be possible to hack the patented protocol :) http://cdn2.hubspot.net/hub/186315/file-2401365665-pdf/docs/Assets/m163-i_tech_spec_sheet.pdf

That should be possible. You'd have to reverse engineer the encoding and protocol though.


text:
Due timer update
I want to test a BPM counter as a part of larger project rewriting code for a groovesizer synth. In essence i want to read a pot for updating BPM tempo, and then have a LED blink that tempo, displaying BPM value on an LCD screen.
I am using the DueTimer library. The code for reading pot value, LED blinking and showing the BPM value in an LCD display works fine. However, i am stuck figuring out how to update the ISR timer frequency continously. I can only have the LED blink in the tempo value initialized in setup().
I tried adding the Timer1.setPeriod() to the function reading pot value, to no effect:
pot[4] = (analogRead(i) >> 2) + 30 ; // we use >> 2 to reduce the range from 0 - 1023 to 0 - 255 and add 30 for bpm value
bpm = pot[4];
Timer1.setPeriod(60000000 / bpm / 2);

Putting the same Timer1.setPeriod(bpm) in the main loop didn't work either:
void loop() {
checkSwitches(); // gets the current state of the buttons - defined in BUTTONS
getPots(); // update the pot values - defined in POTS
Timer1.setPeriod(60000000 / bpm / 2);
updateDisplay();
}

Not sure where to go from here. (I'm a total beginner in case it isn't obvious).

Do you maybe have to stop the timer peripheral to be able to update it? Can you call Timer1.stop()  and replace your Timer1.setPeriod call with Timer1.start(60000000 / bpm / 2)?

Good idea! Tried it, but nothing changed...

I think that each time you go through loop(), the Timer1.setPeriod() calls Timer1.setFrequency() and re-initializes the timer.  Does loop() happen more often than 1/285th of a second?

@DaveX so essentially, the problem could be that the timer is constantly reinitialized within the loop function? Then i suppose a solution would be to keep the timer clock constant and recalculate bpm in a separate function counting microseconds?

Can you try to maybe create a global variable int oldBpm;, and only do a TImer1.setPeriod() with a oldBpm = bpm; if oldBpm != bpm? (i.e. only update timer period if new BPM value is different from current one)

Given the slow time scale, you could just handle the timing in software, with either millis() or micros(). You could then very easily update the frequency in a phase-continuous manner.

@EdgarBonet Thanks a lot, you're right. I believe i was overcomplicating things! It's working as intended now.

license: Creative Commons - Attribution Share-Alike - https://creativecommons.org/licenses/by-sa/4.0/


text:
Using modulo for negative values
I want to wrap a random number using modulo, so that values exceeding 11 starts over from 0 and greater. However, i would also like numbers less than 0 to dividend 11 or less.
Please correct me if i'm wrong, but as far as i can tell the modulo operator only dividends values exceeding the divisor. If so, how can i write code that also dividends values less than 0?

One crude way:
while (x > 11) x -= 11;
while (x < 0) x += 11;

The first could be replaced with a modulo operation.

Simply use modulo
#include <stdio.h>

int main(){
   for (int i = -23;i<23;i++) printf("%d    %d\n",i,i%11);
   return 0;
}

all modern C variants should work the same way https://en.wikipedia.org/wiki/Modulo_operation (result have same sign as divident):
-23 -1
-22 0
-21 -10
-20 -9
-19 -8
-18 -7
-17 -6
-16 -5
-15 -4
-14 -3
-13 -2
-12 -1
-11 0
-10 -10
-9  -9
-8  -8
-7  -7
-6  -6
-5  -5
-4  -4
-3  -3
-2  -2
-1  -1
0   0
1   1
2   2
3   3
4   4
5   5
6   6
7   7
8   8
9   9
10  10
11  0
12  1
13  2
14  3
15  4
16  5
17  6
18  7
19  8
20  9
21  10
22  0

for new formulation of request fixed by @Gerben suggestion
if you want monotonic 0..10 sequencies, add 11, if result is negative :
#include <stdio.h>

int main(){
for (int i = -23;i<23;i++)
    {
    int x= i%11 ;
    x += x<0?11:0;
    printf("    %d  %d\n",i,x);
    };
return 0;
}

results in
-23 10
-22 0
-21 1
-20 2
-19 3
-18 4
-17 5
-16 6
-15 7
-14 8
-13 9
-12 10
-11 0
-10 1
-9  2
-8  3
-7  4
-6  5
-5  6
-4  7
-3  8
-2  9
-1  10
0   0
1   1
2   2
3   3
4   4
5   5
6   6
7   7
8   8
9   9
10  10
11  0
12  1
13  2
14  3
15  4
16  5
17  6
18  7
19  8
20  9
21  10
22  0

Thanks for your feedback. However, this seems to produce a different result than what i asked for.

If the value is negative, add 11.

fixed by @Gerben suggestion


text:
Function, struct or class?
I am trying to learn more about arduino programming, and recently i've written functions for randomizing and then modifying a single array. Now i'd like to do the same for four individual arrays. This is where i'm getting stuck. My questions:
Am i right to assume that it's not possible calling a function for multiple individual arrays?
Perhaps a separate question, but if a class or struct would be more suitable for multiple instances, what are the major differences worth considering to choose the right approach?

Thanks for your clarification! Just to make sure we're on the same page: by individual arrays i mean that the four arrays all have different elements (If i'm not mistaken this implies individually declared arrays, no?). I've tried to read up on this, but i can't seem to come up with a solution where the same function returns four separately declared arrays, each with different elements. I'd be happy for a suggestion that points me in the right direction!

Are you trying to use the same function for different arrays at different times, or are you trying to use a function that handles four different arrays at the same time?
If the former, you'd write something like
void myfunc( T *arr, size_t size ) // where T is the type of the array
{
  for ( size_t i = 0; i < size; i++ )
    arr[i] = some_new_value();
}

then call it for each array:
T arr1[N];  // where T is int, float, double, whatever
T arr2[M];
T arr3[O];
T arr4[P];

myFunc( arr1, N );
myFunc( arr2, M );
myFunc( arr3, O );
myFunc( arr4, P );

This assumes all the arrays have the same base type (e.g., they're all arrays of int).
If you want a function to work on four arrays simultaneously, you'd write it as
void myFunc( T *a1, size_t a1_size,
             T *a2, size_t a2_size,
             T *a3, size_t a3_size,
             T *a4, size_t a4_size )
{
  // code for handling each array
}

While I wrote it such that all the arrays have the same type, it doesn't have to be this way.  Each array can be a different type (a1 can be int, a2 can be double, etc.).

Am i right to assume that it's not possible calling a function for multiple individual arrays?

What would give you that impression?  An array is just a pointer to a block of memory - as such it's just a variable. You can pass as many as you like to a function.
Just remember that a function can't know how big the array is that you pass it, since it only gets the pointer to the start of the array, so you need to pass the size of the array with it. You can't rely on the sizeof operator, since that is a compile-time directive that gives the size of a variable, which inside the function will be the size of a pointer (2 bytes on an 8 bit system). It can only give the size of an array (and then only the memory size in bytes, not the count of elements) if its run in the same (or a subordinate) scope as the declaration of the array.

Perhaps a separate question, but if a class or struct would be more suitable for multiple instances, what are the major differences worth considering to choose the right approach?

A struct is just a way of grouping variables into compound types. Think of them as database records. Great for if you want to keep related, but different, information together in one block.  Classes are the same thing but add functions as well.*

* That's a very simplistic description. In actuality you can have functions in structs and not have functions in classes. The real difference between them is how access controls (private/protected/public) are implemented (there is none in structs, and they are all there in classes) and how inheritance / polymorphism works.

Regarding your first question: I can't figure out a way to pass four individually declared arrays to the same function, and figured i'd ask beforehand instead of trying something that in fact is impossible. If it's doable, please elaborate. Also, thanks for describing things in the latter part of your answer.

@Erik I can't unless you show us what it actually is you are trying to do.

"An array is just a pointer to a block of memory" - if we're talking about C or C++, this isn't correct.  Array expressions will be converted ("decay") to pointer expressions in most contexts, but array objects are not pointers.  An array is simply a contiguous sequence of elements - no storage is set aside for a pointer to the first element.

@JohnBode What on earth is an array object?

@Majenko: The memory set aside for the array elements.

@JohnBode That is just memory. There's nothing object-y about it. If it's local to a function it's just a change in the stack pointer. If it's global or static it's a chunk of memory in the BSS or .data section. All you get is a pointer to that block of memory. The array knows nothing about it. The size of an array is only ever known at compile time by the compiler.

@Majenko - I'm using the term "object" the same way that the C language definition uses "object" - a region of storage in the execution environment that may store values.  An array is not a pointer to a block of memory - an array is that block of memory.

@JohnBode The abstract concept of an array may be the memory, but the actual variable that you have in your program is a pointer. Can you add an integer to an array? No. Can you add an integer to a pointer? Yes.

@Majenko: No, the actual variable is not a pointer.  That's the point I'm trying to make.  The actual variable is an array.  No pointer value is stored in the memory referenced by the array name.

@JohnBode So... if you add 1 to an "array" variable, what do you get? I think the difference you are trying to get across is that an array is the address of a block of memory, but a pointer is a variable that contains the address of a block of memory. Either way both are variables that point to a block of memory. The compiler knows more about what the "array" style is pointing to (since it can see that in the source code) but when compiled both pure pointers (char *) and "arrays" (char[...]) are the same thing.

@Majenko: An array is not an address.  An array is a sequence of elements.  An array expression gets converted to a pointer expression as necessary, but that's not the same thing.

@JohnBode So - if you print an array, what do you get? Do you get the array, or do you get an address? Me, I get an address. There is no variable type in C that can store more than a simple number. Everything else is an address (a simple number) to a block of memory over which the compiler overlays an abstract concept. You're confusing abstract concepts and data storage.

@JohnBode This is why you can never pass a copy of an array to a function, and you can never return an array from a function. The array doesn't exist. Only the address.

@Majenko: Except when it is the operand of the sizeof or unary & operators, or is a string literal used to initialize a character array in a declaration, an expression of type "N-element array of T" will be converted ("decay") to an expression of type "pointer to T", and the value of the expression will be the address of the first element of the array.  When you pass an array expression as an argument to a function (such as to printf), what the function receives is a pointer.  But the array itself is not a pointer.

@Majenko - This is why the expressions arr and &arr yield the same value (the address of an array is the same as the address of the first element of the array), but why the types are different (T * vs. T (*)[N]).

@Majenko: And this is why sizeof behaves differently for expressions of array type vs. expressions of pointer type.

@JohnBode You're still talking abstract concepts overlaid by the compiler. All those things you mention are compile-time constants. Things it can reference in the source code. As soon as it's compiled all those things vanish and are reduced to mere numbers. All you ever have, even if you call a block of memory an "array" and overlay some concept over it, is an address, and maybe a size if specified in the source code and the scope is suitable. No matter what you call an array, it's still a block of memory at an address, and, as you yourself said:

"the expressions arr and &arr yield the same value (the address of an array is the same as the address of the first element of the array)" - the "array" is just an address in memory.

“As soon as it's compiled” you are right. But if you write your code in C, rather than assembly, understanding the difference between an array and a pointer – and the related concept of pointer decay – doesn't hurt.


text:
How can i call lcd.begin() from several different code files in a proper way?
I have a project split into several files:
//Loop.cpp
#include "LiquidCrystal.h"

void setup(){
    LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
    lcd.begin(16, 2);
}

void loop() {
//Code
}

//Display.cpp
#include "LiquidCrystal.h"

namespace display {
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void displayData(const InputPacket &inputPacket, const DataPacket &dataPacket) {
    lcd.setCursor(0,1);
    lcd.print("Foo");    //This creates display error, unless i call lcd.begin(16, 2) in this function
}

} //namespace display

My initial problem is that - without calling lcd.begin() from within displayData() - the characters aren't displayed correctly. In other words, calling lcd.begin() in setup() doesn't help. (It appears to me that setup() has implicit static property, no?)
As an attempted solution, i could create an lcd object in Display.cpp, and call lcd.begin() from within displayData(). Even though characters are displayed properly, this gives me display flickering. (Presumably as a result of calling these functions repeatedly in the loop during runtime).
So, the only solution to this dilemma that i can come up with is to call lcd.begin() from a function written to run only once inside of displayData(). Or is it?
My question is, are there other more elegant solutions/alternatives?

The object called lcd that you create inside the setup function is a local variable. It only lives as long as that function is executing - so not very long. It doesn't exist outside that function.
The lcd object you have in namespace display on the other hand is a global variable. That one lives as long as your program, which means until you reset your Arduino here. (It is completely unrelated to the object inside setup.)
If you want all your LCD code to be grouped inside the display namespace, you could do this in Display.cpp:
namespace display {
  // This is a global variable, full name `display::lcd`
  LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

  void setup() {
    // this `lcd` refers to the global `display::lcd` defined above
    lcd.begin(16, 2);
  }

  // rest of the display functions
}

Create a Display.h file to provide prototypes for the display module:
#ifndef DISPLAY_H
#define DISPLAY_H

// Include the header that defines InputPacket and DataPacket here

namespace display
{
void setup();
void displayData(const InputPacket &inputPacket, const DataPacket &dataPacket);
}

#endif

Then your main file can call the display function. The main file doesn't even have to know that you're using an LCD if you do package all LCD code in the display file.
#include "Display.h" // no need to include LiquidCrystal.h if all
                     // LCD handling is done in Display.cpp

void setup(){
  // Initialize display
  display::setup();
}

Awesome, thanks. Your reply gave me a lot of interesting things to consider!


text:
How to loop over analog pins?
I want to do something along the lines of
for (int i = 0; i < 4; i++) {
  analogRead(i);
}

Which appears to work, but the following does not:
for (int i = 0; i < 4; i++) {
  pinMode(i, INPUT);
  pinMode(i + 4, OUTPUT); // should make Analog Pin (i + 4) into an output
  digitalWrite(i + 4, LOW);
  analogRead(i);
}

Instead, it appears to treat the pin addressed by digitalWrite(i + 4, LOW); as one of the digital pins.
Do I really have to explicitly specify A0, A1, A2, ... anytime I want to loop over the analog pins?

I like your poetic descriptions of the different answers! The metaphors are apt - but you may want to put them in quotes for our non-native English readers, to highlight you are being a little hyperbolic: "nuclear bunker", "paper airplane", etc.

Yes, the analog pins must be addressed using A0, A1,... when using them for digital I/O.
Depending on the board you are using A0,A1,etc. are mapped to different values (for instance it looks like A0 is 18 on some boards but 14 on others.
One solution for looping over the analog pins would be this:
static const uint8_t analog_pins[] = {A0,A1,A2,A3,A4};
// Setup pins for input
for (int i = 0; i < 5; i++) { //or i <= 4
  digitalRead(analog_pins[i]);
}

If you are using the analog pins only with the analogRead() call you can use 0,1,... instead of A0,A1,...

According to http://arduino.cc/en/Reference/analogRead you can read from analog pins merely by number (e.g. 0, 1, 2, 3, etc.); the "A" in "A0" is optional. Of course, it can be more clear if you distinguish them with the "A" prefix but it is not required for analogRead. On the other hand, digitalWrite(i) assumes that i refers to a digital pin; to use digitalWrite with an analog pin one needs to include the "A" prefix.

Good catch. I updated the answer.

This is the most portable solution I've seen so far, and it's the one I'm using now, thanks.

At least an Uno/Megas/leonardos, all the values mapped to analog pin numbers are consecutive, so
for (int i = A0; i < A4; i++) {
  pinMode(i, OUTPUT);
  digitalWrite(i, LOW);
}

will set A0, A1, A2, and A3 to OUTPUT, and then LOW.

I know this is old, but if you hover your mouse over A0 to A7 in visual micro it will show you the true value, they are just a variable (it actually shows as 14U but while addressing you do not need to include the U). What Craig said is wrong, they do NOT have to be addressed by A0, A1 ect..
A0 = 14
A1 = 15
.
.
A7 = 21
//Will set all pins, digital and analog to LOW (0)
for (int i = 1; i < 22; i++) {
    digitalWrite(i, LOW);
}

//Will set all analog pins to LOW (0)
for (int i = 14; i < 22; i++) {
    digitalWrite(i, LOW);
}

//Will set all analog pins to LOW (0)
for (int i = A0; i < A7 + 1; i++) {
    digitalWrite(i, LOW);
}

The last for loop is basically saying i = 1 (A0), and stop on 21 (A7).

Assuming pin numbers are consecutives you can iterate them:
int acc = 0;
for (int Ai = A0; Ai < A0 + NUM_ANALOG_INPUTS; Ai++) {
    acc += analogRead(Ai);
}
Serial.println(acc);

Pins 14 through 19 are the analog pins A0 to A5. A0 is just an alias for 14 and so on.
So another way of writing BrettM's answer:
for (int i = 14; i < 18 i++) {
  pinMode(i, OUTPUT);
  digitalWrite(i, LOW);
}

This does not work on all Arduino boards. Not all boards use 14-19.

Your first loop will work just fine indeed, however, you might want to add delay(1); after you analogRead(i);, to give the ADC some time to settle.
Could you elaborate on what you are trying to do with your second piece of code? As it looks right now, it doesn't really make sense to use analog inputs as digital outputs.
Besides, you're trying to read a pin's input just a couple of lines after you specified the pin to be an output.
Please explain what you are trying achieve, so the nice folks around here can you help you better.


text:
Level detection of 3.3V from 5V arduino
A quick question about microcontroller digital level on I/O pins. I have a photo interrupter which is powered at 3.3V which is interfaced to Arduino UNO running at 5V.
For microcontroller to detect high or low level is determined by signal higher than 5V*(2/3) = 3.33V is high and signal lower than 5V*(1/3) is low. What I don't understand is that arduino is able to detect the level change from the photo interrupter. Doesn't the supply on pins have to be greater than (2/3) or Vcc in order for it to detect logic high? The circuit works and I am able to count pulses from the interrupter but I want to know why that works considering the photo interrupt only gets about 3.23V.
Please clarify

You've... misread the datasheet. The '328 input high voltage (VIH) for most pins is 0.6VCC minimum for devices with a 2.4-5.5V supply. This means that a 5V device has a 3V threshold.

You know the voltage at which the interrupter is connected is not a steady 3.3V. I was keeping track on the voltage and I saw it fluctuated to lowest value of 3.1V. Why doesnt it matter when the Threshold is 3V. The difference is only 0.1V. How come is still works?

The actual numerical difference is irrelevant. As long as the threshold is met, that's what counts.

The designed threshold of the '328 logic is 45% of Vcc for all supply voltages, except the tolerance reduces from +/-25% of Vcc {<3V} to +/-15% of Vcc{>3}  This tolerance is due to temperature and process variation.
Keep in mind that the smaller the difference between the "actual" threshold and your input is your immunity to noise and it will work if there is low noise. Thus 45+15% = 60%* 5V=3V is guaranteed.  What is not guaranteed, is the accuracy of your 5V regulator which if say 10% high will increase the threshold 10% above  3V or 3.3V.   So then 3.1 would not be guaranteed. So ensure accuracy of 5 V is below 5.04 minus your noise immunity requirements.


text:
Arduino Uno R3 ISR does not work on pin 2?
I have an Arduino Uno R3. I have a paddlewheel waterspeed sensor that I use on an ISR on pin 2. The power supply is approximately 8v stepped down to 4.92v with a circuit yanked from the phone charger. I have also tried this with the arduino 5v.
The pin returns the correct values with digitalRead(), so it's cycling between 1 and 0.
The ISR works fine on pin3. Why does it work on pin 3 and not pin 2 ISR?
void itest() {
    Serial.println( "test" );
}

void setup() {
    attachInterrupt(0, itest, FALLING);
}

Have you compared the disassembled code when using each pin?

Can you show us the code of the ISR and how you registered it?

Where do you set pinMode() of pin 2 to INPUT?

@jfpoilpret it doesn't need pinMode() and the ISR is hidden by the arduino code in the attachInterrupt

I hope you haven't forgotten to change attachInterrupt(0,itest,FALLING); to attachinterrupt(1,itest,FALLING);

never use Serial inside an interrupt handler, increment a (volatile) variable and print it in the loop().


text:
How can Arduino control with a servo with only one wire?
I was playing with getting my servos to be on dedicated power, separate form the Arduino entirely, but obviously controlled by the Arduino. I originally had the ground of the Arduino joined with the - of the battery, but to my surprise my Arduino continued to control the servos when I remove the ground wire entirely from the Arduino.
I was under the impression that all electricity must form a complete circuit, and be a closed loop. But my Arduino can obviously send a signal to a component that has no return path to itself.
I feel like I'm missing something fundamental about a electricity. So my question is:
Why does this work?

The return signal is probably the other wire's servo. This only works when the control pulses to both servos are not in sync. Pull one signal wire off the breadboard and both servos will stop working.
You need to interconnect grounds or you will get strange effects sooner or later.

Are the I/O-pins connected to GND when in OUTPUT mode and not outputting? This would make sense, and would mean this answer is correct.

@FriendofKim In any output mode through protection diodes in the microcontroller an in OUTPUT node through the driver transistor.

Yep, it doesn't work with just one servo, which I didn't think to try. Thanks!