body:
I'm having an issue with my project. My project is 8 leds and a potentiometer on an arduino being read and controlled by a raspberry pi running python.

when I'm using a potentiometer the signal is received by my raspberry pi with python which then tells a set of leds to either turn on or off. However my leds flash on my low threshold when they shouldn't, the leds on my higher threshold work as expected and stay on till my pot is out of that range. How can I fix this?

Here is my script!

    from nanpy import Arduino
    from nanpy import serial_manager
    from time import sleep

    serial_manager.connect('/dev/ttyUSB0')

    POT = 0
    LED1 = 13
    LED2 = 12
    LED3 = 11
    LED4 = 10
    LED5 = 9
    LED6 = 8
    LED7 = 7
    LED8 = 6

    Arduino.pinMode(POT, Arduino.INPUT)
    Arduino.pinMode(13, Arduino.OUTPUT)
    Arduino.pinMode(12, Arduino.OUTPUT)
    Arduino.pinMode(11, Arduino.OUTPUT)
    Arduino.pinMode(10, Arduino.OUTPUT)
    Arduino.pinMode(9, Arduino.OUTPUT)
    Arduino.pinMode(8, Arduino.OUTPUT)
    Arduino.pinMode(7, Arduino.OUTPUT)
    Arduino.pinMode(6, Arduino.OUTPUT)

    print "starting"
    while True:
        pot = Arduino.analogRead(POT)
    #this is the section that is blinking when it should stay solid
       if pot < 450:
            Arduino.digitalWrite(LED1, Arduino.HIGH)
            Arduino.digitalWrite(LED2, Arduino.HIGH)
            Arduino.digitalWrite(LED3, Arduino.HIGH)
            Arduino.digitalWrite(LED4, Arduino.HIGH)
            Arduino.digitalWrite(LED5, Arduino.LOW)
            Arduino.digitalWrite(LED6, Arduino.LOW)
            Arduino.digitalWrite(LED7, Arduino.LOW)
            Arduino.digitalWrite(LED8, Arduino.LOW)
            sleep(.5)
    # end of section
       if pot < 650 > 450:
            Arduino.digitalWrite(LED1, Arduino.LOW)
            Arduino.digitalWrite(LED2, Arduino.LOW)
            Arduino.digitalWrite(LED3, Arduino.LOW)
            Arduino.digitalWrite(LED4, Arduino.LOW)
            Arduino.digitalWrite(LED5, Arduino.LOW)
            Arduino.digitalWrite(LED6, Arduino.LOW)
            Arduino.digitalWrite(LED7, Arduino.LOW)
            Arduino.digitalWrite(LED8, Arduino.LOW)
            sleep(.1)
        if pot > 650:
            Arduino.digitalWrite(LED1, Arduino.LOW)
            Arduino.digitalWrite(LED2, Arduino.LOW)
            Arduino.digitalWrite(LED3, Arduino.LOW)
            Arduino.digitalWrite(LED4, Arduino.LOW)
            Arduino.digitalWrite(LED5, Arduino.HIGH)
            Arduino.digitalWrite(LED6, Arduino.HIGH)
            Arduino.digitalWrite(LED7, Arduino.HIGH)
            Arduino.digitalWrite(LED8, Arduino.HIGH)
            sleep(.5)
        print pot

title: Led issue with arduino controled by raspberry pi/python

Answers: 3

body:
Your second condition is written wrongly. It should be this way:

    elif pot >= 450 and pot <= 650:
        # do stuff

Your code should be such that only an option is chosen at any time. There should be only one 'if' condition at the top and the rest should be 'elif'.

body:
The problem is you're using multiple **if** statements, whereas the if-blocks should be mutually exclusive, so **elif** would be better.  It's not really clear what you intend in the 2nd clause either, since it's a typo(?) - not valid python syntax anyway.

    if (pot <= 450):
        Arduino.digitalWrite(LED1, Arduino.HIGH)
        ...
        time.sleep(0.5)
    elif (pot > 450 and pot <= 650):
        Arduino.digitalWrite(LED1, Arduino.LOW)
        ...
        time.sleep(0.1)
    else # pot > 650
        Arduino.digitalWrite(LED1, Arduino.LOW)
        ...
        time.sleep(0.5)

I think your LEDs were flashing because both the first and second **if** clauses were evaluating to True, thus both code segments were being executed (were only the first four LEDs flashing?)  Using if/elif/else instead, ensures only ever one clause is run.

If I might make a suggestion, assuming you want an LED bar graph based on the POT reading...

