body:
I'd like to know the differences between these two boards: [Arduino Pro Mini][1] and [Arduino Pro Micro][2].

Even if I've read [this][3] and [this][4] related post, it is not clear enough. I've always used the Arduino Uno or Leonardo and I'm a little bit scared of using these compact miniaturised boards.

I have seen so far those differences:

- The Micro doesn’t need the separate FTDI, while the Mini does
- The Micro takes more time to boot up due to USB device (keyboard/mouse) emulation (is more like a Leonardo than an Uno)
- They both have 5 V and 3.3 V versions
- The Mini has 2 more digital IO and 2 more analog Inputs (1 more PWM)
- The pinout is the same (a shield designed for the Pro Mini is OK also with Pro Micro)
- Micro is more expensive (IF you don't have already an FTDI cable).

So, what I care about most is the boot up time (because it could make debug harder) but other than that.. if I don't need the 2 more Digital IO and the 2 more Analog Inputs.. why buy one over the other?

And some more question: can I use the Mini boot loader inside the Micro to avoid the boot up time (if I do not need the keyboard/mouse emulation)?

Is the power consumption the same? Can I use the same battery?

Sorry if this is a silly question but I'm little bit confused.

  [1]: https://www.sparkfun.com/products/11113
  [2]: https://www.sparkfun.com/products/12640
  [3]: https://electronics.stackexchange.com/questions/96805/how-to-program-arduino-nano-pro-mini-pro-micro-clone-that-has-no-usb-port
  [4]: https://www.sparkfun.com/arduino_guide

title: All the differences between Arduinos: Pro Mini & Pro Micro

Answers: 4

body:
It is more the differences between ATMega328P + FTDI (Pro Mini) vs ATMega32u4 (Pro Micro)

Apart from the minor pin differences, the peripherals for both MCUs are the same. The major difference is the ATMega32u4 has built in full-speed USB. This allows the board to function as a USB device by implementing the appropriate USB stack. E.g. it can act as a

 - USB to serial converter (CDC device)
 - Keyboard or mouse (HID device)
 - USB hard drive (MSC device)
 - MIDI controller
 - and more...

The LUFA library from AVR devices can be used for this but means going outside of the Arduino IDE and compiling proper C code using the latest avr-gcc tools.

The Arduino core library has built-in support for the HID and CDC device profiles. The CDC profile is used for comms with the Leonardo, Micro, etc. while the HID profile is used for keyboard / mouse emulation.

The Leonardo / Micro boot loader implements a CDC profile for communications with the PC. This CDC profile uses Arduino vendor and product ids so unlike FTDI devices, requires an extra step to install an `*.inf` file on Windows.

You would have to recompile the Pro Mini bootloader for the Micro, but even then it would require an FTDI board as programming would need to be done via the TX and RX UART pins. If you we going to go to all that trouble you could just recompile the proper boot loader to have a shorter time out. Why is difference of 1 or 2 seconds in boot loader time important?

The ATMega32u4 uses more power than the ATMega328P.

body:
In addition to what @geometrikal says (excellent answer, BTW) ATMega32u4 has 5 available true hardware interrupts (so-called "external"), whereas ATMega328p only has 2.

IMHO, that is a key advantage for some applications.

body:
> So, what I care about most is the boot up time (because it could make debug harder)

still couldn't figure out the link between boot up time and debug.

> but other than that.. if I don't need the 2 more Digital IO and the 2 more Analog Inputs.. why buy one over the other?

sounds like there is no reason for you to the other board.

> And some more question: can I use the Mini boot loader inside the Micro to avoid the boot up time (if I do not need the keyboard/mouse emulation)?

the only way to avoid boo up time in anything, pro mini or pro micro, is to not boot it up. you cannot have boot up time if you don't boot it up.

As to the two boards, they use different avrs. the U4 has amazing analog features, but most pro micros don't route out AIN0/AIN1 - rendering them as the same as pro mini. that's a shame.

obviously, if you don't use those features,  they have no value to you and cannot justify the premium / added complexity.

body:
Arduino Pro Mini
[![Arduino Pro Mini][1]][1]
[Pin Mapping][2]

Arduino Micro
[![Arduino Micro][3]][3]
[Pin Mapping][4]
[![ArduinoMicro_Pinout3.png][5]][5]

The Arduino page for the [Arduino Pro Mini][6] and the [Arduino Micro][7].

**Microcontroller**
Arduino Pro Mini: ATmega328 (ATmega168 on older boards)
Arduino Micro: ATmega32U4

**Memory**
Both have 32KB of Flash and 1KB of EEPROM
The Arduino Pro Mini has 2KB of SRAM where as the Arduino Micro has 2.5KB

**Digital I/O**
The Arduino Pro Mini has 14 (of which 6 provide PWM output)
The Arduino Micro has 14 also (of which 7 provide PWM output)
Some of the analog pins can also be used as digital I/O

**Analog Inputs**
Arduino Pro Mini: 8 (some boards only break out 6 analog inputs)
Arduino Micro: 12 ([6 dedicated and 6 from digital I/O pins][8])

**USB**
Arduino Pro Mini: Requires FTDI cable or Sparkfun breakout board to provide USB power and communication to the board.
Arduino Micro: Native USB

**Clock**
Both are 16 MHz (although the 3V Arduino Pros run at 8MHz)

**Power**
There are two version of each of the Arduinos. One runs at 3.3V and 8 MHz, the other at 5V and 16 MHz.
Arduino Pro Mini: VRAW  can accept voltage up to 12VDC.
Arduino Micro: USB or external supply of 6 to 20 volts (recommended range is 7 to 12 volts)

**Interrupts**
Arduino Pro Mini: The Atmega328 has 2 hardware interrupts available
Arduino Micro: The ATMega32u4 has 5 hardware interrupts available
credit: [Enric Blanco][9]

  [1]: https://i.stack.imgur.com/LKcvq.jpg
  [2]: https://cdn.sparkfun.com/datasheets/Dev/Arduino/Boards/ProMini16MHzv1.pdf
  [3]: https://i.stack.imgur.com/l4hOF.jpg
  [4]: https://www.arduino.cc/en/Hacking/PinMapping32u4
  [5]: https://i.stack.imgur.com/IbHDG.png
  [6]: https://store.arduino.cc/usa/arduino-pro-mini
  [7]: https://store.arduino.cc/usa/arduino-micro
  [8]: https://www.arduino.cc/en/uploads/Main/ArduinoMicro_Pinout3.png
  [9]: https://arduino.stackexchange.com/a/34577/19409


body:
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,"d",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.

title: Using XBee and OLED screens with Timer Interrupts

Answers: 1

body:
I suspect `send()` is blocking.

`XBee::send()` calls `_serial->flush()` (see [code](https://code.google.com/p/xbee-arduino/source/browse/XBee.cpp#1461)). `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](https://github.com/arduino/Arduino/blob/master/hardware/arduino/cores/arduino/HardwareSerial.cpp#L455).


body:
I plan on purchasing [a Nano clone][1], an Ethernet shield [(ENC28J60)][2], an LCD and a DHT22 humidity + temperature sensor. This will be used in a wine cellar to monitor relative humidity and temperature.

The DHT sensor, LCD and Nano all operate on 5V logic. The Ethernet shield does not operate at 5V, but rather at 3.3V.

Does the Nano have a way to connect the two, will they work anyway (probably not), or should I use a CD4050 that is recommended on adafruit?

Any guidance is appreciated; I'm still amazed in what $10 in parts can do.

Also, in regards to the DHT22 sensor, what do I need in terms of a resistor? I've seen some people say you absolutely need a 4.7K resistor on the data pin for "pull up", and  others who say it's unnecessary. Can someone give a definite answer, either way?

Edit, wrong link on my nano clone.

  [1]: http://www.ebay.com/itm/3PCS-Nano-V3-0-ATmega328-controller-Board-5V-16M-CH340G-USB-Driver-For-Arduino-/381019048475?pt=LH_DefaultDomain_0&hash=item58b6814a1b
  [2]: http://www.ebay.com/itm/New-ENC28J60-Ethernet-LAN-Network-Module-For-Arduino-SPI-AVR-PIC-LPC-STM32-BDRG-/301354703227?pt=LH_DefaultDomain_0&hash=item462a23d97b

title: Arduino Nano and a 3.3v Ethernet shield

Answers: 1

body:
Just get [one with a 3.3v regulator on it](http://www.ebay.com/itm/3-3V-5V-ENC28J60-LAN-Ethernet-Network-Module-Dual-MOS-For-Arduino-MCU-AVR-51-LPC-/171310795997?pt=LH_DefaultDomain_0&hash=item27e2eb4cdd). PS logic levels are allowed to be 5v.

DHT22 and LCD will also work fine on 3.3v so, alternatively, you could also get a 3.3v Nano.

The resistor value for the DHT22 depends on the length of wire between the DHT and Nano. Just buy them to be sure, or get a breakout board that already has them on the board (along with a capacitor, which is nice).


body:
I'm using an Arduino pro mini to receive the analog signals from three sensors. I was wondering what sampling rate I should sample at in order to properly represent these signals. I know it should be twice the highest analog frequency, but I'm not sure what frequency theses sensors operate in. They're an ECG, a 3 axis accelerometer, and a stretch resistor respectively. To my knowledge, Arduino defaults at a sampling rate of 10kHz, which I believe should be more than enough to quantize the sensor signals. I'm then sending these signals out using bluetooth mate to an android phone. Is there a specific baudrate I should send the data at?

Here is the initialization of my code:

    void setup()
    {
      Serial.begin(9600);
      bluetooth.begin(115200);
      bluetooth.print("$$$");
      delay(100);
      bluetooth.println("U,9600,N");
      bluetooth.begin(9600);
      setTime(0);
    }

Thanks so much

title: Necessary sampling rate

Answers: 2

body:
The sampling frequency you are referring to (twice the highest frequency) is for capturing waves, but is not really a concern for the sensors you are using and the types of data they are used to measure.

If you wanted to analyse the magnitude of a 40kHz vibration in a structure, you should worry about sampling rates on your accelerometer; however, if you want to measure the accelerometers current angle to the ground (assuming its not accelerating), you only need to take one sample.

With the ECG, there will be a signal among all the analog voltages you read of a heartbeat (I'm assuming its hooked up to a person). This signal will never get much over 200 beats per minute, or 3.3 Hz. To capture a 3.3Hz signal you need a minimum sampling rate of 6.6Hz, which as still incredibly slow. The same goes for capturing a gait with your accelerometer.

If you capture the analog voltage of your sensors output with analogRead 100 times a second, you should have a very clear and well defined view of the very low frequency signals you are trying to track, and should not have any issues with transferring that much information over serial.

5, 16 bit values can theoretically be sent at 120Hz over 9600 baud, and its very easy to use faster speeds then that if you want more information.

body:
Since I think BrettAM already gave a pretty good answer, I'm going to expound just a little upon that.

First off: I think you're misunderstanding sample rate. The sample rate here is simply the number of analog readings per second that you are doing of a given signal.

If you want to know the **maximum** sample rate of the Arduino, you simply have to take a ton of samples as fast as you can and see how many you were able to take in a given second. For the Arduino with default settings, that's ~9600 per second *maximum*. If you just take 1 single sample though, your sample rate is......I don't know.....how often do you do this!? If you take 1 sample and then stop your sketch for an hour, your sample rate for that one sample was 1 sample per hour. Now, what are you sampling? If what your're sampling is *changing* faster than one noticeable change (ADC resolution step) per hour, then you need to sample faster than once per hour. If your signal (what you're sampling) is changing at 100 times per second (100Hz), however, then you need to sample at *at least* 200 Hz to even detect it's changing at 100Hz, and at *approximately 1000Hz or higher* to actually plot what that 100Hz signal looks like. Note: sampling at 2x the rate of the sampl**ed** signal is the minimum sample rate required to detect the frequency of the sampl**ed** signal, and is called the [Nyquist Frequency](http://en.wikipedia.org/wiki/Nyquist_frequency). Sampling at 10x the sampl**ed** signal is the generally-accepted rule-of-thumb for minimum sample rate required to capture the *waveform,* or *shape* of the sampl**ed** signal.

Now, let's look into data smoothing. If you just take a single sample, it might bounce around. How do you stop this? One method, is to take many samples and average the result. A library I wrote does this, among many other things, so I'll present it here.

Taking many samples in a row then using the average of the samples in any calculations helps to remove the noise component from your signal. I have written an oversampling library that among other things, does just that. An (outdated..will be updated eventually) page on it is here: [Using the Arduino Uno’s built-in 10-bit to 21-bit ADC (Analog to Digital Converter)](http://www.electricrcaircraftguy.com/2014/05/using-arduino-unos-built-in-16-bit-adc.html#.VVqTlPlViko).

The current version of the code is V2.1 alpha, and the download link is currently highlighted in yellow at the link above.

In case you need to take faster samples, you can also speed up the ADC sample rate to 50+ kHz, using my library...as opposed to settling on the default 9600Hz of the Arduino.

Play around with sampling and smoothing and stuff.  One technique is to speed up the ADC (so you don't waste too much time sampling), then take the avg. of many samples in order to help remove noise from your sensors. This may be unnecessary, if noise is minimal or changes over time on the signal are slow, but for the sake of learning I'll present this.

Here's an example sketch:

    //include the library
    #include <eRCaGuy_NewAnalogRead.h>

    //Global Vars
    byte pin = A0;
    byte bitsOfResolution = 10; //commanded oversampled resolution
    unsigned long numSamplesToAvg = 50; //number of samples AT THE OVERSAMPLED RESOLUTION that you want to take and average

    void setup()
    {
      //Configure the adc how you want it
      adc.setADCSpeed(ADC_PRESCALER_16_CLOCK_1MHZ); //this speeds up the ADC clock by a factor of 8
    }

    void loop()
    {
      //local variables
      unsigned long analogReading;

      //take a reading on the analog pin
     analogReading = adc.newAnalogRead(pin,bitsOfResolution,numSamplesToAvg);
    }

You'll see that I am speeding up the ADC and taking and averaging 50 samples to smooth the data. I have yet to test the speed, but I estimate this could prob. run at 500Hz or so max sample rate (returning an average value each time)...assuming that's all you did.

Doing this and taking a single sample is fine for what you need I believe.

Now, for baud rate. Baud rate is essentially "bits of data sent per second." It's how fast your communication signal is. Lower baud rates are generally less susceptible to electrical noise, and the data is less likely to get corrupted, but higher baud rates send the data values much more quickly and waste less of your code time sitting around transferring data. I recommend you speed it up to maximum, unless you have data transfer problems or dropouts, in which case you should slow it down a bit.

NOTE: for more detailed examples on the library download it and look in the examples folder.


body:
SparkFun sells an FM Tuner Board ([here][1]) and provides code to work it.  However, neither libraries that I found in other places, nor the example code that they provided, worked.  I have checked the wiring multiple times and I am nearly certain that the fault is in the code but I can't find it.  Thanks...

ECC

  [1]: https://www.sparkfun.com/products/11083

title: Attaching an Si4703 to an Arduino

Answers: 0


body:
The [ADS1256 chip][1] is a high precision 24bit, 8 channel, analog digital converter based on SPI communication that is suitable for biomedical applications and perfect for sensing ECG and EEG signals. I want to hook it up to an arduino, e.g., an arduino mega or an arduino due.

Similar ADCs from analog devices are: ADS1248, ADS1251, ADS1252, ADS1252U, ADS1253, ADS1255, ADS1259, ADS1278, ADS1298, ADS1299, etc.

It’s nice that there are [tiny, coin sized breakout boards]  available for the ADS1256 that include basic components like an 8mhz quartz crystal and cost only around 25 USD.

Several people have in the past struggled to get ADC readings using Arduino. Working only with the data sheet it took them several days or even weeks. I have a logic analyzer, multi channel oscilloscope and [bus pirate][2] ready, but I still would prefer adapting an existing library or working with a good tutorial as a starting point.

I searched for code and tutorial not only for the ADS1256 but also for similar analog devices ADC chips.

Here are the tutorials, libraries and information I found so far:

**Main Links (working solution):**

-- [ADS1213 Arduino library][3] (seems to be working!!!)

--  [ADS1213 Arduino tutorial][4] (includes above library)

**Further Information:**

- [Arduino due ADS129X tools(ADS1299, ADS1298, ADS1294, ADS1296)][5]

- [ADS1252 Arduino Tutorial][6]

- [ADS1252 Troubleshooting information][7]

- [ADS1255 Troubleshooting information][8]

- [ADS 1298 Troubleshooting information][9]

- [ADS 1248 and arduino (german)][10]

**Q:**
Is there a working library for the ADS1256 (or similar chip) and is there a current, up-to-date tutorial available for arduino?

----------

(Update with my notes.)

**Next steps** (to get a working library that should be put on github):

 1. Search for more relevant Information online (existing libraries, etc.)
 2. Ask in AVR specific forum, if question is unanswered here. Possibly contact people via e-mail that could know more
 3. Get familiar with Chip and Datasheet
 4. Decide on available codebase as the starting point
 5. Define the minimalistic testcase (This would check that some for of communication works with the chip, i.e., write register that changes the logic level of a bin of the ADC chip)
 6. Implement the minimalistic testcase (i.e., possibly use different codebase as starting point if it fails to implement)
 7. Expand and test the code to get a full implementation

**Risks:** Eittle experience with electronic design the microcontroller at hand, might miss important details that costs a lot of time. Can't be sure that my chip/PCB actually works, can be faulty hardware.

**Time Estimate**: 3 days of work doing 8 hours a day (total 24 hours). Exremly high variance (could be a matter of a few hours in the best case to a few weeks worst case).

  [1]: http://www.ti.com/product/ads1256
  [2]: http://dangerousprototypes.com/docs/Bus_Pirate
  [3]: http://arduino.cc/forum/index.php?action=dlattach;topic=53063.0;attach=15873
  [4]: http://forum.arduino.cc/index.php?PHPSESSID=q3dffkh8l0t6i89mljk3fcj603&topic=53063.0
  [5]: https://github.com/adamfeuer/ADS129x-tools
  [6]: http://forum.arduino.cc/index.php?topic=57873.0
  [7]: http://e2e.ti.com/support/data_converters/precision_data_converters/f/73/t/272825.aspx
  [8]: http://e2e.ti.com/support/data_converters/precision_data_converters/f/73/t/272825.aspx
  [9]: http://e2e.ti.com/support/data_converters/precision_data_converters/f/73/t/168648.aspx
  [10]: http://www.mikrocontroller.net/topic/302404

title: References (e.g, libraries and tutorials) for connecting the 24-bit ADS1256 ADC to arduino

Answers: 1

body:
You are lucky. Looks like there is an Arduino library available for the ADS1256. You should give it a shot: https://github.com/Flydroid/ADS12xx-Library .

I haven't tested it but checked the registers and functions from the datasheet and it does look good.


body:
Is it possible to use more than 1 device that needs to use SDA for I2C with a mini?
Would you use a different analogue pin with a 10k pull up resistor and tie all of the devices to the SCL?

title: Connect multiple I2C to an Uno

Answers: 1

body:
> Is it possible to use more than 1 device that needs to use SDA for I2C with a mini?

Yes, provided they have unique I2C addresses.

> Would you use a different analogue pin with a 10k pull up resistor and tie all of the devices to the SCL?

No. All of the devices must be tied to both SDA and SCL. You may need a smaller resistor depending on how many devices there are; see NXP document UM10204 for details.


body:
I bought a Sainsmart LCD2004 from Amazon to use with my Arduino Uno.
I understand that since this LCD uses I2C a new library needs to be downloaded.

From the sainsmart website I dowloaded the LCD 2004 rar
http://www.sainsmart.com/arduino/arduino-shields/sainsmart-iic-i2c-twi-serial-2004-20x4-lcd-module-shield-for-arduino-uno-mega-r3.html

When I try to compile the example titled helloworld I get the following error:

*In file included from HelloWorld.pde:3:
C:\Users\r_yob_000\Documents\Arduino\libraries\LiquidCrystal_I2C/LiquidCrystal_I2C.h:81: error: conflicting return type specified for 'virtual void LiquidCrystal_I2C::write(uint8_t)'
C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino/Print.h:48: error:   overriding 'virtual size_t Print::write(uint8_t)'*

There seems to be a conflict between two functions returning different types.

I've tried searching the issue and found a lot of posts with similar errors.
The solution suggested is usually that a new version of the LiquidCrytal_I2C needs to downloaded. Or that one should use Arduino IDE version 1.0

I have downloaded tons of LiquidCrytal_I2C libraries and tried them all on IDE version 1.0 and 1.0.6 and I still get the same error message. I've even tried changing the LiquidCrytal_I2C.h file so that it returns the correct type and still have no luck.

Could I please get some help with this issue.

Thank you very much.

title: Sainsmart LCD 2004 - LiquidCrytal_I2C library issue unable to compile

Answers: 3

body:
I just bought 3 of these that work well with this library
 [LiquidCrystal_I2C2004V1.zip](http://arduino-info.wikispaces.com/file/detail/LiquidCrystal_I2C2004V1.zip)
(*License: CC BY-NC 2012 http://www.wikispaces.com/user/view/TerryKing*).

When installing this library in Arduino IDE (version 1.6 or later), use menu item **Sketch | Include Library | Add .ZIP Library...**, navigate to the folder where LiquidCrystal_I2C2004V1.zip was downloaded, and then open the zip file.

Use the I2C address in the example "HelloWorld" supplied with LiquidCrystal_I2C2004V1:

    //YWROBOT
    //Compatible with the Arduino IDE 1.0
    //Library version:1.1
    #include <Wire.h>
    #include <LiquidCrystal_I2C.h>

    LiquidCrystal_I2C lcd(0x27,20,4);  // set the LCD address to 0x27 for a 16 chars and 2 line display

    void setup()
    {
      lcd.init();                      // initialize the lcd
      lcd.init();
      // Print a message to the LCD.
      lcd.backlight();
      lcd.setCursor(3,0);
      lcd.print("Hello, world!");
      lcd.setCursor(2,1);
      lcd.print("Ywrobot Arduino!");
       lcd.setCursor(0,2);
      lcd.print("Arduino LCM IIC 2004");
       lcd.setCursor(2,3);
      lcd.print("Power By Ec-yuan!");
    }

    void loop()
    {
    }

Do not change the other library directory name; this one is compatible with the existing library. Just add it as a contributed library.

body: I had problems with this library too, until I realized the default library name "LiquidCrystal" conflicts with that of another library, which makes that the files get mixed up. Simply place the files in a different folder (I named mine) "LiquidCrystal_4x20". Solved it for me.

body:
You must to upgrade your I2C library.

Here you can find it the last version:
https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads/

And move the old one in another folder so you can  use this one
or after you install this one do like this:

1. Go in the `Arduino\libraries\Newliquidcrystal_1.3.5\`
2. Rename the `LiquidCrystal_I2C.h`  like `LiquidCrystal_I2Ca.h`
3. When you use it in the sketch use include `LiquidCrystal_I2Ca.h`


body:
I have Arduino UNO with 0.96" OLED display with 128(width)*32(height). It is said that I have to edit Adafruit_SSD1306.h for my 128*32 OLED, okey I did it from 128*64 to 128*32 but I still get the compiler error:

    ssd1306_128x32_i2c.ino:54:2: error: #error ("Height incorrect, please
    fix Adafruit_SSD1306.h!");

Yes, I fixed the Adafruit_SSD1306.h file, **but now,** it is still gives me a compiler error:

    C:\Users\OB\Documents\Arduino\libraries\Wire\utility/twi.h: In member
    function 'uint8_t TwoWire::requestFrom(uint8_t, uint8_t, uint8_t)':
    C:\Users\OB\Documents\Arduino\libraries\Wire\utility/twi.h:47: error:
    too many arguments to function 'uint8_t twi_readFrom(uint8_t,
    uint8_t*, uint8_t)'
    C:\Users\OB\Documents\Arduino\libraries\Wire\Wire.cpp:85: error: at
    this point in file
    C:\Users\OB\Documents\Arduino\libraries\Wire\utility/twi.h: In member
    function 'uint8_t TwoWire::endTransmission(uint8_t)':
    C:\Users\OB\Documents\Arduino\libraries\Wire\utility/twi.h:48: error:
    too many arguments to function 'uint8_t twi_writeTo(uint8_t, uint8_t*,
    uint8_t, uint8_t)'
    C:\Users\OB\Documents\Arduino\libraries\Wire\Wire.cpp:140: error: at
    this point in file
    C:\Users\OB\Documents\Arduino\libraries\Wire\Wire.cpp: In member
    function 'virtual size_t TwoWire::write(const uint8_t*, size_t)':
    C:\Users\OB\Documents\Arduino\libraries\Wire\Wire.cpp:195: error:
    invalid conversion from 'const uint8_t*' to 'uint8_t*'
    C:\Users\OB\Documents\Arduino\libraries\Wire\Wire.cpp:195: error:
    initializing argument 1 of 'uint8_t twi_transmit(uint8_t*, uint8_t)'

![enter image description here][1]
![enter image description here][2]

How can I use my four-pin OLED display with no errors?

  [1]: https://i.stack.imgur.com/A6Wbj.png
  [2]: https://i.stack.imgur.com/zAblZ.jpg

title: 0.96" OLED and Arduino UNO usage error

Answers: 2

body:
May I suggest the following. I found this fork of the Adafruit library which works better than the one they have on their website [Adafruit_ssd1306syp][1]. The original `Adafruit_ssd1306` library doesn't play nice with SPI and when you want to have your OLED running on i2c and use the SPI for something else. This is a great resource. Download, unzip to your libraries directory. Then run this sketch:

    #include <Adafruit_ssd1306syp.h>

    #define SDA_PIN A4
    #define SCL_PIN A5

    Adafruit_ssd1306syp display(SDA_PIN, SCL_PIN);

    void setup() {

      display.initialize();
      display.setTextSize(1);
      display.setTextColor(WHITE);
      printM("Starting Demo...");

    }

    void printM(String mess) {

      display.println(mess);
      display.update();
    }

    void loop() {

      printM("working");
      delay(1000);

    }

  [1]: https://github.com/Miyeah/Arduino-Dormitory-Assistant/tree/master/library/Adafruit_ssd1306syp

body:
You may wanna try this lib: [https://github.com/olikraus/u8glib][1]

Supports many devices and is very well documented!

Cheers

  [1]: https://github.com/olikraus/u8glib


body:
The best way to explain my problem is in form of code...

        const int ringerPin = A0;
        const int offhook = A4;
        const int onhook = A5;

        void setup(){
        pinMode(ringerPin, OUTPUT);
        pinMode(offhook, INPUT);
        pinMode(onhook, INPUT);
        randomSeed(analogRead(0));

      }

      int randCall = random(60000, 3600000); // generate a random number between 1 min and 60 min

    //ring every 1 to 60 minutes if the phone is down (hookon) and dont ring if the phone is picked up (no hookon)
    void loop()
    {
      if (digitalRead(hookon) == HIGH)

    void loop(){
    delay(randCall);

          //i dont know how to let this loop below here run for 30 seconds.
     void loop()
        {
          //turn audio off - i dont know how to.
        for(int x = 0; x < 15; x++){
          digitalWrite(ringerPin, HIGH);
          delay(50);
          digitalWrite(ringerPin, LOW);
          delay(80);
        }
        delay(2500);
        }
      else
        //play one randomly choosen audiofile out of 10 - i dont know how to
    }
    }

Maybe you can give me some suggestions to my coding problems.?
I wrote them inside the code descriptions.

title: Lily Pad mp3, nested loops with timing and play randomly choosen mp3, coding problem

Answers: 1

body:
Halo, thank you for ansering anything.. I got the loop loop loop thing now runin..

So its about playing an Audiofile if hookon == LOW ........ check it out :-)

The code now looks like this.

    const int ringerPin = A0;
    const int offhook = A4;
    const int onhook = A5;
    double beginRing = -40000;

    void setup(){
        pinMode(ringerPin, OUTPUT);
        pinMode(offhook, INPUT);
        pinMode(onhook, INPUT);
        randomSeed(analogRead(0)); // this starts Arduino's random number generator
    }

    int randCall = random(60000, 3600000); // generate a random number between 1 min and 60 min

    //ring every 1 to 60 minutes if the phone is down (hookon) and dont ring if the phone is picked up (no hookon)
    void loop()
    {
      if (digitalRead(hookon) == HIGH){
        delay (randCall);
        beginRing = Time.elapsedTime;
        while(Time.elapsedTime - beginRing <= 30000 && digitalRead(hookon) == HIGH){
          //turn any audio off???
          for(int x = 0; x < 15; x++){
            digitalWrite(ringerPin, HIGH);   // turn the solenoid on (HIGH is the voltage level)
            delay(50);                           // wait for 50 msec
            digitalWrite(ringerPin, LOW);    // turn the solenoid off by making the voltage LOW
            delay(80);                          // wait for 50 msec
          }
          delay(2500);
        }
      }
      if(Time.elapsedTime - beginRing <= 30000){
        //play one randomly choosen audiofile out of 10
      }
    }

So, now its about to stop any sound if the hookon is HIGH and to play the randomly choosen file 1 out of 10 if the hookon is LOW (its in the code as description...there i need the right comands)


body:
I would just like to start off by saying that I am new to Arduino so my code and approach to the wanted outcome are probably not the best. Anyway, I had the idea of using an ultrasonic sensor and my hand to act as a potentiometer to control the position of a servo. So, I wired everything up and wrote the code but the Servo just jitters around and doesn't move the way I wanted it to. The serial readings are fine, it is just that the servo isn't responding the way I hoped. Here is the code

    #include <Servo\Servo.h>
    #define echoPin 7
    #define trigPin 8

    int maximumRange = 400;
    int minimumRange = 0;
    int angle;
    long duration, distance;
    Servo myServo;

    void setup()
    {
     Serial.begin(9600);
     pinMode(echoPin, INPUT);
     pinMode(trigPin, OUTPUT);
     myServo.attach(9);
    }

    void loop()
    {
     digitalWrite(trigPin, LOW);
     delayMicroseconds(2);

     digitalWrite(trigPin, HIGH);
     delayMicroseconds(10);

     digitalWrite(trigPin, LOW);
     duration = pulseIn(echoPin, HIGH);

     distance = duration / 58.2;

     angle = map(distance, minimumRange, maximumRange, 0, 179);
     Serial.print("Distance = ");
     Serial.print(distance);
     Serial.print(" Angle = ");
     Serial.println(angle);
     myServo.write(angle);
     delay(50);
    }

If anyone can help, it would be appreciated if you could post what is wrong with my code and how to fix it.

Note: I'm using Visual Studio instead of the Arduino IDE, so that is why it says #include `<Servo\Servo.h>` at the top.

title: Using an ultrasonic sensor to act as a potentiometer for a Servo?

Answers: 0


body:
I followed the instructions in [here](https://github.com/WeAreLeka/Bare-Arduino-Project/blob/master/INSTALL.md), including to use arduino IDE v 1.0.5, but when I tried to `make upload` it stuck. I can upload it when using Arduino IDE.

Here is what I got:

      mkdir -p /Users/bagustrihatmaja/Documents/Projects/MyAwesomeProject/bin/mega328/mySecondProject
     /Applications/Xcode.app/Contents/Developer/usr/bin/make reset
     /Users/bagustrihatmaja/Documents/Projects/MyAwesomeProject/Arduino-Makefile/bin/ard-reset-arduino  /dev/cu.usbmodem1421
     /Applications/Xcode.app/Contents/Developer/usr/bin/make do_upload
     /usr/local/bin/avrdude -q -V -D -p atmega328p -c arduino -b 57600 -P /dev/cu.usbmodem1421 \
   -U flash:w:/Users/bagustrihatmaja/Documents/Projects/MyAwesomeProject/bin/mega328/mySecondProject/mySecondProject.hex:i

What did I miss?

I use: Bare-Arduino-Project, OSX 10.10, XCode 6.1, Arduino Uno, [my Makefile](http://pastebin.com/cR79Sqqz)

title: Make upload stuck on osx 10.10 bare-arduino-project

Answers: 1

body:
I'm the maintainer of the Bare-Arduino-Project, thanks for using it :)

Have you installed `pyserial` and `avrdude`?

To install `avrdude` just run `brew install avrdude` and to install `pyserial`, you need `python installed`, then you can run `pip install pyserial`.

https://github.com/WeAreLeka/Bare-Arduino-Project/blob/master/INSTALL.md#3-install-pyserial

Hope it helps :)

Next time, feel free to open an issue in the Github repo as it might also help others.

**EDIT:** my bad, I did not read your Makefile carefully!

the problem is with:

    BOARD_TAG         = mega328
    # it should be
    BOARD_TAG         = uno


body:
I would like to exchange data via **Xbee**. I've set up a communication based on strings between the Arduino and a Matlab software.
Unfortunately this kind of communication isn't enough robust and sometimes messages aren't delivered correctly. So I decided to move to the **binary communication**.

**The problem:**

I'm not able to send **binary data** from the Arduino to the computer.

Let's say we want to send the decimal value 17 which is **0x11** in hex if we receive 16 from Matlab.
<!-- language-all: lang-cpp -->

    [...]
    SoftwareSerial xbee(pinRx, pinTx);
    void setup()
    {
      Serial.begin(BaudRateSerial);
      xbee.begin( BaudRateXbee );
    }
    [...]
    void loop()
    {
     while(xbee.available())
      {
        getData = xbee.read();
        Serial.println();
        Serial.print("Received: ");
        Serial.print(getData,HEX);
        Serial.println();
        if(getData == 16)
        {
          // First attempt
          //uint8_t s = 17;
          //xbee.write(s);  -> Fail
          // Second attempt
          //xbee.write(0x11);  -> Fail
          // Third attempt
          byte message[] = {0x11, 0x11};
          xbee.write(message, sizeof(message));
        }
      }
    }

In the third attempt I tried sending an **array of bytes** and noticed that the received values were different.

    byte message[] = {0x11, 0x11};

    xbee.write(message, sizeof(message));

The Matlab software sends data correctly. I used the [fwrite][1] function as follows `fwrite(xbee,hex2dec('10'));` and the [fread][2] function to receive the ack which:

> reads binary data from the device connected to the serial port object,
> obj, and returns the data

**Matlab relevant code:**

    fwrite(xbee,hex2dec('10'));
    disp('Ack Requested...')
    ack = fread(xbee);
    disp(ack);
    if (ack == 17)
         % communication established
    end

I've also tried using XC-TU to monitor traffic on Serial port (blu values are sent from the PC, red ones are received from the Arduino) and as you can see red values are different and none of them is equivalent to 17! What am I missing?

![enter image description here][3]

  [1]: http://www.mathworks.it/help/matlab/ref/serial.fwrite.html?searchHighlight=fwrite
  [2]: http://www.mathworks.it/help/matlab/ref/serial.fread.html
  [3]: https://i.stack.imgur.com/mC7BE.jpg

title: Sending binary data to Matlab via serial

Answers: 0


body:
I connected my Arduino Uno to my raspberry via USB serial. I'm able to read out both digital and analog pins of my Arduino using the Python nanpy library (v.0.8).
However, I can't find support for the pulseIn() function. It seems nanpy doesn't support pulseIn() at all.

What is the best way to measure PWM signals with the Arduino and forward the results to the Raspberry Pi?

I am able to measure PWM using the Arduino GUI, however I would to take PWM samples at fixed time intervals over a long period of time and combine this data with other measurements that my Raspberry is making.I also tried pyFirmata, but it doesn't support pulseIn() measurements either.

title: What is the best way to measure PWM signals ( pulseIn ) with the Arduino via a Raspberry Pi?

Answers: 2

body:
Nanpy seems to have a [CounterClass](https://github.com/nanpy/nanpy-firmware/blob/master/Nanpy/CounterClass.cpp) that does frequency measurements.

Or do you want to measure the PWM duty-cycle?

body:
You can just have a sketch in the arduino that takes the measurements at whatever interval you want using the `analogRead(pin)` function and then forward those results to the raspberry pi via serial using `Serial.print(whatever you want here)`. If you don't know how to use serial with arduino just go to their site, they have very good documentation.
Hope that helps :)


body:
How can I sense distance with Bare Conductive's Touch Board, like they suggest in [their product video][1]?

I know how I can set the touch and release thresholds, so my Touch Board is more sensitive and triggers before I touch a sensor. What I want to do is get the information how near I am. Not in centimeters or so, but a simple value telling me when I'm nearer to or farther from the sensor like in the video.

  [1]: https://www.youtube.com/watch?v=Y3eSrUQTesg&t=27s

title: Sense distance with Bare Conductive's Touch Board

Answers: 1

body:
As a member of the Bare Conductive team, I can tell you that looking at the [grapher][1] will be helpful to you. The grapher is a processing sketch that requires the Touch Board to be running the [Datastream][2] code. Datastream will give you the sort of raw electrode data that you're looking for.

  [1]: https://github.com/BareConductive/mpr121-grapher
  [2]: https://github.com/BareConductive/mpr121/tree/public/MPR121/Examples/DataStream


body:
I'm trying to get a sensor to activate if a push button is clicked. And deactivate when a certain condition is met and reactivate when the push button is pressed again.

    #include <SPI.h> // Included for SFE_LSM9DS0 library
    #include <Wire.h>
    #include <SFE_LSM9DS0.h>

    #define LSM9DS0_XM  0x1D // Would be 0x1E if SDO_XM is LOW
    #define LSM9DS0_G   0x6B // Would be 0x6A if SDO_G is LOW
    // Create an instance of the LSM9DS0 library called `dof` the
    // parameters for this constructor are:
    // [SPI or I2C Mode declaration], [gyro I2C address], [xm I2C address]
    LSM9DS0 dof(MODE_I2C, LSM9DS0_G, LSM9DS0_XM);

    const byte INT1XM = 4; // INT1XM tells us when accel data is ready
    //const byte INT2XM = 8; // INT2XM tells us when mag data is ready
    //const byte DRDYG = 7;  // DRDYG tells us when gyro data is ready
    const int buttonPin = 15;     // the number of the pushbutton pin

    int buttonState = 0;

    double X;
    double Y;
    double Z;

    void setup(){

      pinMode(INT1XM, INPUT);
      pinMode(buttonPin, INPUT);

      Serial.begin(9600);
      Serial1.begin(9600); // Start serial at 115200 bps
      // Use the begin() function to initialize the LSM9DS0 library.
      // You can either call it with no parameters (the easy way):

      uint16_t status = dof.begin();
      // Or call it with declarations for sensor scales and data rates:
      //uint16_t status = dof.begin(dof.G_SCALE_2000DPS, dof.A_SCALE_6G, dof.M_SCALE_2GS);

      // begin() returns a 16-bit value which includes both the gyro and
      // accelerometers WHO_AM_I response. You can check this to make sure
      // communication was successful.
      // Serial.println(status, HEX);
      setODR();
    }

    void loop(){

      buttonState = digitalRead(buttonPin); //Read push button logic.

     // Serial.println(buttonState);

      if (buttonState == 1) {   //if push button is pressed

        printAccel(); //print sensor data

      }

    }

    void printAccel()
    {
      // Only read from the accelerometer if the accel interrupts,
      // which means that new data is ready.
      if (digitalRead(INT1XM))
      {
        // Use the readAccel() function to get new data from the accel.
        // After calling this function, new values will be stored in
        // the ax, ay, and az variables.
        dof.readAccel();

        //Serial.print("A: ");

        // Using the calcAccel helper function, we can get the
        // accelerometer readings in g's.
        X=dof.calcAccel(dof.ax);
        Y=dof.calcAccel(dof.ay);
        Z=dof.calcAccel(dof.az);

        Serial.print(X);
        Serial.print(", ");
        Serial.print(Y);
        Serial.print(", ");
        Serial.println(Z);

        // Serial1.println(Z);

        fall(); //jump to check condition

      }
    }

    void setODR(){

      dof.setAccelODR(dof.A_ODR_25);
      dof.setAccelScale(dof.A_SCALE_16G);
    }

    void fall(){

      if(-0.08<X && X<0.08){
        if(-0.08<Y && Y<0.08){
          if(-0.08<Z && Z<0.08){

            Serial1.println("N");
            Serial.println("Fallen!");

            loop(); //if condition is met, jump to loop to wait for push button to be pressed again.

            }
          }
        }
      //else{

        printAccel(); //else continue printing sensor data

      //}
    }

However I am having some trouble getting it to work, above is what I have worked out thus far.

title: Getting Push Button Logic To Stick?

Answers: 1

body:
You'll need to store whether the button has been pressed.

    bool buttonActivated = false;

    ...

    void loop(){

      buttonState = digitalRead(buttonPin); //Read push button logic.
      if (buttonState == 1 ) {
        buttonActivated = true;
      }

      if( buttonActivated ) {
        printAccel(); //print sensor data
      }

    }

to deactivate, use:

    buttonActivated = false;


body:
I am currently coding on a Seeeduino Stalker v2.3 - water proof kit.

http://www.seeedstudio.com/wiki/Seeeduino_Stalker_-_Waterproof_Solar_Kit

It is sold with a solar panel to recharge the battery. Unfortunately, I will not have a lot of light where my sensor will be installed and I would like to power the board with a charger from 110V-220V plug and keep the battery only for potential power shortage.

My questions are:

1. What is the best option for connection and charger?

2. I have a previous Arduino Uno charger (9V-1A). Would it work with some linear regulator? What wiring should I use?

3. Any recommendation for a Li-Ion battery that could I buy and that would last longer than this 3.7 V at 1000mA?

Thank you for your help :)

title: How to power a Seeeduino Stalker v2.3 - water proof with charger instead of solar panel

Answers: 2

body:
1. You can charge the battery and power the board, via USB. The CN3063 requires between 4.4V to 6V, so not a huge range of options besides a 5v wall-wart

2. No. 9V would be too high.

3. How many mains power failures / brownouts do you get, where you live?

body:
 1. To be as little invasive as possible, I'd remove just the [solar panel][1] and replace it with a power supply with the same typical voltage (5.5V) and at least the same typical power output (0.5W). It should not be too difficult, nor too expensive. Any USB charger that can provide 5V should do. You can just cut the USB connector and attach the wires to the board. Or be more elegant and create an adapter. Either way should work. And the price should be about a couple of bucks.

 2. Yes, I think it would work, although linear regulators 9V -> 5V are really inefficient. See my proposed solution from the previous point.

 3. On ebay there's [plenty][2] of options, but they might not fit in the box of the seeduino. You have to compare the dimensions of the battery vs whatever extra space might be available.

  [1]: http://www.seeedstudio.com/depot/05w-solar-panel-55x70-p-632.html?cPath=155
  [2]: http://www.ebay.com/sch/i.html?_from=R40&_trksid=p2050601.m570.l1313.TR0.TRC0.H0.Xlipo+3.7v.TRS0&_nkw=lipo+3.7v&_sacat=0


body:
I am starting to use a Seeeduino GPRS shield (please see note), which is essentially an Arduino Leonardo that, among other things, can be used as a mobile 'phone for sending and receiving texts. I have successfully tried the "blink an led" and "fade an led" sketches, so the compiling and uploading are ok

I am using a desktop computer with Linux Fedora 20.

Now I want to go on to use the cell phone network to communicate with my mobile 'phone. However I am puzzled by something I assume everybody else understands already, and that is the references to "select either software serial port or hardware serial port to be connected to GPRS Shield". Please could someone explain what "software or hardware serial port" is, in simple terms, or point me to a web site that does so? Do I need any wired connection with my PC other than the USB link I use for uploading sketches?

Note: I bought a discounted GPRS shield labelled version 1.0a2. All the information on the 'net is of version 1.0 or 2.0 (with no "a2") and photos and diagrams do not correspond with what I have. I am awaiting official documentation, but meanwhile treating it as an Arduino Leonardo seems to be working.

title: Explanation please, of hardware and software serial links

Answers: 3

body:
The hardware serial port is the serial port which connects to the computer this takes up pins 1 and 2 I believe. You can read about this here http://arduino.cc/en/reference/serial.

Software serial ports are only on digital IO pins. You can read more about this here
http://arduino.cc/en/Reference/softwareSerial

You should not need anything other the USB connection port.

body:
A `SoftwareSerial` connection is created using the `UART` pins 7 and 8.

Having the device in `HardwareSerial` mode allows the device to connect to pins 0 and 1, allowing direct control from the serial connection to the computer.

In `SoftwareSerial`, you can communicate with the Arduino Via serial, and the Arduino controls the GPRS shield via uart.

body:
Most small micro controllers, AVR's included, have dedicated hardware for communicating with different serial devices. In arduino these are referenced with "Serial", "Serial1", "Serial2" and so on, depending on how many hardware serial ports your particular arduino has.

Leonardo's are an exception, the first hardware port is "Serial1" and "Serial" refers to the PC's usb connection. On the other arduinos that I know of "Serial" is hardware serial used for PC comms, so using it for other hardware requires sacraficing your PC link.

Software serial ports use the processors more generic pin-change interrupt system to communicate on any pins that support said interrupts, but they have a higher processing overhead and often cannot support the same high speeds as the hardware serial. There are different libraries for Software Serial that have different approaches giving different advantages and drawbacks.

To use a software Serial port you will need to make one to be used in your code, which will look something like this, depending on the type name the library you include uses:

    SoftwareSerial softSerial( txPinNumber, rxPinNumber);

So in short, your processor has dedicated hardware for communicating over serial that should be used first, but if you need more ports the processor can simulate some extras which is referred to as "Software Serial". The documentation to your GPRS shield implies that either will work just fine. You should look at the arduino documentation for your board to see how many ports you have and which pins can be used for serial.

The documentation does not imply you will need any special link to your computer outside of the USB connection.


body:
I want to run the 5V board at 3.3V because I can get the 5V version cheaper than the 3.3V version.

I read that you can power the Arduino Pro Mini with a battery by connecting the battery to the 5V pin, bypassing the regulator.

Somewhere else I read that the only difference between a 3.3V and 5V Pro Mini is the regulator.

Are these assumptions correct? If yes, can I use a 5V Pro Mini like a 3.3V by powering it with a 3V Battery on the 5V pin?

title: Powering a 5V Arduino Pro Mini with 3.3V

Answers: 5

body:
Pro Mini 5V has voltage regulator for 5V and 16MHz quartz.
Pro Mini 3.3V has voltage regulator for 3.3V and 12MHz quartz.

According to manufacturer specification Atmega328 chip powered by 3.3V cannot run 16MHz and needs at most about 13MHz. But it's official specification. Some chips are better than specification (faster) some are worse (slower). So you can try whether **your** Pro Mini is better or not. Or you can change quartz to 12MHz, if you can solder SMD parts.

Or better look for cheaper 3.3V clone, they are not much more expensive as 5V version...

body:
I just discovered that I knew the answer to this, because I was accidentally running some 5v/16MHz Pro Mini boards at 3.3v without issue.

**Short Version**

Yes, you can run one feeding it 3.3v, but you need to program it as a 5v/16MHz board to get the clock speeds right.  Also, all your TTL levels (outputs) will be 3.3v, not 5v.  Additionally, at least in my experience, the processor will run at 16MHz and not 12MHz with 3.3v.

**Background Story**

I had some generic Pro Mini boards that didn't mark their voltage at all, so I tried programming (and running) them using my FTDI at 3.3v using the 3.3v/8mHz option in the Arduino IDE.  I was able to upload programs just fine, but the clock was clearly wrong, as the "Blink" program ran about 2x as fast.  That told me that it was running faster than 8MHz .

So I tried again this time telling the IDE it was a 5v/16MHz chip, and everything ran fine, despite the fact that I was feeding it 3.3v.  I even saw that pin 13 was cycling from 0v up to 3.3v - exactly what I was feeding it.  So for a while I just thought they were 3.3v Pro Minis.

But then thinking about it, I realized that having to tell it to run at 16MHz to get the clock right meant it really was a 16MHz chip - which I didn't think was available with the 3.3v model.

So on a whim (and since I have a ton of these little boards), I changed my FTDI to 5V, and was able to run and program the board just fine.

So from that, I conclude that yes, you can run them at 3.3v, but your TTL levels will be just 3.3v.

body:
First I am going to say **it is very much possible.** Allow me to explain.

The 5v version can be powered with 3.3v, but it is **not recommended** to supply power through the 5v pin, bypassing the regulator. **Only *regulated* 5v power should be supplied through the 5v pin. Any other voltage levels should go in the RAW pin.** If you supply the Arduino Pro Mini 5b with 3.3v the chip will only be underclocked to 8-12MHz, and the voltage for Vcc (the board's operating voltage and what it will power its pins with) will be 3.3v; but there is another way.

I primarily source my components from [SparkFun][1] due to their reliability, cheap price and awesome support. They provide the Arduino Pro Mini in [3.3v][2] and [5v][3] variants for only $10. I have used both variants for many purposes, but primarily when working with embedded and small solutions. One of those times I was accessing sensors that ran on 5v TTL logic, but I didn't have room to place a >5v battery, only room for a LiPo (which generally powers 3.3v).

I was able to solve this issue with a [SparkFun 5v Step-Up Breakout][4]*, which boosts the voltage to 5v without any other major issues. I should warn you that there are some issues you could face if you are using a LiPo to feed into the Step-Up. Even if you aren't I'll list it here for reference. The Step-Up's maximum safe input voltage is 4v, and can be a bit unreliable if the voltage goes above it. Unfortunately a LiPo's discharge curve places it above 4v when it is within the upper 95% soc (state-of-charge), so a 3.3v regulator ([which SparkFun also sells][5]) would be needed to reliably power an Arduino Pro Mini 5v through a Step-Up breakout (at least in my experience). Also, power from a Step-Up breakout is regulated.

*Pololu also sells a [comparable Step-Up][6] that could handle an input up to 5.5v in theory, but I haven't personally used it.

  [1]: https://www.sparkfun.com
  [2]: https://www.sparkfun.com/products/11114
  [3]: https://www.sparkfun.com/products/11113
  [4]: https://www.sparkfun.com/products/10968
  [5]: https://www.sparkfun.com/products/526
  [6]: https://www.pololu.com/product/2564

body:
> If yes, can I use a 5V Pro Mini like a 3.3V by powering it with a 3V Battery on the 5V pin?

two options (at least):

1) apply 3.3v at the regulator *output* pin. there may be already a break-out for that on the board;

2) solder in a 3.3v regulator in place of the 5v regulator -> fairly easy to do as well.

body:
Im feeding 5V pro mini clone with 2 AA battery, to VCC pin, about 3V and it works normally. It consumes few current compared to 5V. [![consuming at 3V][1]][1] [![at 5V][2]][2]
And you can see what it the setup in [here][3].
Also [this][4] video can be useful.

  [1]: https://i.stack.imgur.com/CwZiJ.jpg
  [2]: https://i.stack.imgur.com/Lb51E.jpg
  [3]: https://twitter.com/anunidentified/status/1069283092135845888?s=19
  [4]: https://youtu.be/381Rg5YDmRM


body:
So I am trying to test what will eventually be a Arduino controlling 3 110V motors that are currently controlled by an analog pot. But more on that later.

I am trying to test out using a digital pot (never have before) and am running into some issues with tutorials I have found online. For now, I want to control a LED with the digital pot ([Spec Sheet][1]) so that the LED fades in and fades out in a continuos loop.

Here is the [tutorial I followed][2]. It uses a different chip model but it seems from the pot I am using that the pins are the same. (I could be wrong?)

I double and triple checked the wiring and it matches below.

![Wiring Diagram][3]

Here is the code I am running (slightly modified from the tutorial, also tried the tutorial code)

    #include <SPI.h>
    byte address = 0x11;
    int CS= 10;
    int i=0;

    void setup()
    {
      pinMode (CS, OUTPUT);
      SPI.begin();
    }

    void loop()
    {
        for (i = 0; i <= 128; i++)
        {
          digitalPotWrite(i);
          delay(10);
        }
        delay(500);
        for (i = 128; i >= 0; i--)
        {
          digitalPotWrite(i);
          delay(10);
        }
    }

    int digitalPotWrite(int value)
    {
      digitalWrite(CS, LOW);
      SPI.transfer(address);
      SPI.transfer(value);
      digitalWrite(CS, HIGH);
    }

As a result of the two above, I have an LED that stays lit (at about 50% it seems) and does not fade in/out at all.

Being relatively new to wiring and EE in general, is there a better way to replicate an analog pot without using a digital pot? Can I just use PWM to control it? Why would the LED be just staying lit?

Thanks!

  [1]: http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Components/General IC/22060b.pdf
  [2]: http://www.instructables.com/id/Digital-Potentiometer-MCP41100-and-Arduino/?ALLSTEPS
  [3]: https://i.stack.imgur.com/urSnK.jpg

title: Digital Potentiometer not fading LED

Answers: 1

body:
After studying the datasheet differences between **MCP41100** (digital pot used in the tutorial) and **MCP4131** (the one you get), I found **two major differences** between both:

1. Difference in **resolution**:
   - MCP41100 has **257 steps** resolution (8 bits + 1): you can see that at the beginning of [its datasheet][1]
   - MCP4131 has only **129 steps** resolution (7 bits + 1): you can get this information on page 2 of [its datasheet][2]

2. Difference in **commands formats** sent through SPI; both use one "command byte" followed by a "data byte", but have a diffrent format for their command byte:
   - MCP41100 command byte is `X X C1 C0 X X P1 P0` where `X is unused`, `C1 C0` is one of 4 possible commands,  only 2 being valid commands actually: `01` (Write data), `10` (Shutdown), finally `P1 P0` should be always `01` for an MCP41100
   - MCP4131 command byte is `AD3 AD2 AD1 AD0 C1 C0 D9 D8`, where `AD3-AD0` is the address of the "register" on which to perfom a command. For the MCP4131, the most important address is `00` which means "volatile wiper 0" (this is what allows you to change the resistance value of the pot), `C1 C0` is one of 4 possible commands (read data, write data, increment, decrement), in your example the command should be `00` (write data); finally `D9 D8` are the high order bits of the value to write to the register, but `D9` is unused and should always be `0`. For 257-steps pots, `D8`is used to have the full resistance scale, otherwise it should be `0`

Now that we know aht your MCP4131 expects as commands passed through SPI, we can take a look at what the tutorial program passes:

    00010001 value

The first byte can be broken down as such:

- `0001` address of the pot **wiper register 1** (**not 0**): this wiper does not exist on MCP4131 hecne writing to it will have no impact...
- 00 command bits meaning "Write to register specified in previous address"
- 01 high order bits (D9-D8) of the value to write to the wiper register.

Although I don't have an MCP4131 at hand, I think you should adapt the program as follows:

    byte address = 0x00;

And that should be fine! Indeed, now your program passes:

    00000000 value

Which means "write `value` (between `0` and `128` which matches exactly the 129 steps resolution) to the wiper register 0 of the port".

Note that the MCP4131 has more features than the MCP41100 in terms of commands, for instance you could use the special commands "increment" and "decrement", with the advantage they need only one byte (the command byte), e.g.

    void loop()
    {
        for (i = 0; i <= 128; i++)
        {
          digitalPotIncrement();
          delay(10);
        }
        delay(500);
        for (i = 128; i >= 0; i--)
        {
          digitalPotDecrement();
          delay(10);
        }
    }

    void digitalPotIncrement()
    {
      digitalWrite(CS, LOW);
      SPI.transfer(0x04);
      digitalWrite(CS, HIGH);
    }

    void digitalPotDecrement()
    {
      digitalWrite(CS, LOW);
      SPI.transfer(0x08);
      digitalWrite(CS, HIGH);
    }

  [1]: http://www.futurlec.com/SFMicrochip/MCP41100.shtml
  [2]: http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Components/General IC/22060b.pdf


body:
I have a demo that spins a motor, but the leads on my motor broke. I happen to have another motor lying around that I'd like to swap in, but it's of a different type. Here's my circuit:

![Spin Motor Spin from Node-Ardx][1]

This is the old (broken) motor: https://www.sparkfun.com/products/11696. It has an operating voltage range of 1.0 to 3.0V DC and a no load speed of 6600±10% RPM (@1.0V DC, 110mA).

The new motor that I'd like to use is part of this kit: https://www.sparkfun.com/products/12866. It's a 6VDC motor with a No Load Speed of 90±10rpm and a No Load Current of 190mA(max.250mA).

I'm running this off a Sparkfun Redboard, which is UNO R3 compatible.

Can I swap in the new motor without any circuit changes? Will I have to add additional power for the new motor? Or should I change the circuit with a larger resistor or something else?

  [1]: https://i.stack.imgur.com/ccBRT.png

title: Can I use this replacement motor without modifying the circuit?

Answers: 1

body:
Regarding voltage, I think there should be no problem as the datasheet for your replacement motor specifies a "suggested voltage 4.5V DC".

However, be careful that there is another important value in motor datasheets: the **stall current**.

Simply stated, this is the current consumed by the motor when it tries to rotate but is unable to, due to its too low torque in comparison with the effort needed for rotation, e.g. if it tries to rotate the wheel of a robot that is too heavy.

The original motor has a stall current of 0.8A according to its datasheet (you can get it from the link you provided).

Your replacement motor has 1A according to the link you provided.

These 200mA can make a big difference for the transistor used in your circuit, a **P2N2222A**.

Indeed, that transistor is [specified][1] to switch a maximum of **600mA** current at the collector.

So in the best case, the motor will run correctly without load, but if you provide some load that makes it stall, then the transistor will raise temperature (you could sense that by approaching your finger) and ultimately would get toasted.

Please also note that some poorly designed motors may consume a current near the stall current, due to internal friction (I have already almost grilled a transistor this way...)

So my answer is:

- you can do it for a simple experiment with no load on the motor
- if you really want to do something with the motor, take another transistor with a higher *Ic* current

  [1]: https://cdn.sparkfun.com/datasheets/Components/General/P2N2222A-D.PDF


body:
I am making a tiny game, and want to store high-scores. I made a Highscore-class in the top of the sketch file, like this:

    class Highscore {
    public:
      String name;
      int score;

      String toString() {
        return this->name + " - " + (String)score;
      }

      Highscore(String name, int score) {
        this->name = name;
        this->score = score;
      }
    };

    setup() { // etc

Now. Near the bottom of the sketch, I have a function I want to take a Highscore-object as a parameter, but the compiler will not let me. Example:

    void writeHighscore(Highscore hs) {
      File f = SD.open("high.txt", FILE_WRITE);
      // Do stuff

The complation error is as follows:

> sketch.ino:19:21: error: variable or field ‘writeHighscore’ declared void

sketch.ino:19:21: error: ‘Highscore’ was not declared in this scope

sketch.ino: In function ‘void setup()’:

sketch.ino:64:20: error: ‘writeHighscore’ was not declared in this scope

After changing parameter type to String, int or whatever, all the errors go away. I am able to create Highscore-objects INSIDE the `writeHighscore()` function, but how can I pass objects to it?

**Edit 1 - Object creation**

    Highscore hs = Highscore("John", 975);
    Serial.println(hs.toString()); // Prints "John - 975" as expected
    writeHighscore(hs); // Error

title: How can I pass an object as a parameter to a function?

Answers: 2

body:
You are doing everything right, but you need to move the class outside of your .ino file for this to work. <del> I'm not sure why the arduino IDE makes you do this </del> (see edit) , but it is something I've run into before.

I just tested this, and moving the class declaration outside the ino and into a header file in the project folder makes it compile correctly. Just remember to include the header you make in the ino and to `#include "Arduino.h"` in the header to get access to "String" again.

Technically, only a forward declaration of the class needs to be in a different file.

**Edit:**

I'm relatively sure what is happening is the IDE is generating forward declarations for all your functions but not the class, which are placed before your class definition.
This means that breaking the function regex the IDE uses with a dummy "throw()" fixes your problem. for example:

    void writeHighscore(Highscore hs) throw() { ...

should work just fine (it worked for me)

body:
<!-- language-all: lang-C++ -->

This is a classic example of the IDE "helping" you by generating function prototypes, and not doing it very well. Example code to reproduce:

    class Highscore {
    public:
      String name;
      int score;
      String toString() {
        return this->name + " - " + (String)score;
      }

      Highscore(String name, int score) {
        this->name = name;
        this->score = score;
      }
    };

    void setup () { }
    void loop () { }

    void writeHighscore(Highscore hs)
    {
    // do stuff
    }

This gives the error:

    sketch_jul06b:4: error: variable or field ‘writeHighscore’ declared void
    sketch_jul06b:4: error: ‘Highscore’ was not declared in this scope

---

If you look at the output of the IDE preprocessor (you can do this by turning on verbose compilation, and finding out the name of the file it is actually compiling) you see this:

    #line 1 "sketch_jul06b.ino"
    #include "Arduino.h"
    void setup ();
    void loop ();
    void writeHighscore(Highscore hs);
    #line 1
    class Highscore {
    public:
      String name;
      int score;
      String toString() {
        return this->name + " - " + (String)score;
      }

      Highscore(String name, int score) {
        this->name = name;
        this->score = score;
      }
    };

    void setup () { }
    void loop () { }

    void writeHighscore(Highscore hs)
    {
    // do stuff
    }

The important part is that it put:

    void writeHighscore(Highscore hs);

**before** where the class is declared.

---

You can fix the error by simply generating your own function prototype like this:

    void writeHighscore(Highscore hs);  // function prototype
    void writeHighscore(Highscore hs)
    {
    // do stuff
    }

Now it compiles without errors. It detects your *own* function prototype, and therefore does not generate its own. The first few lines of the generated file are now:

    #line 1 "sketch_jul06b.ino"
    #include "Arduino.h"
    void setup ();
    void loop ();
    #line 1

That troubling prototype has gone.


body:
I'm trying to get my LED matrix to run Conway's Game of Life. After 4 different pin configurations, I've finally been able to run a separate test code, that lights all the LED's in order, and then turns them off in order (Code Below). I've written the entirety of GoL in C#, but the Arduino language is just different enough to where I can write sort of ok in it, but not enough to understand what's going wrong. I got a Game of Life code from [here][1] and it won't even light my LEDs, or when it does, it's incredibly dim, unlike my test code. I'll show my pin layout in the code. I've tried changing the pins in the GoL code, copying the setup from one to the other, and  but for the life of me, I can't seem to figure out why one would light up the LED's without a hitch, and the other is struggling. Can anybody see the changes I'd need to make that would make the GoL code at that link, work like this test code?

Here's my Test code that works fine:

    int speed = 4; //the delay time in milliseconds

    int pauseDelay = 1;    //the number of milliseconds to display each scanned line

    //Pin Definitions
    int rowA[] = {14,15,16,17,2,3,4,5};          //An Array defining which pin each row is attached to
                                         //(rows are common anode (drive HIGH))
    int colA[] = {6,7,8,9,10,11,12,13};  //An Array defining which pin each column is attached to
                                         //(columns are common cathode (drive LOW))

    //The array used to hold a bitmap of the display
    //(if you wish to do something other than scrolling marque change the data in this
    //variable then display)
    byte data[] = {0,0,0,0,0,0,0,0};

    //Setup runs once when power is applied
    void setup()
    {
      Serial.begin(9600);         //Open the Serial port for debugging
      for(int i = 0; i <8; i++){  //Set the 16 pins used to control the array as OUTPUTs
        pinMode(rowA[i], OUTPUT);
        pinMode(colA[i], OUTPUT);
      }
    }

    //repeats
    void loop()
    {
     //Example #1 - test pattern
     //Run a small test program which lights up each light in time
      test();

     //Example #2 - static image
     //Display a defined bitmap
    /*
      data[0] = B10101010; //row 1s bit mask (1 LED is on 0 LED is off)
      data[1] = B01010101; //row 1s bit mask (1 LED is on 0 LED is off)
      data[2] = B10101010; //row 1s bit mask (1 LED is on 0 LED is off)
      data[3] = B01010101; //row 1s bit mask (1 LED is on 0 LED is off)
      data[4] = B10101010; //row 1s bit mask (1 LED is on 0 LED is off)
      data[5] = B01010101; //row 1s bit mask (1 LED is on 0 LED is off)
      data[6] = B10101010; //row 1s bit mask (1 LED is on 0 LED is off)
      data[7] = B01010101; //row 1s bit mask (1 LED is on 0 LED is off)
      showSprite(speed);
    */
     }

    //An array to store power values to act as bit masks
    const int powers[] = {1,2,4,8,16,32,64,128};

    //Runs a pattern where each LED is lit one after another
    void test(){
      for(int i = 0; i < 8; i++){
    for(int ii = 0; ii< 8; ii++){
    data[i] = data[i]+ powers[ii];   //Goes through each row of lights lighting each column one after another
    showSprite(speed);
    }
      }

      for(int i = 0; i < 8; i++){
       for(int ii = 0; ii< 8; ii++){
    data[i] = data[i] - powers[ii];   //Goes through each row of lights turning off each column one after another
       showSprite(speed);
        }
      }
    }

    void showSprite(int speed2){
     for(int iii = 0; iii < speed2; iii++){                 //show the current frame speed2 times
      for(int column = 0; column < 8; column++){            //iterate through each column
           for(int i = 0; i < 8; i++){
               digitalWrite(rowA[i], LOW);                      //turn off all row pins
       }
       for(int i = 0; i < 8; i++){ //Set only the one pin
         if(i == column){     digitalWrite(colA[i], LOW);}  //turns the current row on
         else{                digitalWrite(colA[i], HIGH); }//turns the rest of the rows off
       }

       for(int row = 0; row < 8; row++){                    //iterate through each pixel in the current column
        int bit = (data[column] >> row) & 1;
        if(bit == 1){
           digitalWrite(rowA[row], HIGH);                   //if the bit in the data array is set turn the LED on
        }

       }
       delay(pauseDelay);                       //leave the column on for pauseDelay microseconds (too high a delay causes flicker)
      }
     }
    }

[1]: http://brownsofa.org/blog/2010/12/30/arduino-8x8-game-of-life/

title: What in the example code is different from my test code? LED matrix lights up differently

Answers: 1

body: I ended up using a different PIN layout, and the GoL code had the pins As anodes where they were Cathodes in the other code. Switched rows pins to Columns pins in the code and Problem solved.


body:
Would it be possible to have an Arduino write directly to a MySQL database?

I'm a web programmer, so I'm familiar with how to get records from a MySQL database. I have MAMP installed on my mac, so I have the ability to build an interface, directly in the web browser, that retrives the records from a MySQL database.

What I'm thinking is to connect the Arduino directly to my computer via USB, and write data from the sensors, or the pins, directly to my MySQL database.

I'm using two phototransistor to record whenever something blocks the light. Each sensor records individually a timestamp for when the blocking occur.

Is that possible?

title: Have Arduino write data to a MySQL database?

Answers: 2

body:
It's possible if you forget about the Arduino directly writing to the database.

Simply put, the Arduino is restricted to a serial connection.  To directly communicate with MySQL you would need a network connection, and then implement the MySQL protocol - a huuuge amount of work.

The normal way is to have an adapter program running on the PC which receives data from the Arduino over the serial connection, then performs any insert, select, etc instructions on the MySQL for you.

There is a "MySQL Connector" available* (https://launchpad.net/mysql-arduino) but of course that requires you to have an active network connection of some form to your Arduino.  Remember that the Arduino (certainly the Uno) is very limited on memory and program space, so having the Arduino connect direct, and doing anything else, might be mutually exclusive.

-----
*Nice find, @SomeHardwareGuy...

body:
You can do that using an Arduino Yun: the Yun has a linux cpu paired with the ATMega32U4, so you can delegate things like accessing a mysql database, either local or remote.

Take a look at this [instructable][1].

There are different ways for delegating logging sensors readings to the linux side and have them stored on a mysql: the easiest is to code a short python script and call it from the sketch using [Process][2].

  [1]: http://www.instructables.com/id/Control-Access-of-Arduino-YÚN-with-MySQL-PHP5-and-/?ALLSTEPS
  [2]: http://arduino.cc/en/Tutorial/Process


body:
Can the Arduino Mega2560 use the [New Haven NHD-0420D3Z-NSW-BBW-V3][1] LCD panel by controlling it with the [New LiquidCrystal library][2]? What cable will you use to connect the LCD to Arduino, are there screw terminals on the LCD board to secure the connections? It seems like only 4 connections are needed, for `GND`, `VCC`, `SDA`, `SCL`.

  [1]: http://www.newhavendisplay.com/nhd0420d3znswbbwv3-p-5745.html
  [2]: https://bitbucket.org/fmalpartida/new-liquidcrystal

title: Can the Arduino use this i2c LCD Panel

Answers: 1

body:
Unfortunately you cannot control that display using that library; the library expects to be connected to a HD44780-compatible driver but the display uses a fully custom control scheme. You may be able to adapt the library to the scheme, but I have not looked at that specifically.

I2C itself only requires 3 connections: SDA, serial data; SCL serial clock; GND, ground reference. Since the display is not powered separately it also requires power, in this case 5V. Since the display can only communicate at 100kHz you don't need to be *too* terribly concerned about cable quality; Cat3 or even telephone cable is acceptable as long as you don't exceed a few feet in length. Don't forget the external pullup resistors though, on SDA and SCL.


body:
I want to know if there is a way to install/use the [PBC library][1] on Arduino UNO. I want to implement some cryptographic primitives using PBC library.

Thank you.

  [1]: http://crypto.stanford.edu/pbc/

title: Using PBC library on Arduino

Answers: 1

body:
You could use the [RELIC][1] toolkit. It has PCB and they have scripts to compile for Due and Mega. I'm not sure if you could use this with Uno. But this library targets resource-constrained devices.

  [1]: https://github.com/relic-toolkit/


body:
I've been trying to get an Arduino (I have a Mega and Uno lying around) to read values from a small array of 3 [ColorPal 20380][1], which individually, work as intended with some reflective material. The [demo][2] gives no problem, but I am confused as to how to approach activating all the 3 sensors and reading the 3 different sets of values so that I can analyze them in a program on the Arduino.

**How can I get all three sensors to output data to my program in parallel?** I want to use the values at the same point in time on all three sensors to do some calculations in my program. Should I approach something like a state machine? Or at least near-parallel (a few ms delay is fine too)? How would an example look like?

The most confusing thing for me is the non-inverted, open-drain protocol it uses. From the documentation:

> Because of the open-drain protocol, the pin used to communicate with the ColorPAL should always be configured as an input, except when being driven low. Also, when starting up, you should wait for this pin to be pulled high by the ColorPAL before trying to send it any commands.

I tried modifying the demo to something silly in sequence like this just to see how it would work in the Arduino but I got nothing (pins 2, 4 and 6 are the data pins):

    /* ColorPal Sensor Example for Arduino
      Author: Martin Heermance, with some assistance from Gordon McComb
      This program drives the Parallax ColorPAL color sensor and provides
      serial RGB data in a format compatible with the PC-hosted
      TCS230_ColorPAL_match.exe color matching program.
    */

    #include <SoftwareSerial.h>

    int sio = 0;
    const int unused = 255;   // Non-existant pin # for SoftwareSerial
    const int sioBaud = 4800;
    const int waitDelay = 10;

    // Received RGB values from ColorPAL
    int red;
    int grn;
    int blu;

    // Set up two software serials on the same pin.
    SoftwareSerial serin = SoftwareSerial(sio, unused);
    SoftwareSerial serout = SoftwareSerial(unused, sio);

    void setup() {

      // Unoptimized setup

          sio = 2;
          serin = SoftwareSerial(2, unused);
          serout = SoftwareSerial(unused, 2);
          Serial.begin(9600);
          reset();      // Send reset to ColorPal
          serout.begin(sioBaud);
          pinMode(2, OUTPUT);
          serout.print("= (00 $ m) !");       // Loop print values, see ColorPAL documentation
          serout.end();     // Discontinue serial port for transmitting

          serin.begin(sioBaud);           // Set up serial port for receiving
          pinMode(2, INPUT);

          sio = 4;
          serin = SoftwareSerial(4, unused);
          serout = SoftwareSerial(unused, 4);
          Serial.begin(9600);
          reset();
          serout.begin(sioBaud);
          pinMode(4, OUTPUT);
          serout.print("= (00 $ m) !");
          serout.end();

          serin.begin(sioBaud);
          pinMode(4, INPUT);

          sio = 6;
          serin = SoftwareSerial(6, unused);
          serout = SoftwareSerial(unused, 6);
          Serial.begin(9600);
          reset();
          serout.begin(sioBaud);
          pinMode(6, OUTPUT);
          serout.print("= (00 $ m) !");
          serout.end();

          serin.begin(sioBaud);
          pinMode(6, INPUT);
    }

    void loop() {

      sio = 2;
      serin = SoftwareSerial(sio, unused);
      serout = SoftwareSerial(unused, sio);
      readData();

      sio = sio + 2;
      serin = SoftwareSerial(sio, unused);
      serout = SoftwareSerial(unused, sio);
      readData();

      sio = sio + 2;
      serin = SoftwareSerial(sio, unused);
      serout = SoftwareSerial(unused, sio);
      readData();
    }

    // Reset ColorPAL; see ColorPAL documentation for sequence
    void reset() {
      delay(200);
      pinMode(sio, OUTPUT);
      digitalWrite(sio, LOW);
      pinMode(sio, INPUT);
      while (digitalRead(sio) != HIGH);
      pinMode(sio, OUTPUT);
      digitalWrite(sio, LOW);
      delay(80);
      pinMode(sio, INPUT);
      delay(waitDelay);
    }

    void readData() {
      char buffer[32];

      if (serin.available() > 0) {
        // Wait for a $ character, then read three 3 digit hex numbers
        buffer[0] = serin.read();
        if (buffer[0] == '$') {
          for(int i = 0; i < 9; i++) {
            while (serin.available() == 0);     // Wait for next input character
            buffer[i] = serin.read();
            if (buffer[i] == '$')               // Return early if $ character encountered
              return;
          }
          parseAndPrint(buffer);
          delay(10);
        }
      }
    }

    // Parse the hex data into integers
    void parseAndPrint(char * data) {
      sscanf (data, "%3x%3x%3x", &red, &grn, &blu);
      char buffer[32];
      sprintf(buffer, "R%4.4d G%4.4d B%4.4d", red, grn, blu);
      Serial.println(buffer);
    }

[1]: http://www.parallax.com/product/28380
[2]: http://learn.parallax.com/colorpal-arduino-demo

title: Read data from 3 ColorPal 28380 simultaneously on Uno/Mega

Answers: 2

body:
I'm doing something similar with you right now. I'm troubleshooting this right now so we can collaborate.

First of all, even though you have setup 3 pins, you're only telling the Arduino to read only 1 sensor because they're using the same variable (pin6 since it's the last one you set up). You have to declare each pin with a different variable then create 2 more readData() functions to read each pin as a start. But even after I set it up with that, it only read one colorpal. Reading up a little more on the Uno board, it seems that only pin 2 and 3 can do serial interrupt which we need to use to communicate with the ColorPal. I'm not 100% sure as I'm a novice still, but from what my analysis and research shows, that's the problem right now. I'll update if I find anything.

body:
Try using `serin.listen()` for each SoftwareSerial before using `serin.read()`.

Only one pin can be read at a time and by default it's reading from the last pin initialized.


body:
Basic question: How far do I have to go to assure that integer math is done correctly? For example, this is probably overdone:

    unsigned long burnTime = 0UL;
    unsigned long curBurnTime = 0UL;
    // Do some stuff that sets the above variables to millis() at various times
    // Later on...
    unsigned long adjustedBurnTime = (unsigned long) ((burnTime + curBurnTime) / 1000UL);

Would the math be done correctly if I went to a more minimal last statement (since all the elements of the equation are unsigned longs)? Like this:

    unsigned long adjustedBurnTime = ((burnTime + curBurnTime) / 1000UL);

Or even:

    unsigned long adjustedBurnTime = ((burnTime + curBurnTime) / 1000);

title: Assuring an unsigned long int?

Answers: 1

body:
Any good C manual will tell you the result type for each basic math operation on given types. But briefly, the basic math operators return a result as wide as the widest operand, with the narrower operand being widened to match the wider one, if they differ. The same with assignment: assigning a result of a given type to a variable of the same type will not involve any conversion.

tl;dr: No, you're not missing anything. You don't need any casts in your example.

PS: One thing you do need to be aware of is whether any of your intermediate results will overflow the arithmetic type you're using. For example, the final result may be not exceed an unsigned long but the expressions `(burnTime + curBurnTime)` must also not exceed it. This is a greater concern with smaller data-types, of course.

PPS: Good on you for tackling fixed point arithmetic rather than just reaching for the floating-point library!


body:
I am creating a tiny game on my Arduino UNO with an Adafruit ST7735 1.8" TFT / SD breakout. I am performing screen operations using the built-in TFT-library.

The problem is screen flickering. Even though I take care to prepare data and minimize the time between clearing the screen and writing the new stuff to it, the screen "refresh()" is significant. I heard someone mention something called double buffering, so I read a bit up on it, but I am frankly clueless on how to implement it on an Arduino UNO.

Is it possible to implement double buffering on an Arduino UNO to prevent screen flickering, and if so, how?

Libraries used:

    #include <TFT.h>
    #include <Wire.h>
    #include <SPI.h>
    #include <SD.h>

<br>The screen is "cleared" like this:

    screen.background(0,0,0);  // Clear it
    screen.text(buf, 10, 25);  // Write new stuff

title: How can I implement double buffering with an Arduino UNO?

Answers: 3

body:
If you're already preparing the next screen's-worth of data before you clear the screen, then double buffering won't help. In that case, the time taken to re-write the screen data is what causes the flicker, and the only way to improve it is to write the screen faster. If the software is to blame, it will be in screen.text(). If the software is already driving the hardware as fast as the hardware will go, then that's the best you can do.

Double-buffering would let you prepare the next screen while the currently-prepared one is loading (and will require interrupt-driven I/O to do it). The result would be more screen refreshes per unit time, but it doesn't sound like that is your problem.

One easy experiment to try is to not clear the screen before you re-write it, if that is possible to do. Then your next screen will overlay the current screen with (we hope...) no blanking period. That might prevent the blinking.

body:
> How can I implement double buffering with an Arduino UNO?

Full screen [double buffering][1] (aka [off-screen bitmap][2]) for an ST7735 (128 x 160 x 16 bit color) would require 40 Kbyte. With only 2K byte SRAM on the Arduino Uno double buffering is not possible.

Some of the flickering is due to the Arduino core unoptimized SPI protocol and the graphics library. They could be optimized to reduce some of the flickering.

Please see the Cosa [ST7735][3] driver and [SPI][4] support for examples of high speed inter-leaving SPI transfer and graphics optimizations.

Smaller mono-chrome screens (such as ST7565) can be supported with double buffering. An example is the Cosa [OffScreen Canvas][5] that can be used to create a bitmap that is transfered to the screen in a [single operation][6].

Cheers!

  [1]: https://en.wikipedia.org/wiki/Multiple_buffering
  [2]: https://stackoverflow.com/questions/7347367/whats-concept-of-off-screen-bitmap
  [3]: https://github.com/mikaelpatel/Cosa/tree/master/libraries/ST7735
  [4]: https://github.com/mikaelpatel/Cosa/blob/master/cores/cosa/Cosa/SPI.hh
  [5]: https://github.com/mikaelpatel/Cosa/blob/master/libraries/Canvas/Canvas/OffScreen.hh
  [6]: https://github.com/mikaelpatel/Cosa/blob/master/examples/LCD/CosaST7565/CosaST7565.ino#L157

body:
To add to previous answers:

Double-buffering is an approach where you _write to the actual device_ - but in an off-screen area. Then you switch to the new area in a single instruction, indistinguishable to the naked eye, rather than clear the visible area and write while it's still being displayed.

This requires that the _device_ has extra memory to support the two areas: on-screen and off-screen. Absent that extra memory, then the best that you can do is pre-calculate as much as possible, and write to the screen as fast as possible.


body:
I want to split this:

    char* value = "12;32;blue";
    or
    string value = "12;32;blue";

into this vars:

    TV = 12;
    AR = 32;
    LED = "blue";

is it possible?

title: How to split in string

Answers: 2

body:
Scan function should do the job.

    int tv, ar;
    char color[10];
    sscanf(value, "%d;%d;%s", &tv, &ar, color);

body:
For C-strings (`char*`), your best option (in terms of performance and memory consumption) is to use [`strtok`][1]:

    char* value = "12;32;blue";
    char* token = strtok(value, ";");
    int TV = atoi(token);
    token= strtok(0, ";");
    int AR = atoi(token);
    token = strtok(0, ";");
    char* LED = token;

**Note 1**: the code above takes it for granted that `value` is properly formatted, i.e. contains 3 parts split by `;`. If it is not sure, then you should add additional checks on `token` value returned by `strtok`.

**Note 2**: `strtok` is modifiying its `value` argument, so that at the end of the code above, `value` will not be equal to `12;32;blue` any longer.

**Note 3**: `LED` variable above will point directly to the character `b` inside `value`, which means that if `value` is modified afterwards, `LED` might be modified as well.

  [1]: http://www.cplusplus.com/reference/cstring/strtok/


body:
I have a water flow sensor with Arduino Megs 2560 board. I am trying to conceptualize the concept to calculate amount of water getting dispensed esp. in 1,2,3,4 and 5 liters quantity.

Water flow sensor specification:

http://www.seeedstudio.com/wiki/images/b/b7/Water_flow_sensor_datasheet.pdf

I would connect the sensor input to any pin from 22-53 pin.

Suppose I connect to ping 23 so in my setup() function I would add:

    attachInterrupt(23, pulseCounter, FALLING);

where pulseCounter is an interrupt function triggered on each signal generated from sensor and increments a variable

    void pulseCounter()
    {
      // Increment the pulse counter
      pulseCount++;
    }

Now how do I calculate the flowrate and water dispensed in milliliters using this information?  How do I know the freqz of the MCU (which is required as water dispensed per pulse is different for different MCUs)?

title: Measure Water Flow in literes using Arduino Mega 2560 Board and Water Flow Sensor

Answers: 1

body:
the pulse rate can be derived without knowledge of the CPU clock speed. To achieve the pulse rate from your sensor input you can do two things:

 1. count the pulses **dn** within a certain (i.e. fixed) interval **T** of time) or
 2. measure the time **dt** between two pulses.

I'll come back later on this concerning accuracy.

To measure time, you can use the function millis(). This function returns you the milliseconds since bootup as an integer upon calling it. Method 2 is rather simple to implement.

 - Setup three global integers *a*, *b* and *c*.
 - At the end of setup set *a* to current millis();
 - In your ISR set b to current millis();
 - Also in ISR: set a=b;
 - calculate *c=b-a* (i.e. your **dt**);

c holds your current full wave pulse length in milliseconds, which is updated every pulse. You can derive your flow then from it.

The first method uses a counter as demonstrated in your suggestion. You then need a timer outside your ISR, two variables *d* and *e*. Either you poll millis() in your main "loop()" or you install a timer interrupt, both will work here.

 - At the end of setup set *d* to current millis();
 - If your predefined time **T** is passed (by comparing *d* with millis(),
 - save your counted pulses to *e=pulseCount*
 - reset: *pulseCount=0*

*e* holds your pulse count during interval **T**, from which you can derive your pulse rate.

Accuracy
---
Method 1's accuracy increases with higher **T** and higher flow speeds. Therefore the update rate of your measurement is low. By changing **T** you can easily increase accuracy on cost of responsiveness. This is perhaps a good idea, if you have pulsating flows in your tubings, or the sensor is a bit rattling.

Method 2's accuracy increases with lower flow speeds. It is best to measure very low flow speeds. Update frequency is minimal (1/**dt**).

Regarding this sensor you should calibrate it yourself. It is a cheap and rugged device (I'm using it, too), but its output depends on several parameters like mounting position, fluid viscosity and so on. Make sure, there are no bubbles, foam or contaminants in your fluid systems as they garble the results effectively.

n.b.: make sure to take care of an overflow of millis().


body:
I want to use a proto shield (brand is unimportant) and solder some components to it, to make something more premanent than using a breadboard.

My question is can the components be soldered directly to the middle area where there are a lot of small holes?

I would assume this is possible, but everywhere I look people add mini breadboards to their proto shields.

If it's possible, then I assume components and wires can't just be connected in a row like on a breadboard and would instead need some solder between 2 holes where for example a component and seperate wire are connected?

title: Proto Shields wthout breadboard?

Answers: 1

body:
There are many different types of photo-shields, sometimes they have interconnected rows or they just have individual solder holes or even breadboards.  What you get all depends on what you are doing.  My personal favorite are the interlocked rows so I buy that and use a breadboard while I am developing my project then take off the breadboard and solder everything into place.

[Example of non interlocked rows][1]  and an [My favorite proto-shield, it has a little of both kinds][2]

  [1]: http://www.amazon.com/Ventisonic®-MEGA2560-Prototype-ProtoShield-breadboard/dp/B00K992NTI/ref=sr_1_2?ie=UTF8&qid=1416068414&sr=8-2&keywords=protoshield arduino mega
  [2]: http://www.amazon.com/MEGAshield-KIT-Arduino-MEGA-2560/dp/B006SJSBBM/ref=sr_1_1?ie=UTF8&qid=1416068735&sr=8-1&keywords=MEGAshield KIT for Arduino MEGA 2560 R3


body:
I'm using an Arduino Uno with Funduino I2C 1602 LCD display. The LCD display is connected as

LCD

SCL--> A5
SDA -->A4

I need to measure the temperature, pressure and the velocity of a duct flow. So I connected a BMP180 to my arduino with the following connection

SCL--> A5
SDA -->A4

As you can see, both of them are connected to same pins. The connection works fine just for BMP180 but when I add a rotary encoder and print its value on LCD, I'm getting delayed and wrong data.

I'm using this BMP180 library
https://github.com/adafruit/Adafruit_BMP085_Unified

The LCD uses this library (v1.2.0)

https://bitbucket.org/fmalpartida/new-liquidcrystal/downloads

how can I change bmp180 or LCD analog pins in these libraries?

title: Custom Library Pin Change

Answers: 0


body:
Is it possible to use an Arduino, connected to a 3 axis accelerometer, to estimate a platform's continuous change in position and orientation? I have a small mobile robot, and given an initial position and velocity vector and sequence of acceleration changes, I'd like to calculate the current position and velocity vector.

From [this question][1], it sounds possible, but I can't find any reference to projects or code to accomplish it with an Arduino. I understand the main problem will be the build-up of errors over time, but that's ok, as a rough estimate is acceptable. I'm also using wheel encoders to calculate the same values, and I want to use the accelerometer to account for errors in the encoders, like slippage. e.g. If the encoders say we're accelerating at 1cm/sec but the accelerometer says we're at a constant speed, then I know to ignore the encoders because the wheels are probably slipping.

I understand the math behind this, so the problem is how to write it in C to run on an Arduino. Is anyone aware of existing open source code for something like this? I'd like to avoid reinventing the wheel in-case anyone's implemented a similar system.

  [1]: https://electronics.stackexchange.com/questions/110506/dead-reckoning-with-accelerometer-gyro-possible

title: Dead reckoning with an accelerometer

Answers: 1

body:
    for each accelerometer:
       sample the accelerometer;
       low-pass filter its values (current and recent history) to remove noise;
       multiply by the sample interval to get the velocity increment;
       add the increment to a running sum to get velocity;

       sample the velocity (the running sum you just updated);
       maybe low-pass filter, as above;
       multiply by the sample interval, as above, to get the position increment;
       add the increment to a running sum to get position;
    end;

Noise, the artifacts created by filtering, and the double summation all work against your accuracy. That said, if your problem is to sense traction or loss of it, how about sensing real velocity more directly such as by dragging an encoded but otherwise free fifth wheel? Or if circumstances allow, optically sense the velocity of the surface underneath you as an optical mouse does?