The analogRead() will give you a result 0-1023. Graphed over 8 LEDs, this means one more LED should be illuminated roughly per 128 units.  Since you want a full bar when rounding makes the value near 1023, maybe something like 120 is a better divisor (I just guessed this, it's probably calculable).

A simple loop over your LEDs, summing units over each iteration gives an easy way of turning the LEDs on or off.

    Arduino.analogRead(POT)
    led_bar_per_units = 120   # needs a better name

    ### illuminate the LED-bar
    bar_length = 0
    for led in (LED1, LED2, LED3, LED4, LED5, LED6, LED7, LED8):
        bar_length += led_per_bar_units
        if (bar_length <= pot):
            Arduino.digitalWrite(led, Arduino.HIGH)
        else:
            Arduino.digitalWrite(led, Arduino.LOW)
    time.sleep(0.5)

EDIT: I know you don't need brackets around python **if** statements.  I've been doing C/C++ code for so long I find bracketed-clauses easier to read, and thus code my python this way too.

body:
I figured it out.
Here is my new script.

    from nanpy import Arduino
    from nanpy import serial_manager
    from time import sleep

    serial_manager.connect('/dev/ttyUSB0')

    POT = 0
    LED1 = 13
    LED2 = 12
    LED3 = 11
    LED4 = 10
    LED5 = 9
    LED6 = 8
    LED7 = 7
    LED8 = 6

    Arduino.pinMode(POT, Arduino.INPUT)
    Arduino.pinMode(13, Arduino.OUTPUT)
    Arduino.pinMode(12, Arduino.OUTPUT)
    Arduino.pinMode(11, Arduino.OUTPUT)
    Arduino.pinMode(10, Arduino.OUTPUT)
    Arduino.pinMode(9, Arduino.OUTPUT)
    Arduino.pinMode(8, Arduino.OUTPUT)
    Arduino.pinMode(7, Arduino.OUTPUT)
    Arduino.pinMode(6, Arduino.OUTPUT)

    print "starting"
    while True:
        pot = Arduino.analogRead(POT)
        if pot < 450:
            Arduino.digitalWrite(LED1, Arduino.HIGH)
            Arduino.digitalWrite(LED2, Arduino.HIGH)
            Arduino.digitalWrite(LED3, Arduino.HIGH)
            Arduino.digitalWrite(LED4, Arduino.HIGH)
            Arduino.digitalWrite(LED5, Arduino.LOW)
            Arduino.digitalWrite(LED6, Arduino.LOW)
            Arduino.digitalWrite(LED7, Arduino.LOW)
            Arduino.digitalWrite(LED8, Arduino.LOW)
            sleep(.01)
        elif pot > 650:
            Arduino.digitalWrite(LED1, Arduino.LOW)
            Arduino.digitalWrite(LED2, Arduino.LOW)
            Arduino.digitalWrite(LED3, Arduino.LOW)
            Arduino.digitalWrite(LED4, Arduino.LOW)
            Arduino.digitalWrite(LED5, Arduino.HIGH)
            Arduino.digitalWrite(LED6, Arduino.HIGH)
            Arduino.digitalWrite(LED7, Arduino.HIGH)
            Arduino.digitalWrite(LED8, Arduino.HIGH)
            sleep(.01)
        else:
            Arduino.digitalWrite(LED1, Arduino.LOW)
            Arduino.digitalWrite(LED2, Arduino.LOW)
            Arduino.digitalWrite(LED3, Arduino.LOW)
            Arduino.digitalWrite(LED4, Arduino.LOW)
            Arduino.digitalWrite(LED5, Arduino.LOW)
            Arduino.digitalWrite(LED6, Arduino.LOW)
            Arduino.digitalWrite(LED7, Arduino.LOW)
            Arduino.digitalWrite(LED8, Arduino.LOW)
            sleep(.01)
        print pot


body:
How do we measure 100 Volts Arduino LCD [Proje][1]

    #include <LiquidCrystal.h>
    LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
    int analogInput = 0;
    float vout = 0.0;
    float vin = 0.0;
    float R1 = 100000.0; // 100K ohm direnç
    float R2 = 10000.0; // 10K ohm direnç
    int value = 0;
    void setup(){
       pinMode(analogInput, INPUT);
       lcd.begin(16, 2);
       lcd.print("DC VOLTMETRE-PROJEHOCAM");
    }
    void loop(){
       // read the value at analog input
       value = analogRead(analogInput);
       vout = (value * 5.0) / 1024.0;
       vin = vout / (R2/(R1+R2));
       if (vin<0.09) {
       vin=0.0;
    }
    lcd.setCursor(0, 1);
    lcd.print("VOLTAJ V= ");
    lcd.print(vin);
    delay(500);
    }

  [1]: http://www.projehocam.com/arduino-lcd-voltmetre-yapimi/

title: LCDs measuring volts arduino

Answers: 1

body:
The project that you show as your reference : [link in your question](http://www.projehocam.com/arduino-lcd-voltmetre-yapimi/),  shows this picture :

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

Change R1 to 200 K ohms.   The Arduino will receive 4.76 volts when the input is 100 volts.

You will also need to change your program line for float R1 = 100000.0;

**CAUTION :  Beware of high voltage.  Also, the Arduino is not isolated from the 100 volts.**

  [1]: https://i.stack.imgur.com/5Dxpa.jpg


body: What kind of a sim card is required for sim800 module? I know it must be activated and must be valid. But about 2g, 3g or LTE...What kind of a sim card in overall should I use with this module?

title: Sim800 sim card requirements

Answers: 1

body:
> What kind of a sim card is required for sim800 module?

*The SIM interface complies with the GSM Phase 1 specification and the new GSM Phase 2+ specification for FAST 64 kbps SIM card. Both 1.8V and 3.0V SIM card
are supported. The SIM interface is powered from an internal regulator in the module.*

For more details see [here][1] and [here][2]. And remember "Google is your friend".

Cheers!

  [1]: https://www.adafruit.com/datasheets/sim800h_hardware_design_v1.00.pdf
  [2]: https://learn.adafruit.com/adafruit-fona-mini-gsm-gprs-cellular-phone-module/obtaining-a-sim


body: I am trying to receive and send some data from a computer to an ATtiny through USB. Can an ATtiny85 IC communicate with a computer through USB? If yes, how should it be connected?

title: ATtiny85 communication with computer through USB

Answers: 2

body:
> Can an ATtiny85 ic communicate with a computer through USB?if yes,how should be the connection?

Have you checked the web? There are many such projects. Here is a link to one:

http://www.instructables.com/id/Digispark-DIY-The-smallest-USB-Arduino/

Please remember "Google is your friend".

Cheers!

body:
Digispark made a lot of these as part of a "cheap Arduino USB interface" project a while back.

This is my Digispark, it's pretty cute:

[![Digispark][1]][1]

They have a [web page here](https://digistump.com/wiki/digispark).

---

I got them for about $2 each. The board has the ATtiny85, a voltage regulator, and a handful of other parts.

Schematic (courtesy of [Digistump Wiki](https://digistump.com/wiki/digispark/tutorials/digispark)):

[![Digispark schematic][2]][2]

---

More information about the Virtual USB idea at [USB-Keyboard with Arduino and V-USB library, an example](http://blog.petrockblock.com/2012/05/19/usb-keyboard-with-arduino-and-v-usb-library-an-example/).

  [1]: https://i.stack.imgur.com/0oXID.jpg
  [2]: https://i.stack.imgur.com/Iv2bq.png


body:
I have tried to use different libraries like `TimeAlarms` , `SimpleTimer`, `Timer` and others. My goal is to call function periodically every minute or so. Each library works fine when repeat time is less than 15 seconds ( maybe greater) but 30seconds,45seconds, 60seconds doesn't work at all.

It seems something with internal timer.

I also use NRF24l01 Mesh library.

Please help to solve the problem

**SOLVED**

  The issue was that I used int type instead of long. but I don't understand why 60 000 cannot be stored in int type which is 4 bytes (2^32)

title: Arduino signed int can't fire timer > 15 seconds

Answers: 0


body:
Since the AT89S52 controller is ISP programmable is it possible to use an Arduino UNO as a programmer to upload the hex file to the 8952 ?

I've tried various programmer softwares such as progisp, 8051 loader and ISP Prog v1.4 but the Arduino doesnt show up as a programmer on any of these. I've uploaded the ArduinoISP sketch on the UNO and then tried to program the 8952 without any luck.

According to my understanding the ISP programmers use an ATMega8 ,so is what I'm trying to do possible or do I need to purchace an ISP programmer ?

title: Can an AT89S52 be programmed using an Arduino as ISP?

Answers: 3

body:
You should be able to use the Arduino as an ISP since an ISP is basically just a serial to SPI interface. If you are trying to use the arduino software to upload your program, you will need to edit your boards.txt file to be able to talk to the chip. If you are just using avrdude you will need to update your avrdude.conf.  [AVR Freaks][1] has a post on someone trying something similar and may be of some help. Without knowing your environment it's difficult to give more specific advice

  [1]: http://www.avrfreaks.net/forum/writing-at89s52-through-usbasp

body:
You might be able to use the programmer sketch I wrote a while back (it runs on a Uno). You need an SD card interface so it can read the .hex file for programming. See: <http://www.gammon.com.au/uploader>

You connect things up roughly like this (Atmega328P shown, your wiring would be different at the target chip side):

[![Chip programmer][1]][1]

You would need to modify the sketch to add the details for the AT89S52. As far as I can make out from the datasheet:

* Signature: 0x1E 0x52 0x06
* PROGMEM: 8k bytes
* RAM: 256 bytes
* Pinouts: Depending on the chip package. You need to identify MOSI/MISO/SCK/RESET along with Vcc and Gnd.
* Fuses: None that I can see
* Flash page size: 256 bytes

Thus you could modify the table of chips to add that one, along these lines:

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

    // see Atmega datasheets
    const signatureType signatures [] PROGMEM =
      {
    //     signature        description   flash size   bootloader  flash  fuse
    //                                                     size    page    to
    //                                                             size   change

      // AT89S52
      { { 0x1E, 0x52, 0x06 }, "AT89S52",   8 * kb,           0,   256,   NO_FUSE },

    // ... other ones here ...

I haven't got an AT89S52 to test it on, so I can't say for sure I got those parameters right. I am assuming that the programming instructions for ICSP programming are the same as for the other chips in their range.

---

* Sketch source: <https://github.com/nickgammon/arduino_sketches>

  [1]: https://i.stack.imgur.com/tscQr.jpg

body:
If you haven't been successful yet, Try this.(assuming it's still not solved.)

I'm using Arduino to successfully program the AT89S52.
Need 2 tools:
Arduino program and
an AT89S52 programmer software.
Here's a complete tutorial on how to do it.
Works on Windows, not so sure about linux.
http://www.instructables.com/id/ARDUINO-AS-A-8051-PROGRAMMER/?ALLSTEPS


body:
arduino nano, the driver is not showing up in Port assignments. It has worked with this operating system before. I’ve messed something up.  “OS X EI Capitan ver. 10.11.3 I have check the posts but the serial port is a no show

[![Available Ports ][1]][1]

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

title: driver is not showing up in Port assignments mac

Answers: 1

body:
If the port showed in earlier versions of OS X, but never showed after upgrading to El Capitan, then you probably used an unsigned driver, which is no longer allowed by Apple's new [System Integrity Protection][1] (a.k.a. "Rootless"; more details [in a WWDC session][2]).

Any unsigned drivers will have been disabled during the upgrade process. Even more, SIP does not allow *any* non-Apple files in `/System`, `/bin`, `/sbin` and `/usr` (except for `/usr/local`), so anything you had put in there will have been moved away as well. To see what has been disabled:

- `ls -l "/Incompatible Software"`
- `ls -lR /Library/SystemMigration/History/Migration-*/QuarantineRoot/*`

To get it working again: find a signed driver, or [Switch off SIP][3].

  [1]: https://support.apple.com/en-us/HT204899
  [2]: https://developer.apple.com/videos/play/wwdc2015-706/
  [3]: https://apple.stackexchange.com/questions/208478/how-do-i-disable-system-integrity-protection-sip-aka-rootless-on-os-x-10-11


body:
Ive been working with a motor project for a while and i bought this H-bridge(LMD18200). I dont understand how im supposed to connect it to the arduino.

Here is the datasheet for the lmd18200:

![the datasheet](https://imagizer.imageshack.us/v2/484x397q90/924/KkI1QB.png)

title: How to wire an LMD18200 and an arduino?

Answers: 1

body:
Most basic way would be to use only DIR, PWM and Break.

Use Break as enable (put high at begining of the program, put low when you want to start rotation).

Use Dir to change rotation of the motor (usually high is CV, low is CCV, but you need to check the datasheet)

And hook up PWM to [PWM][1] pin on arduino. This will control the speed.

  [1]: https://www.arduino.cc/en/Tutorial/PWM


body: My question is: how do I read multiple inputs at the same time without using interrupts on an UNO.  I'm building an RC drag strip with tree and finish line that will calculate run time as well as calculate each run in mph.  I'm using lasers and non modulated laser detectors for the beams and I'm using a 1" beam gap(between 1st beam and 2nd beam) at the finish line(for mph calculation). My concern comes in when two cars come close enough at the finish line for one to break the first beam at set the win flag but the car in the other lane is close enough to cross the 1st beam before the 1st car actually crosses the 2nd beam then the detection loop is going to miss one of them. (just a note: a few of these cars can top 100 mph when crossing the line)

title: RC drag strip finish line with mph calculation (using 1" spaced lasers)

Answers: 3

body:
One option, if you want very-real-time processing, for a task like this that break neatly into chunks: Have one Arduino per vehicle.

Arduinos are cheap. If they are too expensive, use AtTiny's - they can be had for about a dollar a piece (depending on your currency). You can share a clock/power between a large number of them.

You can either have a "master" Arduino talk to each individual one, to collect the information, or have daisy-chained bus - each one can pass it's data to the next one in the chain (once is has the data, and the next one in the chain indicates it's ready for it).

body:
**ONE:**

What you can do is use a while loop waiting for the first pulse and then wait until the last pulse, for an idea look at [this code from ][1]Gadjet, he made a [chronograph][2] with a similar operation, you would just need to adapt the design, this might not be as accurate for an 1". Also it will be the issue of having ties between cars. This is short as I don't like this option.

**TWO:**

Another option, although using what you don't want to use, would be using the interrupts on the Arduino. *I am basing the following on the fact that you are using two cars.*

What you can do is have a `finish line` for *both vehicles* and detect a break with a interrupt, one interrupt pin per lane(UNO has to interrupts).

The trick here is that you place both the outputs from one lane onto a single interrupt pin with a edge detector type of [circuit][3]1 to generate a pulse while the vehicle crosses a point, especially important as it will be in the inch area for a while. The code handles the double pulse on one pin. I know this works as I used this on a ballistic chronograph which works in microseconds detecting shots >2000fps over a 0.406 foot distance.

1 This is an example of the circuit you would use at the output of each sensor before the OR gates:
[![enter image description here][6]][6]

The hardware would just become a duplicate for each lane, and to combine the input on one pin you can use an [OR gate IC][4] or you can use diode OR gate:
![from ee.se][5]

Interrupts are actually easy to use with Arduinos, and there are [a lot of examples][7] out there.

Have a look at the below flow chart to get an idea of operation in the code:

[![RSM code][8]][8]

A small thing would be that the code ignores a interrupt once the cars have passed so it doesn't calculate a second time.

  [1]: https://dl.dropboxusercontent.com/u/2253850/Chronograph_7_Seg_on_Nano.ino
  [2]: http://gadjetsblog.blogspot.co.za/2013/02/air-rifle-chronograph.html
  [3]: https://electronics.stackexchange.com/questions/158015/how-to-turn-continuous-signal-into-a-short-pulse-using-logic-gates
  [4]:http://www.digikey.com/product-search/en/integrated-circuits-ics/logic-gates-and-inverters/2556317
  [5]:https://i.stack.imgur.com/ntAAj.gif
  [6]: https://i.stack.imgur.com/eXQMP.png
  [7]: https://www.google.com/search?q=arduino interrupts&spell=1&sa=X&ved=0ahUKEwjg9LD2m9vKAhXFRhQKHTY7A1oQvwUIGigA
  [8]: https://i.stack.imgur.com/88Q1C.png

body:
Building upon Nick Gammon's excellent answer at https://arduino.stackexchange.com/questions/1784/how-many-interrupt-pins-can-an-uno-handle/12958#12958 here's some untested code:

     const int events = 256; // events to store
     unsigned volatile int index;
     byte pinStates[events];
     unsigned int times[events];

     ISR (PCINT1_vect) //  Watch for pin changes on the C port (Uno pins A0-A5)
     {
       if (index == 0) { // start clock
        TCCR1B = bit(CS12) | bit (CS10) ;    // clock/1024 for <4.19s x 64us
        //TCCR1B = bit(CS12);                // clock/256  for <1.05s x 16us
        //TCCR1B = bit(CS11) | bit (CS10) ;  // clock/64   for <0.25s x 4us
        //TCCR1B = bit(CS11) ;               // clock/8    for <0.03s x 0.5us
        //TCCR1B = bit(CS10) ;               // clock/1    for <0.004s x 62ns
       }
       times[index] = TCNT1;
       pinStates[index] = PORTC;
       index = (index+1) & 0xff; // increment and protect from overflow

     }  // end of PCINT1_vect

    void setup ()
      {
      // activate pin change interrupts on port C / pins A0-A5

      PCICR   =  bit (PCIE1);    // enable PCINT[14:8] pin triggers
      PCMSK1 |=  bit (PCINT8) |
                 bit (PCINT9) |
                 bit (PCINT10) |
                 bit (PCINT11) |
                 bit (PCINT12) |
                 bit (PCINT13);     // enable individual pins

      // stop and clear 16 bit timer  CS1[0-2]=0; TCNT1 = 0;
      TCCR1A = 0;  // no comparisons, normal WGM mode, stop the counting
      TCCR1B = 0;
      TCNT1  = 0;  // Clear the counter

      pinMode (A0, INPUT_PULLUP);
      pinMode (A1, INPUT_PULLUP);
      pinMode (A2, INPUT_PULLUP);
      pinMode (A3, INPUT_PULLUP);
      pinMode (A4, INPUT_PULLUP);
      pinMode (A5, INPUT_PULLUP);

      index = 0 ; // nothing happened yet

      pinMode (5, OUTPUT);
      }  // end of setup

    void loop ()
      {

       // check index, parse and report times, check for arming, etc...

      }

The point is to use the pin change interrupt to record state changes on the pins and the times.   The clock/1024 prescaler would give a 1/16MhZ*1024*65536= 4.19s window at 64us resolution timing counts, but you could go to higher resolution with a tighter window by using a smaller prescaler.

Also, if you wanted longer timing windows, you could cascade timer1 into timer0 (messing up millis(), etc.,) and get 24 bits of range before overflow, but a better way than cascading timers might be to add another interrupt to increment a variable.  For much longer timing windows add another quick interrupt to handle for timer1 overflow.

    ...
    volatile unsigned long int t1Cycles,times[events];
    ...

    ISR(TIMER1_OVF_vect){t1Cycles++;}

    void setup(){
        ...
        TIMSK1 = bit(TOIE1);
        t1Cycles = 0;
        ...
    }

    ISR (PCINT1_vect)
    {
        ...
        times[index] = t1Cycles << 16 | TCNT1; // store 32 bit count of clocks
        ...
    }

This is still untested, but it looks like it could be capable of 268 seconds worth of 62ns resolution multichannel timing.  With the longer period, you could move the conditional clock-starting code out of the pin-change ISR.


body:
I have this voice sensor:

[![http://s3.amazonaws.com/img.iluria.com/product/22C645/5241CF/450xN.jpg][1]][1]

I need to know how bytes pass through soundsensor into arduino and get this bytes and put out in a speaker.

I read on the net a Lib PCM thats converts chars in voices, but how do I extract bytes from sound sensor in analog-in?

  [1]: https://i.stack.imgur.com/K48qt.jpg

title: How do I use Sound Sensor LM393 + Speaker in Arduino

Answers: 2

body:
Oh, the joys of buying something off the Internet with no datasheet, no part number and no clue how to use it. And then expecting somebody else to tell you how it works.

That module looks like a KY-038, made by Keyes. No guarantees, though, because I'm not telepathic.

Bytes don't "pass through the soundsensor". Bytes don't pass anywhere, in fact. That board has an analogue output, `A0`, which is the amplified audio sensed by the microphone. It swings between 0 and 5 volts, and is 2.5V when no sound is being picked up. The board also has a digital output, `D0`, which is **active-low** when the intensity of the sound picked up by the microphone exceeds a thershold. I have no idea what this threshold is or what volume it represents, or if it can be changed.

Have a look at the pages on [AnalogRead()](https://www.arduino.cc/en/Reference/AnalogRead) for information on how to convert analogue audio to a digital signal.

I don't know what you mean by "a Lib PCM thats converts chars in voices" - 'chars' as in the C-type `chars` or do you mean literal 'characters from a voice', i.e. speech recognition? I cannot tell if you have misunderstood something or there's an unfortunate translation coincidence which is confusing matters.

body:
This post was awhile ago, but I wanted to offer some more definitive info for others like myself who were trying to identify it. What you have there is the Keyes KY-037 "high-sensitivity voice sensor" module. Mine came with the Inland Arduino Uno RFID Learning Kit.

Apparently the KY-037 and the KY-038 are the same except the KY-037 has a higher sensitivity microphone. I could not find any specs to quantify what that sensitivity difference is, however. Both have a LM393 voltage comparator on the board. The same Arduino code ought to work for both.

Here are a few helpful links I found, some also showing a bunch of the other Keyes modules and how to use them:

http://linksprite.com/wiki/index.php5?title=Advanced_Sensors_Kit_for_Arduino

http://brd4.braude.ac.il/~ksamuel/ElIn.31361/Lectures/022-Basic Definitions and Concepts Sensors and Actiators 2013-10-10.pdf  (Page/slide 40)

http://tkkrlab.nl/wiki/Arduino_37_sensors


body:
Problem: can't print to the serial monitor, it appears that the serial monitor disconnects itself after uploading a program.

I'm brand new to arduino, and I'm trying to upload a basic program to print to the serial monitor.

I use an arduino uno and my OS is Ubuntu.
I am connecting the arduino to my PC via USB.
Using Arduino Studio Release 0.0.5 experimental build 0.0.5-16058

(I am able to communicate via the digital output pins, tested by making a simple circuit to make the led light blink)

Here is the program:

    void setup()
    {
        Serial.begin(9600);
    }

    void loop()
    {
        Serial.print("test");
        delay(500);
    }

Here is the result of the build, look at the last line and it says the serial monitor was disconnected? Why would this happen automatically?

    [2/2/2016 8:51:26 PM] - Start Building
    [2/2/2016 8:51:26 PM] - CPP File Created [/tmp/build1454471486915/test.cpp]
    [2/2/2016 8:51:26 PM] - test.cpp compiled
    [2/2/2016 8:51:26 PM] - CDC.cpp compiled
    [2/2/2016 8:51:27 PM] - HID.cpp compiled
    [2/2/2016 8:51:27 PM] - HardwareSerial.cpp compiled
    [2/2/2016 8:51:27 PM] - HardwareSerial0.cpp compiled
    [2/2/2016 8:51:27 PM] - HardwareSerial1.cpp compiled
    [2/2/2016 8:51:27 PM] - HardwareSerial2.cpp compiled
    [2/2/2016 8:51:27 PM] - HardwareSerial3.cpp compiled
    [2/2/2016 8:51:27 PM] - IPAddress.cpp compiled
    [2/2/2016 8:51:27 PM] - Print.cpp compiled
    [2/2/2016 8:51:27 PM] - Stream.cpp compiled
    [2/2/2016 8:51:27 PM] - Tone.cpp compiled
    [2/2/2016 8:51:27 PM] - USBCore.cpp compiled
    [2/2/2016 8:51:27 PM] - WInterrupts.c compiled
    [2/2/2016 8:51:27 PM] - WMath.cpp compiled
    [2/2/2016 8:51:27 PM] - WString.cpp compiled
    [2/2/2016 8:51:27 PM] - abi.cpp compiled
    [2/2/2016 8:51:27 PM] - hooks.c compiled
    [2/2/2016 8:51:27 PM] - main.cpp compiled
    [2/2/2016 8:51:27 PM] - new.cpp compiled
    [2/2/2016 8:51:28 PM] - wiring.c compiled
    [2/2/2016 8:51:28 PM] - wiring_analog.c compiled
    [2/2/2016 8:51:28 PM] - wiring_digital.c compiled
    [2/2/2016 8:51:28 PM] - wiring_pulse.c compiled
    [2/2/2016 8:51:28 PM] - wiring_shift.c compiled
    [2/2/2016 8:51:28 PM] - CDC.cpp.o linked to core.a
    [2/2/2016 8:51:28 PM] - HID.cpp.o linked to core.a
    [2/2/2016 8:51:28 PM] - HardwareSerial.cpp.o linked to core.a
    [2/2/2016 8:51:28 PM] - HardwareSerial0.cpp.o linked to core.a
    [2/2/2016 8:51:28 PM] - HardwareSerial1.cpp.o linked to core.a
    [2/2/2016 8:51:28 PM] - HardwareSerial2.cpp.o linked to core.a
    [2/2/2016 8:51:28 PM] - HardwareSerial3.cpp.o linked to core.a
    [2/2/2016 8:51:28 PM] - IPAddress.cpp.o linked to core.a
    [2/2/2016 8:51:28 PM] - Print.cpp.o linked to core.a
    [2/2/2016 8:51:28 PM] - Stream.cpp.o linked to core.a
    [2/2/2016 8:51:28 PM] - Tone.cpp.o linked to core.a
    [2/2/2016 8:51:28 PM] - USBCore.cpp.o linked to core.a
    [2/2/2016 8:51:28 PM] - WInterrupts.c.o linked to core.a
    [2/2/2016 8:51:28 PM] - WMath.cpp.o linked to core.a
    [2/2/2016 8:51:28 PM] - WString.cpp.o linked to core.a
    [2/2/2016 8:51:28 PM] - abi.cpp.o linked to core.a
    [2/2/2016 8:51:28 PM] - hooks.c.o linked to core.a
    [2/2/2016 8:51:28 PM] - main.cpp.o linked to core.a
    [2/2/2016 8:51:28 PM] - new.cpp.o linked to core.a
    [2/2/2016 8:51:28 PM] - test.cpp.o linked to core.a
    [2/2/2016 8:51:28 PM] - test.ino linked to core.a
    [2/2/2016 8:51:28 PM] - wiring.c.o linked to core.a
    [2/2/2016 8:51:28 PM] - wiring_analog.c.o linked to core.a
    [2/2/2016 8:51:28 PM] - wiring_digital.c.o linked to core.a
    [2/2/2016 8:51:28 PM] - wiring_pulse.c.o linked to core.a
    [2/2/2016 8:51:28 PM] - wiring_shift.c.o linked to core.a
    [2/2/2016 8:51:28 PM] - test.cpp.elf linked to core.a
    [2/2/2016 8:51:28 PM] - test EEPROM
    [2/2/2016 8:51:28 PM] - test.hex builded
    [2/2/2016 8:51:28 PM] - Uploading...
    [2/2/2016 8:51:30 PM] - Uploaded
    [2/2/2016 8:51:30 PM] - [arduino ide - serial monitor] Serial monitor connected to /dev/ttyACM0
    [2/2/2016 8:51:36 PM] - [arduino ide - serial monitor] Serial monitor disconnected from /dev/ttyACM0

title: Serial monitor disconnecting itself

Answers: 1

body: I'm not sure why your IDE is doing that, but the official Arduino IDE from [Arduino.cc](http://arduino.cc/) works on Ubuntu and does not have that issue. Download from [Arduino Software download page](https://www.arduino.cc/en/Main/Software).


body: I would like to use my arduino even where there's no wifi router. I've only found people saying that it needs to connect to a router, but isn't the phone like a router when it's in tethering mode? Do I still need a mobile internet connection or can I do it directly?

title: Can I connect an Arduino wifi module directly to my android phone?

Answers: 2

body:
A phone running in wifi tethering (mobile hotspot) mode is no different to a wifi access point or router. So yes, you can use that.

Chances are though that you will need a mobile internet connection in order to activate mobile hotspot mode in the first place.

body:
If you are using the Arduino UNO WiFi Board (http://www.arduino.org/products/boards/arduino-uno-wifi) with the built in ESP8266 chip then your phone can connect directly to the Arduino's network and you can interact with it that way.

With the default firmware, this board can simultaneously connect to a local WiFi network, and create its on access point. This is very handy because it means that you can connect and access its hosted web pages even without a WiFi router with no extra setup steps, or special configuration.


body:
I can't figure out where I doing wrong

https://www.youtube.com/watch?v=35NqOANmgUE

This is my question in videos

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

  [1]: https://i.stack.imgur.com/6TGmH.jpg

The both of two connect the same pin

(so the right display result is the correct  OLED)

My connecting table  (using SPI )

   GND              gnd

   VCC              5V

   D0(OLED_CLK)     10

   D(OLED_MOSI)     9

   RES(OLED_RESET)  13

   D/C(OLED_DC)     11

   CS（OLED_CS）    12

but the left OLED doesn't have the "RES" pin
(so I didn't connect it)

the left OLED just display the upper part
(and its the position of display picture is also wired ,too)

 this is my code

    /*********************************************************************
    This is an example for our Monochrome OLEDs based on SSD1306 drivers
    This example is for a 128x64 size display using SPI to communicate
    4 or 5 pins are required to interface

    Adafruit invests time and resources providing this open source code,
    please support Adafruit and open-source hardware by purchasing
    products from Adafruit!

    Written by Limor Fried/Ladyada  for Adafruit Industries.
    BSD license, check license.txt for more information
    All text above, and the splash screen must be included in any redistribution
    *********************************************************************/

    #include <SPI.h>
    #include <Wire.h>
    #include <Adafruit_GFX.h>
    #include <Adafruit_SSD1306.h>

    // If using software SPI (the default case):
    #define OLED_MOSI   9
    #define OLED_CLK   10
    #define OLED_DC    11
    #define OLED_CS    12
    #define OLED_RESET 13
    Adafruit_SSD1306 display(OLED_MOSI, OLED_CLK, OLED_DC, OLED_RESET, OLED_CS);

    /* Uncomment this block to use hardware SPI
    #define OLED_DC     6
    #define OLED_CS     7
    #define OLED_RESET  8
    Adafruit_SSD1306 display(OLED_DC, OLED_RESET, OLED_CS);
    */

    #define NUMFLAKES 10
    #define XPOS 0
    #define YPOS 1
    #define DELTAY 2

    #define LOGO16_GLCD_HEIGHT 16
    #define LOGO16_GLCD_WIDTH  16
    static const unsigned char PROGMEM logo16_glcd_bmp[] =
    { B00000000, B11000000,
      B00000001, B11000000,
      B00000001, B11000000,
      B00000011, B11100000,
      B11110011, B11100000,
      B11111110, B11111000,
      B01111110, B11111111,
      B00110011, B10011111,
      B00011111, B11111100,
      B00001101, B01110000,
      B00011011, B10100000,
      B00111111, B11100000,
      B00111111, B11110000,
      B01111100, B11110000,
      B01110000, B01110000,
      B00000000, B00110000 };

    #if (SSD1306_LCDHEIGHT != 64)
    #error("Height incorrect, please fix Adafruit_SSD1306.h!");
    #endif

    void setup()   {
      Serial.begin(9600);

      // by default, we'll generate the high voltage from the 3.3v line internally! (neat!)
      display.begin(SSD1306_SWITCHCAPVCC);
      // init done

      // Show image buffer on the display hardware.
      // Since the buffer is intialized with an Adafruit splashscreen
      // internally, this will display the splashscreen.
      display.display();
      delay(2000);

      // Clear the buffer.
      display.clearDisplay();

      // draw a single pixel
      display.drawPixel(10, 10, WHITE);
      // Show the display buffer on the hardware.
      // NOTE: You _must_ call display after making any drawing commands
      // to make them visible on the display hardware!
      display.display();
      delay(2000);
      display.clearDisplay();

      // draw many lines
      testdrawline();
      display.display();
      delay(2000);
      display.clearDisplay();

      // draw rectangles
      testdrawrect();
      display.display();
      delay(2000);
      display.clearDisplay();

      // draw multiple rectangles
      testfillrect();
      display.display();
      delay(2000);
      display.clearDisplay();

      // draw mulitple circles
      testdrawcircle();
      display.display();
      delay(2000);
      display.clearDisplay();

      // draw a white circle, 10 pixel radius
      display.fillCircle(display.width()/2, display.height()/2, 10, WHITE);
      display.display();
      delay(2000);
      display.clearDisplay();

      testdrawroundrect();
      delay(2000);
      display.clearDisplay();

      testfillroundrect();
      delay(2000);
      display.clearDisplay();

      testdrawtriangle();
      delay(2000);
      display.clearDisplay();

      testfilltriangle();
      delay(2000);
      display.clearDisplay();

      // draw the first ~12 characters in the font
      testdrawchar();
      display.display();
      delay(2000);
      display.clearDisplay();

      // draw scrolling text
      testscrolltext();
      delay(2000);
      display.clearDisplay();

      // text display tests
      display.setTextSize(1);
      display.setTextColor(WHITE);
      display.setCursor(0,0);
      display.println("Hello, world!");
      display.setTextColor(BLACK, WHITE); // 'inverted' text
      display.println(3.141592);
      display.setTextSize(2);
      display.setTextColor(WHITE);
      display.print("0x"); display.println(0xDEADBEEF, HEX);
      display.display();
      delay(2000);

      // miniature bitmap display
      display.clearDisplay();
      display.drawBitmap(30, 16,  logo16_glcd_bmp, 16, 16, 1);
      display.display();

      // invert the display
      display.invertDisplay(true);
      delay(1000);
      display.invertDisplay(false);
      delay(1000);

      // draw a bitmap icon and 'animate' movement
      testdrawbitmap(logo16_glcd_bmp, LOGO16_GLCD_HEIGHT, LOGO16_GLCD_WIDTH);
    }

    void loop() {

    }

    void testdrawbitmap(const uint8_t *bitmap, uint8_t w, uint8_t h) {
      uint8_t icons[NUMFLAKES][3];

      // initialize
      for (uint8_t f=0; f< NUMFLAKES; f++) {
        icons[f][XPOS] = random(display.width());
        icons[f][YPOS] = 0;
        icons[f][DELTAY] = random(5) + 1;

        Serial.print("x: ");
        Serial.print(icons[f][XPOS], DEC);
        Serial.print(" y: ");
        Serial.print(icons[f][YPOS], DEC);
        Serial.print(" dy: ");
        Serial.println(icons[f][DELTAY], DEC);
      }

      while (1) {
        // draw each icon
        for (uint8_t f=0; f< NUMFLAKES; f++) {
          display.drawBitmap(icons[f][XPOS], icons[f][YPOS], logo16_glcd_bmp, w, h, WHITE);
        }
        display.display();
        delay(200);

        // then erase it + move it
        for (uint8_t f=0; f< NUMFLAKES; f++) {
          display.drawBitmap(icons[f][XPOS], icons[f][YPOS],  logo16_glcd_bmp, w, h, BLACK);
          // move it
          icons[f][YPOS] += icons[f][DELTAY];
          // if its gone, reinit
          if (icons[f][YPOS] > display.height()) {
     icons[f][XPOS] = random(display.width());
     icons[f][YPOS] = 0;
     icons[f][DELTAY] = random(5) + 1;
          }
        }
       }
    }

    void testdrawchar(void) {
      display.setTextSize(1);
      display.setTextColor(WHITE);
      display.setCursor(0,0);

      for (uint8_t i=0; i < 168; i++) {
        if (i == '\n') continue;
        display.write(i);
        if ((i > 0) && (i % 21 == 0))
          display.println();
      }
      display.display();
    }

    void testdrawcircle(void) {
      for (int16_t i=0; i<display.height(); i+=2) {
        display.drawCircle(display.width()/2, display.height()/2, i, WHITE);
        display.display();
      }
    }

    void testfillrect(void) {
      uint8_t color = 1;
      for (int16_t i=0; i<display.height()/2; i+=3) {
        // alternate colors
        display.fillRect(i, i, display.width()-i*2, display.height()-i*2, color%2);
        display.display();
        color++;
      }
    }

    void testdrawtriangle(void) {
      for (int16_t i=0; i<min(display.width(),display.height())/2; i+=5) {
        display.drawTriangle(display.width()/2, display.height()/2-i,
                         display.width()/2-i, display.height()/2+i,
                         display.width()/2+i, display.height()/2+i, WHITE);
        display.display();
      }
    }

    void testfilltriangle(void) {
      uint8_t color = WHITE;
      for (int16_t i=min(display.width(),display.height())/2; i>0; i-=5) {
        display.fillTriangle(display.width()/2, display.height()/2-i,
                         display.width()/2-i, display.height()/2+i,
                         display.width()/2+i, display.height()/2+i, WHITE);
        if (color == WHITE) color = BLACK;
        else color = WHITE;
        display.display();
      }
    }

    void testdrawroundrect(void) {
      for (int16_t i=0; i<display.height()/2-2; i+=2) {
        display.drawRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, WHITE);
        display.display();
      }
    }

    void testfillroundrect(void) {
      uint8_t color = WHITE;
      for (int16_t i=0; i<display.height()/2-2; i+=2) {
        display.fillRoundRect(i, i, display.width()-2*i, display.height()-2*i, display.height()/4, color);
        if (color == WHITE) color = BLACK;
        else color = WHITE;
        display.display();
      }
    }

    void testdrawrect(void) {
      for (int16_t i=0; i<display.height()/2; i+=2) {
        display.drawRect(i, i, display.width()-2*i, display.height()-2*i, WHITE);
        display.display();
      }
    }

    void testdrawline() {
      for (int16_t i=0; i<display.width(); i+=4) {
        display.drawLine(0, 0, i, display.height()-1, WHITE);
        display.display();
      }
      for (int16_t i=0; i<display.height(); i+=4) {
        display.drawLine(0, 0, display.width()-1, i, WHITE);
        display.display();
      }
      delay(250);

      display.clearDisplay();
      for (int16_t i=0; i<display.width(); i+=4) {
        display.drawLine(0, display.height()-1, i, 0, WHITE);
        display.display();
      }
      for (int16_t i=display.height()-1; i>=0; i-=4) {
        display.drawLine(0, display.height()-1, display.width()-1, i, WHITE);
        display.display();
      }
      delay(250);

      display.clearDisplay();
      for (int16_t i=display.width()-1; i>=0; i-=4) {
        display.drawLine(display.width()-1, display.height()-1, i, 0, WHITE);
        display.display();
      }
      for (int16_t i=display.height()-1; i>=0; i-=4) {
        display.drawLine(display.width()-1, display.height()-1, 0, i, WHITE);
        display.display();
      }
      delay(250);

      display.clearDisplay();
      for (int16_t i=0; i<display.height(); i+=4) {
        display.drawLine(display.width()-1, 0, 0, i, WHITE);
        display.display();
      }
      for (int16_t i=0; i<display.width(); i+=4) {
        display.drawLine(display.width()-1, 0, i, display.height()-1, WHITE);
        display.display();
      }
      delay(250);
    }

    void testscrolltext(void) {
      display.setTextSize(2);
      display.setTextColor(WHITE);
      display.setCursor(10,0);
      display.clearDisplay();
      display.println("scroll");
      display.display();

      display.startscrollright(0x00, 0x0F);
      delay(2000);
      display.stopscroll();
      delay(1000);
      display.startscrollleft(0x00, 0x0F);
      delay(2000);
      display.stopscroll();
      delay(1000);
      display.startscrolldiagright(0x00, 0x07);
      delay(2000);
      display.startscrolldiagleft(0x00, 0x07);
      delay(2000);
      display.stopscroll();
    }

title: OLED display wrong (using SPI )

Answers: 1

body:
Check the connections with that required by the software/library. If you intend to use SPI the pins on Arduino Uno are:

    SS   10
    MOSI 11
    MISO 12
    SCK  13

You connections above are:

    VCC             => 5V
    D0(OLED_CLK)    => 10 (SPI SS ??)
    D(OLED_MOSI)    => 9
    RES(OLED_RESET) => 13 (SPI SCK ??)
    D/C(OLED_DC)    => 11 (SPI MOSI ??)
    CS（OLED_CS）     => 12 (SPI MISO ??)
    GND             => GND (??)

That is not correct for SPI. Post link to library, oled hardware, and snippet of your code for more help.

It is more than the video that is out of focus :)

Cheers!


body:
I'm working on Arduino Nano and I have to use both the Bluetooth LE module **Adafruit nRF8001** and **ENC28J60** Ethernet module using [Ethercard][1]

The idea of the project is to receive data from smartphone via BLE and send it via Ethernet to check with server if the data is valid then the Arduino will send an **ON** signal out of digital pin 4

But the problem is when `uart.begin()` (BLE) command invoked. I can no longer use the Ethernet module anymore.

I tried remove the `uart.begin()` part and Ethernet works fine.
I tried swap `uart.begin()` to run before `ether.begin()`. Ethernet cannot be initialized anymore.

Either way, the BLE module seems to work fine and the Arduino can respond to messages from smartphone. But sometimes it returns error code which I cannot understand. And after I pressed reset button on the Arduino it begins to work again.

    ACI Command 40
    Evt Cmd respone: Error. Arduino is in an while(1); loop

This version doesn't include the data verification part yet. Only send `open` from smartphone to trigger the Ethernet request and the server will always return `you-are-good`

Here is my sketch

<!-- language: c -->

    //BLUETOOTH
    #include <SPI.h>
    #include "Adafruit_BLE_UART.h"

    #define ADAFRUITBLE_REQ 8
    #define ADAFRUITBLE_RDY 2
    #define ADAFRUITBLE_RST 9

    Adafruit_BLE_UART uart = Adafruit_BLE_UART(ADAFRUITBLE_REQ, ADAFRUITBLE_RDY, ADAFRUITBLE_RST);
    static bool isBTConnected = false;

    //ETHERNET
    #include <EtherCard.h>
    #define ETH_CS 10
    #define FORCE_STATIC_IP true

    static const byte mymac[] = { 0x74, 0x69, 0x69, 0x2D, 0x30, 0x31 };
    byte Ethernet::buffer[140];
    const char website[] PROGMEM = "192.168.1.104";
    const char website_path[] PROGMEM = "/check";

    //TIMER AND OUTPUT
    #define OUTPUT_PIN 4
    #define OUTPUT_ON  LOW
    #define OUTPUT_OFF HIGH

    static uint32_t timer;
    static const uint16_t interval PROGMEM = 5000; // 5 seconds
    static bool isOn = false;

    //ETHERNET
    static void ethCallback (byte status, word off, word len) {
      Serial.println(F(">>> Response"));

      Ethernet::buffer[len + off] = 0;
      Serial.print((const char*) Ethernet::buffer + off);
      Serial.println(F("..."));
      checkPermission(len + off);
    }

    // check if the server returns exactly string "you-are-good"
    void checkPermission (word len) {
      byte c;
      uint16_t i = 0;
      uint8_t found = 0;

      const byte target[] PROGMEM = "you-are-good";
      const uint8_t targetlen PROGMEM = 12;

      do {
        c = Ethernet::buffer[i];

        if (c == target[found]) {
          if (++found >= targetlen) {
            Serial.println(F("OK"));
            outputON();
            return;
          }
        } else {
          found = 0;
        }
      } while (i++ <= len);

      Serial.println(F("NOT OK"));
      outputOFF();
    }

    void sendRequest() {
      Serial.println();
      Serial.println("<<< REQ ");

      char params[64];
      String prm = "?p=PARAMS_HERE";
      prm.toCharArray(params, 64);

      ether.browseUrl(website_path, params, website, ethCallback);
    }

    void initEthernet () {
      Serial.print(F("ETH:"));
      if (ether.begin(sizeof Ethernet::buffer, mymac, ETH_CS) == 0)
        Serial.println(F("Failed"));
      else
        Serial.println(F("OK"));

      Serial.print(F("DHCP:"));
      if (FORCE_STATIC_IP || !ether.dhcpSetup()) {
        Serial.println(F("Failed\r\nStatic: "));

        byte ip[] = {192, 168, 1, 12};
        byte gw[] = {192, 168, 1, 1};
        byte dn[] = {192, 168, 1, 1};
        byte ms[] = {255, 255, 255, 0};
        ether.staticSetup(ip, gw, dn, ms);
      } else {
        Serial.println(F("OK"));
      }

      ether.printIp(F("IP:  "), ether.myip);
      ether.printIp(F("GW:  "), ether.gwip);
      ether.printIp(F("DNS: "), ether.dnsip);

      if (!ether.dnsLookup(website)) {
        Serial.println(F("Lookup failed"));
        while (1) {
          digitalWrite(OUTPUT_PIN, HIGH);
          delay(500);
          digitalWrite(OUTPUT_PIN, LOW);
          delay(500);
        }
      }

      ether.printIp(F("SRV: "), ether.hisip);
    }

    //BLUETOOTH
    void initBluetooth () {
      uart.setRXcallback(rxCallback);
      uart.setACIcallback(aciCallback);
      uart.setDeviceName(PSTR("BLEUART")); /* 7 characters max! */
      Serial.print(F("BT:"));
      if (uart.begin())
        Serial.println(F("OK"));
      else
        Serial.println(F("FAILED"));
    }

    void aciCallback(aci_evt_opcode_t event) {
      switch (event)
      {
        case ACI_EVT_DEVICE_STARTED:
          Serial.println(F("Advertising started"));
          break;
        case ACI_EVT_CONNECTED:
          isBTConnected = true;
          Serial.println(F("Connected!"));
          break;
        case ACI_EVT_DISCONNECTED:
          isBTConnected = false;
          Serial.println(F("Disconnected or advertising timed out"));
          break;
        default:
          Serial.print(F("ACI OPCODE:"));
          Serial.println(event);
          break;
      }
    }

    void rxCallback(uint8_t *buffer, uint8_t len) {
      uint8_t target_len = 4;
      const char* target = "open";
      uint8_t counter = 0;

      Serial.print(F("Received "));
      Serial.print(len);
      Serial.print(F(" bytes: "));
      for (int i = 0; i < len; i++) {
        char ch = (char)buffer[i];
        Serial.print(ch);
        if (ch == target[counter]) {
          counter++;
        }

        if (counter == target_len) {
          sendRequest();
        }
      }
    }

    //OUTPUT
    void outputOFF() {
      digitalWrite(OUTPUT_PIN, LOW);
      isOn = false;

      Serial.println(F("Locked"));
    }

    void outputON() {
      timer = millis() + interval;
      digitalWrite(OUTPUT_PIN, HIGH);
      isOn = true;

      Serial.println(F("Unlocked"));
    }

    //ARDUINO
    void setup () {
      pinMode(4, OUTPUT);
      Serial.begin(9600);
      Serial.println(F("BT+ETH"));

      initEthernet();
      initBluetooth();
    }

    void loop () {
      uart.pollACI();
      ether.packetLoop(ether.packetReceive());

      if (isOn && millis() > timer) {
        outputOFF();
      }

      // debugging commands
      if (Serial.available()) {
        char c = Serial.read();
        if (c == '0') {
          Serial.println(F("Still OK"));
        } else if (c == '1') {
          sendRequest();
        } else if (c == '2') {
          Serial.println(isBTConnected);
        }
      }
    }

PS. I don't know if it has something to do with the problem. But the Arduino compiler reports that Global variables use **1,538 bytes (75%)** of dynamic memory. I'm planning to get another Arduino model to make sure it works fine after I added data verification part. Don't know if it will help with the problem.

  [1]: https://github.com/jcw/ethercard

title: Problem using Adafruit nRF8001 (BLE) with Ethernet module on Arduino Nano

Answers: 0


body:
I'd like to offer some context about what I'd like to do because I might have misundertood something.

I'm trying to reduce power consumption on my device, an Arduino Mega 2560, and I've found this library

https://github.com/rocketscream/Low-Power

which uses the Watchdog to put Arduino on power saving for a predetermined interval of time; after that it reactivates what has been disabled and let the program continue its flow.

I searched for more information about the Watchdog and I found out several warnings about dealing with Watchdog on an Arduino Mega 2560, stating that it would only work with a modified bootloader:
This scared me a bit because I'm not very keen on risking to brick my Arduino (I absolutely need it to work on the next few days).

Now, I only have two Arduino Mega 2560 at my disposal and if I'm not mistaken, flashing the bootloader on an Arduino Mega 2560 using another Arduino Mega 2560 as a programmer can't be done because the procedure ends with errors:

( see http://forum.arduino.cc/index.php?topic=126160.0 )

Hence my most important question: if I test the watchdog functionality on my code (the sketch) and the Arduino happens to continually reset, can I fix the situation by powering off the Arduino?

(if you can help with my other issues as well, I'd be very grateful, I'm not sure I completely understood how these things work)

title: Is a power off sufficient to avoid problems with the Watchdog on Arduino Mega 2560?

Answers: 1

body:
The problem you have is that once the watchdog is turned on it is very hard to turn it off again. There are certain procedures you have to go through to ensure it's turned off.

The default bootloader doesn't turn the bootloader off, and a reset doesn't turn it off either. The watchdog then fires whilst the bootloader is still waiting for communication from the PC thus making it reboot before your sketch has had a chance to run. Hence the change needed in the bootooader.

The only way to clear the watchdog is to remove the power. However as soon as your sketch runs and turns the watchdog back on you are then back at square one.

So you need to upload a new sketch to stop that happening, but that is tricky, since the watchdog keeps resetting and interrupting the bootloader. So what do you do? Well, there's a specific sequence you need to do.

1. Unplug the mega
2. Compile the new sketch
3. Hold the reset button on the mega
4. Plug in the mega
5. Press upload
6. As soon as avrdude starts release the reset button.

That way you have a chance of the bootloader running without your sketch having run first and enabled the watchdog. The bootloader runs just the once when the computer is tryung to upload the sketch, and with luck that will happen instead of your sketch running.


body:
I can't compile a simple blink sketch.

Error is:

    [Stino - Start building "t5"...]
    [  3%] Creating C:\Users\lov\AppData\Local\Temp\Stino_build\t5\t5.ino.cpp.o...
    The filename, directory name, or volume label syntax is incorrect.

See also [see similar question, that answer not working here][1].

Path to IDE app is `C:\Program Files (x86)\added\Arduino`.

  [1]: https://arduino.stackexchange.com/questions/18601/sublime-text-compilation-issue

title: Sublime Text 2 with stino, compilation gives "filename ... is incorrect" Arduino IDE 1.7.8

Answers: 1

body:
Sorry but this is too big for a comment.

Firstly please can you check the obvious, in Windows Explorer paste the path C:\Users\lov\AppData\Local\Temp\Stino_build\t5 into the address bar and does the directory exist. (I have fallen for that so many times)

Secondly do you have permission to create a file there?

Have you updated the IDE? Does blink compile?

Have you tried running the IDE as admin?

Hopefully one of those will fix it.


body:
I would like to copy a file that is in the root folder of my Yun, to my Macbook. They are connected with an ethernet cable and I am logged into the Yun through ssh.
The Yun's IP is 192.168.2.16 while the Mac's is 192.168.2.1.

How can I copy a file from the Yun?

Once I tried to copy a file from the Macbook to the Yun using "scp" and it worked, but now I don't know how to do for the other direction

title: How to copy files from Yun to local computer?

Answers: 1

body:
You simply reverse the arguments.  Whatever you used to copy a file *to* the Yun you just do the opposite to copy *from* the Yun.

For instance, if you copied to the Yun using:

    scp /my/local/file root@192.168.2.16:/where/you/want/it

Then you would change it around to copy from the Yun thus:

    scp root@192.168.2.16:/path/to/file /where/you/want/it/to/go


body:
Can somebody please tell me what is the operating voltage of ESP8266?

What is the A0 voltage range?

I am powering it up from USB (5v) and have a sensor that comes back with Analog value, to calculate it correctly I am asked to provide "Logical Voltage" value that is either 3300 or 5000 (3.3v or 5v). Sensor is connected to 3.3V port as there is no 5v port on the board.

What do I choose here 3300 or 5000 for NodeMCU V3?

Thank you.

title: ESP8266 NodeMCU v3 basic questions

Answers: 1

body:
The subtle clue is in the voltage that is available. That is, the only voltage provided on the board is 3.3v. That's a slight hint that the board might run at 3.3v. And you would be right in that assumption.

The ESP8266 chips, as are most modern MCUs more powerful than 8-bit, 3.3v devices.

So you would choose 3300 as your "Logical Voltage" value.  Or better still, measure the 3.3V and find exactly what it is and use that value x 1000 (for example 3317 or 3295).


body:
[![Picture of the boards][1]][1]

I am trying to make motion capture and someone gave me these boards.

I think it's a test board for MPU 9500. I tried to google but I only found datasheets. What boards are these?

"ITG-3500 evb" is written on the back of the green board.
I think this is <datasheet>[datasheet](http://store.invensense.com/datasheets/invensense/AN-IVS-0001EVB-00-v1-2.pdf) of green board maybe

"EV_ARM_XXAXA_D" is written on the back of the blue board.

  [1]: https://i.stack.imgur.com/9ee55.jpg

title: How to use ITG-3500 evb

Answers: 2

body:
The green board is an ITG-3500 (3 axis gyroscope) evaluation board of some form.

The blue board is some form of microcontroller evaluation board. It probably has one of the Atmel SAM chips on it since it mentions ARM.

That's about all you'll get from us I'm afraid, unless there is the highly unlikely situation that someone here happens to have the exact same boards as you.

body:
I have had to, briefly, play with these boards a while back, and although I used different revisions and versions of the boards, they are probably the same functionally. Unfortunately, I don't have any of my old notes as I have moved country. Regardless...

As Majenko says in his [answer][1] the green board is an evaluation board for the ITG-3500 3-axis gyroscope, which is presumably the SMD chip (in a QFN format) mounted on it, in the lower part of the board (looking at your photo). A [data sheet on the *similar* ITG-3200][2] (note *not* the evaluation board itself)  can be found on SparkFun. To quote part of the product description:

> The ITG-3200 is the world’s first single-chip, digital-output, 3-axis
> MEMS gyro IC optimized for gaming, 3D mice, and 3D remote control
> applications. The part features enhanced bias and sensitivity
> temperature stability, reducing the need for user calibration. Low
> frequency noise is lower than previous generation devices, simplifying
> application development and making for more-responsive remote
> controls.
>
>The ITG-3200 features three 16-bit analog-to-digital
> converters (ADCs) for digitizing the gyro outputs, a user-selectable
> internal low-pass filter bandwidth, and a Fast-Mode I2C (400kHz)
> interface. Additional features include an embedded temperature sensor
> and a 2% accurate internal oscillator. This breakthrough in gyroscope
> technology provides a dramatic 67% package size reduction, delivers a
> 50% power reduction, and has inherent cost advantages compared to
> competing multi-chip gyro solutions.

In addition, in case it is of any use, here is the [datasheet for the, again similar, ITG-3701][3], which I located on the [Digi sales site][4]. Frustratingly, I am unable to locate a datasheet for the ITG-3500 - however, you mentioned that you found some datasheets - could you edit your answer to include the links, please?

The Blue board is a "Gyroscope Evaluation Board: EV_INV-ARM" manufactured by InvenSense Inc., and to quote its [product description][5]:

>The InvenSense ARM reference board provides a bridge function between InvenSense evaluation boards and a PC. It connects to a PC via USB and to InvenSense evaluation boards via SPI or I2C. The ARM processor on the reference board is not meant to be reprogrammed by the user. It contains all code necessary to be used in conjunction InvenSense evaluation boards. (Note that separate demonstration software may accompany the individual evaluation boards with which this device connects.)

Here is a link to the [EV_INV-ARM DataSheet][6]. The Atmel chip on it is possibly the AT91SAM7SE512 MCU, and here is a link to its [product specification][7].

Software wise, you may find this [Linux kernel driver for the ITG-3500][8] extremely useful.

----

### TL;DR

It seems like you need to get hold of the separate demonstration software for the ITG-3500 evaluation board, according to the EV-INV_ARM's product description, in order to *easily* make it do something.

  [1]: https://arduino.stackexchange.com/questions/20286/how-to-use-itg-3500-evb#answer-20287
  [2]: https://www.sparkfun.com/datasheets/Sensors/Gyro/PS-ITG-3200-00-01.4.pdf
  [3]: http://store.invensense.com/datasheets/invensense/PS-ITG-3701.pdf
  [4]: http://www.digikey.com/product-detail/en/ITG-3701/1428-1050-1-ND/5015524
  [5]: http://store.invensense.com/ProductDetail/EVINVARMG-InvenSense-Inc/425140/
  [6]: http://store.invensense.com/datasheets/invensense/AN-000039 v1.0.pdf
  [7]: http://www.atmel.com/devices/SAM7SE512.aspx
  [8]: https://android.googlesource.com/kernel/tegra.git/+/eb72d0308d4f46ff106f7097a3c040cfda83733d/drivers/staging/iio/imu/inv_mpu/README


body:
I want to run a 9g servo off of the pins from an arduino nano board, using only the 5v USB connection.

The servo specifically is a SG90, which I have measured a stall current of ~250mA - I don't intend to stall it, just have it run with almost no load

I am not sure which pins to power it off of from the arduino itself - do I use the VCC or the +5v? does it matter which ground I use? should I use a breadboard to help me place any other components that may be needed, i.e. a capacitor or something? does the arduino nano negotiate to get more than the default of 100mA from a USB power connection?

title: Can I power a 9g servo from an arduino nano with USB power only?

Answers: 1

body:
<strike>The max current of the Arduino-Nano 5V Pin is 200mA. So if you draw more than that it might damage your Arduino.</strike>

Here is an interesting summary regarding the Maximum Ratings of the Arduino Nano: https://electronics.stackexchange.com/questions/67092/how-much-current-can-i-draw-from-the-arduinos-pins

> The 5V pin of the arduino is not connected through the
> microcontroller. As such, it can source significantly more power. When
> you are powering your arduino from USB, the USB interface limits your
> total power consumption to 500 mA.

So yes, it actually seems you can draw 250mA out of the 5V PIN.

> do I use the VCC or the +5v?

You use +5V, because VCC is for powering your Arduino with an external Power Source. It allows you to use up to 7-12V (recommended), or up to 6-20V (limits).

> does it matter which ground I use?

Doesn't matter

> should I use a breadboard to help me place any other components that may be needed, i.e. a capacitor or something?

A breadboard makes it easier for you, to test your circuit. But you can do it without if you like. Then you possibly have to solder some connections

See also the [offical Arduino Page][1] for the Nano.

  [1]: https://www.arduino.cc/en/Main/ArduinoBoardNano


body:
Please, help me to set up Clion + Arduino.

Clion has an Arduino plugin which I've installed. Here is some instruction on Github but I'm fully noob about `cmake` and other things which are talking about in instruction. I have only used Arduino IDE before for my simple projects. Now in CLion I can create an Arduino projects but autocompletion doesn't work. Actually it works but does it on true C, not for Arduino code.

So if you can please explain like for complete idiot, what I should change to get working Arduino autocompletion.

title: CLion + Arduino

Answers: 2

body:
Rather than using any plugin, I am using CLion with [PlatformIO][1], which supports several IDEs. CLion then not only gives you code completion, but also full support for refactoring, Git, and much much more.

From [its documentation][2]:

> [...] generate project via `platformio init --ide` command:
>
>     platformio init --ide clion --board %TYPE%
>
>     # For example, generate project for Arduino UNO
>     platformio init --ide clion --board uno

Then import the project in CLion and you're about done.

Some hints:

- Make sure your code is in the `src` folder, and that the main file has a `.cpp` extension.

- For other files: either rename all `.ino` files to use `.cpp`, or tell CLion to associate the `.ino` extension with C++ files. (Preferences, Editors, File Types.)

- Whenever adding libraries to the `lib` folder (and using `#include` to refer to them), just run the above `init` command again.

- If you're using ESP-boards and changed `platform.txt` for an alternative `esptool`, then note that PlatformIO [needs a different hack][3].

- Rather than using the CLion Serial Monitor plugin, I simply use a Terminal within CLion to upload and start the monitor as soon as possible:

      pio run -t upload; pio device monitor -b 115200

- If you always want to upload and monitor whenever using `pio run`, then add:

      [env]
      targets = upload, monitor
      upload_protocol = esptool
      upload_speed = 115200
      monitor_speed = 115200

- Nowadays, [CLion has a PlatformIO plugin][4] as well, including a menu Tools, PlatformIO with commands such as Re-init.

  [1]: http://platformio.org/
  [2]: https://docs.platformio.org/en/latest/integration/ide/clion.html
  [3]: https://arduino.stackexchange.com/questions/20219/upload-with-esptool-fails-with-espcomm-send-command-cant-receive-slip-payload/20220#20220http://
  [4]: https://plugins.jetbrains.com/plugin/13922-platformio-for-clion

body:
I know this was asked a long time ago, but maybe it will be useful for someone. I'm a beginner, regarding all this stuff, so if anybody knows a better way to do it, please correct me. here is how I set up CLion for Arduino (on Windows 10):

CLion 2016.1.3 + Arduino 1.6.9 + plugin

1. Download and install the official Arduino IDE (1.6.9).

2. Download and install [MinGW][1] to 'C:\MinGW'

3. In MinGW, install: 'mingw32-base' and 'mingw32-gcc-g++'

4. Download and install [CLion][2].

5. Create an 'untitled' project, just to open CLion.

6. In CLion > Settings > Plugins > Browse Repositories > Search for and install: 'Arduino' (tools integration), and 'Serial Monitor' (misc).

7. In CLion > Settings > Search > type 'MinGW'

8. At the environment select 'Use MinGW home', and browse to MinGW folder ('C:\MinGW'). Press apply, and wait until CLion finds the environment.

9. In File > Close project.

10. Open any file manager and go to 'c:\Users\name\ClionProjects\' and delete the 'untitled' project you just created.

11. Open CLion, select 'New Arduino sketch project'

12. In the project directory > 'open cmakelists.txt' and configure lines:

        6: set board version
        7: set port (you can find out port# from the Arduino IDE)
        8: set the path where you installed your Arduino libraries (Arduino sketch folder)

        set(${CMAKE_PROJECT_NAME}_BOARD uno)
        set(${CMAKE_PROJECT_NAME}_PORT COM3)
        LINK_DIRECTORIES(c:\\ARDUINO\\libraries)

13. In the upper right corner in CLion, near the green 'Play' button, select 'Edit Configuration', on the left select 'Application' > 'Upload', and set:

        -target: 'upload'
        -configuration: 'debug'
        -executable: the project name

 then press ok.

14. In the project .ino file, write some really simple code (blink).

15. Connect an Arduino Uno via USB, and press the green 'play' button to upload the sketch.

16. To start serial monitor:

    - In CLion main window bottom left, click serial monitor tab (in 'the tool buttons')
 - Click the wrench icon to set up port and baud rate.
 - On the top of the wrench icon, click the blue 'connect' icon.
 - If values did not appear 'correctly', click the white 'switch to hex' icon (on the right of the wrench).
 - Before uploading sketch, disconnect the serial monitor.

17. For CLion to properly find the libraries, make sure to use the same name for the lib folder as for the '.h' file. example: for DallasTemperature.h use folder name DallasTemperature. After #inlcude-ing new libs, right click on 'External libraries folder' and select 'Reload cmake project'.

18. You may want to do further configuration in CLion settings like: theme, colours, text size, etc.

19. Also, you can configure some handy 'live templates', like: `serialprintln`, `digitalwrite`, `pinmode`, `switch`, etc. to enhance your productivity.

  [1]: https://sourceforge.net/projects/mingw/files/latest/download?source=files
  [2]: https://www.jetbrains.com/clion/download/#section=windows-version


body:
i' m trying to simulate a robot' s movement on a 2d array. In my case, robot goes forward firstly, if it sees a engel, it turns left and continues its movement. The problem is that, i could not present turning left and moving on left-direction on the initial matrix.

Here' s my code:

    #include <Servo.h>
    #define x 7                                         //Matrix dimensions
    #define y 7

    const int trigPin = 12;
    const int echoPin = 11;

    Servo myServo;                                     //variable definations
    Servo myServo2;

    int pos = 0;

    int counter;
    int counter1 = 0;
    int counter2;
    int counter3;

    int integer;
    int integer2;
    int integer4;

    long duration;
    long distance;

    void setup() {
     Serial.begin(9600);
     myServo.attach(9);
     myServo2.attach(10);
     pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
     pinMode(echoPin, INPUT); // Sets the echoPin as an Input
    }

    void loop() {
     int my2dArray[x][y] = {                          // initial matrix
      {1, 1, 1, 1, 1, 1, 1},
      {1, 1, 1, 1, 1, 1, 1},
      {1, 1, 1, 1, 1, 1, 1},
      {1, 1, 1, 0, 1, 1, 1},
      {1, 1, 1, 1, 1, 1, 1},
      {1, 1, 1, 1, 1, 1, 1},
      {1, 1, 1, 1, 1, 1, 1},
     };
     // Clears the trigPin
     digitalWrite(trigPin, LOW);
     delayMicroseconds(2);
    // Sets the trigPin on HIGH state for 10 micro seconds
     digitalWrite(trigPin, HIGH);
     delayMicroseconds(10);
     digitalWrite(trigPin, LOW);
    // Reads the echoPin, returns the sound wave travel time in microseconds
     duration = pulseIn(echoPin, HIGH);
    // Calculating the distance
     distance = duration * 0.034 / 2;
     int robot = my2dArray[3][3];                   // first place of robot

     if (counter1 > 0) {
      for (integer = 0;  integer < counter1; integer += 1) {
       if (distance < 10) {                                  //seeing     the object
        for (pos = 0; pos <= 180 ; pos += 1) {              //turning left
         myServo.write(pos);
        }

        for (pos = 0; pos <= 180  ; pos += 1) {            //moving on after turning
         myServo.write(pos);
         myServo2.write(pos);

         if (pos == 180) {
          counter3 +=  1;
         }
        }

        Serial.println(integer);

        for (integer4 = 0;  integer4 < counter3; integer4 += 1) {     //modifying matrix if there is an object
         my2dArray[3 + integer][3 + integer4] = robot * my2dArray[3 + integer][3 + integer4];
        }

        Serial.println("Break condition.");
        break;
       } else {
        my2dArray[3 + integer][3] = robot * my2dArray[3 + integer][3];    //modifying matrix in case of there is no object
       }
      }
     }

     for (integer2 = 0; integer2 < 7; integer2++) {                          //displaying matrix
      Serial.print(my2dArray[integer2][0]);
      Serial.print("|");
      Serial.print(my2dArray[integer2][1]);
      Serial.print("|");
      Serial.print(my2dArray[integer2][2]);
      Serial.print("|");
      Serial.print(my2dArray[integer2][3]);
      Serial.print("|");
      Serial.print(my2dArray[integer2][4]);
      Serial.print("|");
      Serial.print(my2dArray[integer2][5]);
      Serial.print("|");
      Serial.println(my2dArray[integer2][6]);
     }

     Serial.println();

     for (pos = 0; pos <= 180  ; pos += 1) {                               // moving forward as first movement
      myServo.write(pos);
      myServo2.write(pos);

      if (pos == 180) {
       counter1 +=  1;
      }
     }

     delay(1000);
    }

The problem part is:

    for (integer4 = 0;  integer4 < counter3; integer4 += 1){      //modifying matrix if there is an object

        my2dArray[3 + integer][3+integer4] = robot * my2dArray[3 + integer][3+integer4];

         }

"integer" value does not change in the problem part, it' s always 0 in despite of the first for loop. How can i pass the "integer" to the problem part properly?

title: For loop question-Simulating a robot' s movement on a 2d array

Answers: 1

body:
Your program is hard to follow with all those meaningless "integer" and "counter" variables, and the logic seems a little odd in places, but I believe the cause of your problems is the `break` statement:

    for (integer = 0; integer < counter1; integer += 1) {
        if (distance < 10) {
            // ...
            for (integer4 = 0;  integer4 < counter3; integer4 += 1) {     //modifying matrix if there is an object
                my2dArray[3 + integer][3 + integer4] = robot * my2dArray[3 + integer][3 + integer4];
            }
            break; // << HERE
        } else {
            // ...
        }
    }

What is the purpose of that `break`? I think you are using it to jump out of the `if` so that it doesn't run the `else`, which it *won't run anyway since it's an else condition*. Instead, what the `break` is actually doing is terminating the `for` loop after the first iteration that hits that inner `if` condition. That is, as long as the distance is less than 10 it will only ever run the `for` once, and so `integer` will only ever be 0.


body:
I build a circuit that work on breadboard now i try to prototype it,so i start solder it on a prototype board and the arduino is out of sync.So i check the tension and for some reason it's 4.4~4.6 on the Vin pin of Atmega328 so i try to find how to debug.I don't have a lot of theorical knowledge on electronic,but my thougt was as long as everything is plug in parrallel the tension should remain the same ( and i don't have any thing in serie) so for the tension to drop i may have something acting as Resistor, and i try to find how and what.
I use 22AWG 0.7mm wire o create a 5V line and my GND line on each side of the Atmega ( roughly 7 cm on each side),i start to wondering if it was not a bad idea. I have picture of my prototype bellow,but it's messy so not sure it help. My question is how to you proceed to troubleshoot this thing ? What are the step you do to find out where is the problem [![Atmega328][1]][1]

  [1]: https://i.stack.imgur.com/WgnF6.jpg

title: Arduino on breadboard Tension is 4.4V instead of 5 V,looking for some guidance

Answers: 1

body:
The yellow-boxed 5V and Gnd buses on the [freetronics.com.au ProtoShield Basic for Arduino](http://www.freetronics.com.au/products/protoshield-basic#.VrLTZt_U2kA) [like you used] already have copper strips connecting the holes.  The strips run on both sides of the board and the holes are plated-through, so there's no need (for this kind of circuit) to have additional bus wire running along above the boxes.  Having that extra wire there gets in the way of making changes, whether for debugging the circuit or for adding or replacing components.

From the [frontside picture](http://s12.postimg.org/99wap5rr1/MG_3581.jpg), it appears you may have a voltage regulator on board.  (However, I don't see the connections to 5V and Gnd, so might be misinterpreting things.)

If your board input is 5 VDC from an external supply, feeding that 5 V into a regulator will lose half a volt or so, which may account for what you are seeing.

However, let's instead suppose you are putting 7 to 12 VDC into an on-board 5V regulator and then measuring 4.4-4.6 V out.  One possibility is the regulator isn't working.  This can happen if the regulator's input or output capacitors are the wrong sizes or wrong kinds, and cause oscillation.  Diagnosing that kind of problem is straightforward if you look at the 5V line with an oscilloscope.  Another possibility is something drawing a *lot* of current (eg a couple of amps) and taking the 5V line out of regulation.  That's usually easy to diagnose because of all the resulting smoke and heat.

Drawing a good schematic is an excellent step to take to allow better problem debugging.

Other steps to take:

* Measure the amount of current the whole board is drawing, or that the NRF24L01 is drawing.  (For the latter measurement, you might need to lift your ground lead off the NRF24L01 board and put the ammeter into the ground circuit.  In general you want all the grounds to be at the same voltage, so the voltage drop across the ammeter is a problem, but not much of one.)

* Pull the '328P chip and see if that makes any difference.  In general, it's a good idea to work out a prototype board's power supply problems – such as shorts, reversed electrolytics, incorrect resistors – in advance of installing a microcontroller chip onto the board.

* Remove the NRF24L01, if feasible, while debugging the power supply.  If you can't easily remove it, check your schematic and see if all of its pins except 5V and Gnd are open when the '328P chip is pulled.  If so, you can detach the NRF24L01  ground lead to take it out of the circuit.  If, during testing, you unsolder and remove the NRF24L01 board, consider making a socket for it from two 5-pin female header strips.


body:
I'm doing a little project that, on a press of a button, will light up three LEDs and then will turn off the LEDs in different times. I'm using the `millis()` function to control the time that each LED will be on.

On the first time that I press the button, everything works fine. But the problem starts when I press the button for the second time.

If I press the button soon after the loop ends, something goes wrong and the behavior of the LED become a mess (just one or two LEDs light up in weird times). But, if I wait about 2 seconds before pressing the button for the second time, everything goes right.

Here's my code:

    const int ledPin1 =  11;
      const int ledPin2 =  12;
      const int ledPin3 =  13;
      const int buttonPin = 2;

      int buttonState = 0;
      long previousMillis1 = 0;
      long previousMillis2 = 0;
      long previousMillis3 = 0;

      int state = 0;

      void setup()
      {
        pinMode(ledPin1, OUTPUT);
        pinMode(ledPin2, OUTPUT);
        pinMode(ledPin3, OUTPUT);
        pinMode(buttonPin, INPUT);

        Serial.begin(9600);
      }

      void loop()
      {

           buttonState = digitalRead(buttonPin);

           if (buttonState == HIGH) {
            state = 1;
           }

           if (state == 1)
           {
            taskExecute(3000, 2000, 4000);
           }
      }

      void taskExecute(int tMotor1, int tMotor2, int tMotor3)
      {

        int ledState1 = HIGH;
        int ledState2 = HIGH;
        int ledState3 = HIGH;

        digitalWrite(ledPin1, ledState1);
        digitalWrite(ledPin2, ledState2);
        digitalWrite(ledPin3, ledState3);

        do
        {
          unsigned long currentMillis = millis();

          if(currentMillis - previousMillis1 > tMotor1)
          {
            previousMillis1 = currentMillis;

            if (ledState1 == HIGH)
              ledState1 = LOW;

            digitalWrite(ledPin1, ledState1);
          }

          if(currentMillis - previousMillis2 > tMotor2)
          {
            previousMillis2 = currentMillis;

            if (ledState2 == HIGH)
              ledState2 = LOW;

            digitalWrite(ledPin2, ledState2);
          }

          if(currentMillis - previousMillis3 > tMotor3)
          {
            previousMillis3 = currentMillis;

            if (ledState3 == HIGH)
              ledState3 = LOW;

            digitalWrite(ledPin3, ledState3);
          }
        } while (ledState1 == HIGH || ledState2 == HIGH || ledState3 == HIGH);
        state = 0;
      }

Other strange thing that happens is that sometimes the time that i've been set in millis for the led get on become a little different. Example: when I press the button, the LED 1 needs to light up for 3 seconds, but he lights up just 2.5 seconds.

What i'm doing wrong? Thanks!!

title: millis() not working properly

Answers: 1

body:
The variables `previousMillis` (1-3) are not properly initialised.  So if you wait a while before pressing the button, that delay time becomes part of the time that the LED is illuminated for.

If your `taskExecute()` function sets them before the loop, this will fix that:

    void taskExecute(int tMotor1, int tMotor2, int tMotor3)
    {
        int ledState1 = HIGH;
        int ledState2 = HIGH;
        int ledState3 = HIGH;

        digitalWrite(ledPin1, ledState1);
        digitalWrite(ledPin2, ledState2);
        digitalWrite(ledPin3, ledState3);

        unsigned long time_now = millis();
        previousMillis1 = time_now;
        previousMillis2 = time_now;
        previousMillis3 = time_now;

        do
        {
            ...
        } while (ledState1 == HIGH || ledState2 == HIGH || ledState3 == HIGH);
        state = 0;
    }

On a coding-style note - I did not initially see the resetting of the global variable `state=0` at the end of the `taskExecute()` function.  It might be better to move this up to underneath the initial call to `taskExecute()` so all the `state` handling is in one place.


body:
I have done a lot of tries to make my two IMU work with my arduino. I'm also done with many research about it and I found this code:

     // I2C device class (I2Cdev) demonstration Arduino sketch for MPU6050 class
     // 10/7/2011 by Jeff Rowberg <jeff@rowberg.net>
     // Updates should (hopefully) always be available at
     //https://github.com/jrowberg/i2cdevlib
     //
    // Changelog:
    //     2011-10-07 - initial release

    /* ============================================
     I2Cdev device library code is placed under the MIT license
     Copyright (c) 2011 Jeff Rowberg

     // Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE   implementation
     // is used in I2Cdev.h
     #include "Wire.h"

     // I2Cdev and MPU6050 must be installed as libraries, or else the .cpp/.h files
    // for both classes must be in the include path of your project
     #include "I2Cdev.h"
     #include "MPU6050.h"

    // class default I2C address is 0x68
    // specific I2C addresses may be passed as a parameter here
    // AD0 low = 0x68; (default for InvenSense evaluation board)
    //AD0 high = 0x69;
    MPU6050 accelgyro;
    // accelgyroIC1.initialize();
    //accelgyroIC2.initialize();
    MPU6050 accelgyroIC1(0x69);
    MPU6050 accelgyroIC2(0x68);

    int16_t ax1, ay1, az1;
    int16_t gx1, gy1, gz1;

    int16_t ax2, ay2, az2;
    int16_t gx2, gy2, gz2;

    #define LED_PIN 13
    bool blinkState = false;

    void setup() {
    // join I2C bus (I2Cdev library doesn't do this automatically)
    Wire.begin();

    // initialize serial communication
    // (38400 chosen because it works as well at 8MHz as it does at 16MHz, but
    // it's really up to you depending on your project)
    Serial.begin(38400);

    // initialize device
    Serial.println("Initializing I2C devices...");
    //accelgyro.initialize();
    accelgyroIC1.initialize();
    accelgyroIC2.initialize();

    // verify connection
    Serial.println("Testing device connections...");
    Serial.println(accelgyroIC1.testConnection() ? "MPU6050 #1 connection successful" : "MPU6050 connection failed");
    Serial.println(accelgyroIC2.testConnection() ? "MPU6050 #2 connection successful" : "MPU6050 connection failed");

    // configure Arduino LED for
      pinMode(LED_PIN, OUTPUT);
    }

    void loop() {
    // read raw accel/gyro measurements from device
    accelgyroIC1.getMotion6(&ax1, &ay1, &az1, &gx1, &gy1, &gz1);
    accelgyroIC2.getMotion6(&ax2, &ay2, &az2, &gx2, &gy2, &gz2);

    // these methods (and a few others) are also available
    //accelgyro.getAcceleration(&ax, &ay, &az);
    //accelgyro.getRotation(&gx, &gy, &gz);

    // display tab-separated accel/gyro x/y/z values
    Serial.println("MPU1:");      Serial.print("\t"    );     Serial.print("\t"      );
    Serial.print(ax1);        Serial.print("\t"    );  Serial.print("\t"    );
    Serial.print(ay1);        Serial.print("\t"    );  Serial.print("\t"    );
    Serial.print(az1);        Serial.print("\t"    );  Serial.print("\t"    );
    Serial.print(gx1);        Serial.print("\t"    );  Serial.print("\t"    );
    Serial.print(gy1);        Serial.print("\t"    );  Serial.print("\t"    );
    Serial.println(gz1);
    delay(1000);

    // display tab-separated accel/gyro x/y/z values
    Serial.println("MPU2:");     Serial.print("\t"    );     Serial.print("\t"    );
    Serial.print(ax2);       Serial.print("\t"    );   Serial.print("\t"    );
    Serial.print(ay2);       Serial.print("\t"    );   Serial.print("\t"    );
    Serial.print(az2);       Serial.print("\t"    );   Serial.print("\t"    );
    Serial.print(gx2);       Serial.print("\t"    );   Serial.print("\t"    );
    Serial.print(gy2);       Serial.print("\t"    );   Serial.print("\t"    );
    Serial.println(gz2);
    delay(1000);

    // blink LED to indicate activity
    blinkState = !blinkState;
    digitalWrite(LED_PIN, blinkState);
    }

After running it, I'm wondering why the two MPU connections failed. Please see the attached image for the result I got.[![enter image description here][1]][1]

And I guess that should be the probable reason why everytime I try to move the MPU1, the MPU2 varies like what is happening to the MPU1, and there are times that they get the same value.

I also even tried to edit the code I posted above, and here it goes...

     #include <MPU9250.h>

     // I2C device class (I2Cdev) demonstration Arduino sketch for MPU6050 class
     // 10/7/2011 by Jeff Rowberg <jeff@rowberg.net>
     // Updates should (hopefully) always be available at
     //https://github.com/jrowberg/i2cdevlib
     //
     // Changelog:
     //     2011-10-07 - initial release

    // Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation
     // is used in I2Cdev.h
     #include "Wire.h"

     // I2Cdev and MPU6050 must be installed as libraries, or else the .cpp/.h files
     // for both classes must be in the include path of your project
     #include "I2Cdev.h"
     #include "MPU6050.h"

     // class default I2C address is 0x68
     // specific I2C addresses may be passed as a parameter here
      int AD0LOW= 0x68; //(default for InvenSense evaluation board)
      int AD0HIGH= 0x69;
      //MPU9250 accelgyro;
      int accelgyroIC1 ();
      int accelgyroIC2 ();
      //MPU9250 accelgyroIC1(0x68);
      //MPU9250 accelgyroIC2(0x69);

      int16_t ax1, ay1, az1;
      int16_t gx1, gy1, gz1;
      int16_t mx1, my1, mz1;

      int16_t ax2, ay2, az2;
      int16_t gx2, gy2, gz2;
      int16_t mx2, my2, mz2;

      #define LED_PIN 13
      bool blinkState = false;

      void setup() {
       // join I2C bus (I2Cdev library doesn't do this automatically)
       Wire.begin();
       Serial.begin(38400);

      // initialize device
       Serial.println("Initializing I2C devices...");
      //accelgyro.initialize();
      int accelgyroIC1();
      int accelgyroIC2();

       // verify connection
       Serial.println("Testing device connections...");
       //    Serial.println(accelgyroIC1.testConnection() ? "MPU9250 #1     connection successful" : "MPU9250 connection failed");
       //    Serial.println(accelgyroIC2.testConnection() ? "MPU9250 #2 connection successful" : "MPU9250 connection failed");

        // configure Arduino LED for
        pinMode(LED_PIN, OUTPUT);
        }

        void loop() {
       // read raw accel/gyro measurements from device
       //    accelgyroIC1.getMotion9(&ax1, &ay1, &az1, &gx1, &gy1, &gz1);
       //  accelgyroIC2.getMotion9(&ax2, &ay2, &az2, &gx2, &gy2, &gz2);

        accelgyroIC1.getMotion9(&ax1, &ay1, &az1, &gx1, &gy1, &gz1, &mx1, &my1, &mz1);
        accelgyroIC2.getMotion9(&ax2, &ay2, &az2, &gx2, &gy2, &gz2, &mx2, &my2, &mz2);

        // these methods (and a few others) are also available
        //accelgyro.getAcceleration(&ax, &ay, &az);
        //accelgyro.getRotation(&gx, &gy, &gz);

        // display tab-separated accel/gyro x/y/z values
        /*Serial.println("MPU1:");      Serial.print("\t"    );              Serial.print("\t"    );
       Serial.print(ax1);        Serial.print("\t"    );  Serial.print("\t"    );
       Serial.print(ay1);        Serial.print("\t"    );  Serial.print("\t"    );
       Serial.print(az1);        Serial.print("\t"    );  Serial.print("\t"    );
       Serial.print(gx1);        Serial.print("\t"    );  Serial.print("\t"    );
        Serial.print(gy1);        Serial.print("\t"    );  Serial.print("\t"    );
        Serial.println(gz1);
        delay(1000);

        // display tab-separated accel/gyro x/y/z values
         Serial.println("MPU2:");     Serial.print("\t"    );     Serial.print("\t"    );
        Serial.print(ax2);       Serial.print("\t"    );   Serial.print("\t"    );
        Serial.print(ay2);       Serial.print("\t"    );   Serial.print("\t"    );
        Serial.print(az2);       Serial.print("\t"    );   Serial.print("\t"    );
        Serial.print(gx2);       Serial.print("\t"    );   Serial.print("\t"    );
        Serial.print(gy2);       Serial.print("\t"    );   Serial.print("\t"    );
        Serial.println(gz2);
        delay(1000);*/

        Serial.print("MPU1:");
        Serial.print(ax); Serial.print("\t");   Serial.print("\t");   Serial.print("\t");
        Serial.print(ay); Serial.print("\t");   Serial.print("\t");   Serial.print("\t");
        Serial.print(az); Serial.print("\t");   Serial.print("\t");   Serial.print("\t");
        Serial.print(gx); Serial.print("\t");   Serial.print("\t");   Serial.print("\t");
        Serial.print(gy); Serial.print("\t");   Serial.print("\t");   Serial.print("\t");
        Serial.print(gz); Serial.print("\t");   Serial.print("\t");   Serial.print("\t");
        Serial.print(mx); Serial.print("\t");   Serial.print("\t");   Serial.print("\t");
        Serial.print(my); Serial.print("\t");   Serial.print("\t");   Serial.print("\t");
        Serial.println(mz);

         Serial.print("MPU2:");
        Serial.print(ax); Serial.print("\t");   Serial.print("\t");     Serial.print("\t");
         Serial.print(ay); Serial.print("\t");   Serial.print("\t");   Serial.print("\t");
         Serial.print(az); Serial.print("\t");   Serial.print("\t");   Serial.print("\t");
         Serial.print(gx); Serial.print("\t");   Serial.print("\t");   Serial.print("\t");
         Serial.print(gy); Serial.print("\t");   Serial.print("\t");   Serial.print("\t");
         Serial.print(gz); Serial.print("\t");   Serial.print("\t");   Serial.print("\t");
         Serial.print(mx); Serial.print("\t");   Serial.print("\t");   Serial.print("\t");
         Serial.print(my); Serial.print("\t");   Serial.print("\t");   Serial.print("\t");
          Serial.println(mz);

         // blink LED to indicate activity
         blinkState = !blinkState;
         digitalWrite(LED_PIN, blinkState);
          }

And please see the error that it displayed: (please see attached image)
[![enter image description here][2]][2]

With a result of: (please see image attched)[![enter image description here][3]][3]

  [1]: https://i.stack.imgur.com/LA6ke.jpg
  [2]: https://i.stack.imgur.com/Hnc47.jpg
  [3]: https://i.stack.imgur.com/x1Zb6.jpg

Please help me with these. I'm getting confused with my codes that I should be using and how to edit them. Please guide me on how to put connections in between them..

Thank you...

...Thom

This is the error message I copied:

    Arduino: 1.6.7 (Windows 8.1), Board: "Arduino Mega ADK"

    C:\Users\Jasmin.Morales\Desktop\_2MPU_Practice\_2MPU_Practice.ino: In function 'void loop()':

    _2MPU_Practice:70: error: request for member 'getMotion9' in 'accelgyroIC1', which is of non-class type 'int()'

       accelgyroIC1.getMotion9(&ax1, &ay1, &az1, &gx1, &gy1, &gz1, &mx1, &my1, &mz1);

                    ^

    _2MPU_Practice:71: error: request for member 'getMotion9' in 'accelgyroIC2', which is of non-class type 'int()'

       accelgyroIC2.getMotion9(&ax2, &ay2, &az2, &gx2, &gy2, &gz2, &mx2, &my2, &mz2);

                    ^

    _2MPU_Practice:100: error: 'ax' was not declared in this scope

         Serial.print(ax); Serial.print("\t");   Serial.print("\t");   Serial.print("\t");

                      ^

    _2MPU_Practice:101: error: 'ay' was not declared in this scope

         Serial.print(ay); Serial.print("\t");   Serial.print("\t");   Serial.print("\t");

                      ^

    _2MPU_Practice:102: error: 'az' was not declared in this scope

         Serial.print(az); Serial.print("\t");   Serial.print("\t");   Serial.print("\t");

                      ^

    _2MPU_Practice:103: error: 'gx' was not declared in this scope

         Serial.print(gx); Serial.print("\t");   Serial.print("\t");   Serial.print("\t");

                      ^

    _2MPU_Practice:104: error: 'gy' was not declared in this scope

         Serial.print(gy); Serial.print("\t");   Serial.print("\t");   Serial.print("\t");

                      ^

    _2MPU_Practice:105: error: 'gz' was not declared in this scope

         Serial.print(gz); Serial.print("\t");   Serial.print("\t");   Serial.print("\t");

                      ^

    _2MPU_Practice:106: error: 'mx' was not declared in this scope

         Serial.print(mx); Serial.print("\t");   Serial.print("\t");   Serial.print("\t");

                      ^

    _2MPU_Practice:107: error: 'my' was not declared in this scope

         Serial.print(my); Serial.print("\t");   Serial.print("\t");   Serial.print("\t");

                      ^

    _2MPU_Practice:108: error: 'mz' was not declared in this scope

         Serial.println(mz);

                        ^

    exit status 1
    request for member 'getMotion9' in 'accelgyroIC1', which is of non-class type 'int()'

      This report would have more information with
      "Show verbose output during compilation"
      enabled in File > Preferences.

title: Two MPU 9250 connected to one arduino (Code of the MPU6050 edited for MPU9250)

Answers: 0


body:
I just stayed on `delay()` since that is the only thing I know but the thing is `delay()` cannot be interrupted. What I'm trying to achieve with this code is:

 1. When the soilSensor detects moisture it would send a text message to a number only ONCE without terminating the program even if in the next loop the soilSensor is still detecting moisture.

 2. The soilSensor's delay is `delay(60000)` and we would still wait for while to finish the delay but what if in the middle of the soilSensor's `delay(60000)` there is a movement for just about 5 seconds? What to do so that the tiltSensor can overlap the soilSensor's delay and sends a message to a number?

I want this program to run forever. Please help me! I needed this ASAP!

    #include <SoftwareSerial.h>
    SoftwareSerial SIM900(7, 8);
    int led=22;

    void setup()
    {
      Serial.begin(9600);
      SIM900.begin(19200);
      pinMode(led, OUTPUT);
      delay(1000);
    }

    void sendSMS1()
    {
      SIM900.println("AT + CMGS = \"+************\"");
      delay(100);
      Serial.println("Water Detected");
      delay(100);
      SIM900.println("Water Detected");
      delay(100);
      SIM900.println((char)26);
      delay(100);
      SIM900.println();
      delay(100);
    }

    void sendSMS2()
    {
      SIM900.println("AT + CMGS = \"+************\"");
      delay(100);
      Serial.println("Movement Detected");
      delay(100);
      SIM900.println("Movement Detected");
      delay(100);
      SIM900.println((char)26);
      delay(100);
      SIM900.println();
      delay(100);
    }

    void loop()
    {
      int soilSensor = analogRead(A0);
      int tiltSensor = analogRead(A1);

      if(soilSensor >= 10)
      {
        digitalWrite(22, HIGH);
        Serial.println(soilSensor);
        sendSMS1();
        delay(60000);
      }
      else
      {
        digitalWrite(22, LOW);
        delay(60000);
      }

      if (tiltSensor >= 100)
      {
        digitalWrite(led, HIGH);
        Serial.println(tiltSensor);
        sendSMS2();
        delay(60000);
      }
      else
      {
        digitalWrite(led, LOW);
        Serial.println(tiltSensor);
        delay(60000);
      }
    }

title: How to limit the number of message that an Arduino sends to a phone without terminating it

Answers: 1

body:
You use millis() to keep track of time and also prevent blocking. Replicating your program logic:

    long soil_timer = 0;
    long tilt_timer = 0;
    char soil_flag = 1;
    char tilt_flag = 1;

    void loop() {
        int soilSensor = analogRead(A0);
        int tiltSensor = analogRead(A1);

      if (soil_flag == 1) {
        if (soilSensor >= 10) {
          digitalWrite(22, HIGH);
          Serial.println(soilSensor);
          sendSMS1();
        }
       else {
          digitalWrite(22, LOW);
        }
        soil_timer = millis();
        soil_flag = 0;
      }

      if (tilt_flag == 1) {
        if (tiltSensor >= 100) {
           digitalWrite(led, HIGH);
           Serial.println(tiltSensor);
           sendSMS2();
        }
        else {
           digitalWrite(led, LOW);
           Serial.println(tiltSensor);
        }
        tilt_flag = 0;
        tilt_timer = millis();
      }
      if (millis() - soil_timer >= 60000){
         soil_flag = 1;
      }
      if (millis() - tilt_timer >= 60000){
         tilt_flag = 1;
      }
    }