text:
Displaying binary to LEDs
I've written a program for Arduino UNO and 3 LED lights. The program is supposed to turn an inputted number into binary and then display it on the LEDs, on being 1 and off being 0 I have looked it over quite a few times and don't understand why it is not working as it should. I'm a beginner at working with Arduino so I probably just need a more experienced eye to show me where I have messed up. I have a link to a picture of the Arduino setup below. Thanks!
https://drive.google.com/file/d/0B8k_WNZ3eFOkZHkwNUllTEp4WGM/view?usp=sharing
//setting up lights
const int lightOne = 13;
const int lightTwo = 12;
const int lightThree = 11;

//array of the lights for when printing the binary
int lights[] = {lightOne, lightTwo, lightThree};

void setup() {
  //setting pin modes and starting up the serial monitor
  pinMode(lightOne, OUTPUT);
  pinMode(lightTwo, OUTPUT);
  pinMode(lightThree, OUTPUT);
  Serial.begin(9600);
}

//converts a given number into binary
String binary(int number) {
  String r;
  while(number!=0) {
    r = (number % 2 == 0 ? "0" : "1")+r;
    number /= 2;
  }
  return r;
}

//outputs the binary string to the lights (not expecting numbers larger than     9)
void printBinary(String binaryNumber) {
  for (int i = 0; i < sizeof(binaryNumber); i++) {
    digitalWrite(lights[i+11], (binaryNumber[i] == '0' ? LOW : HIGH));
    delay(2000);
  }
}

void loop() {
  int input = Serial.read();                //get the number
  String binaryNumber = binary(input);      //convert number to binary
  Serial.println(binaryNumber);             //print binary to serial monitor
  printBinary(binaryNumber);                //display number in binary on     LEDs

}

Welcome to SE Arduino!
Long Version
You have a couple of things to look at:

Don't use String class it has too much overhead for Arduino.
Your conversion function is not really necessary because you can convert it on your Serial.println() by specifying binary as output. eg: Serial.println(number, BIN);
The Serial.read returns an integer, but that int only contains a byte (unsigned) value anyway (unless there's nothing to be read, in which case it returns -1). Because you're taking a number (not really relevant) and you want it to be a number on the return, just use int or byte (unsigned: 0 <-> 255) or char (signed: -127 <-> +128).
You could/should/doesn't matter if you use Serial.available() or not, it is a matter for yourself, I usually do, but it's non blocking anyway and if there's nothing there to be read, it'll just continue on anyway. Although if you're not going to use it, you should test for that -1 as what you're doing at the moment is taking that and converting it to binary (which is 0xFF which is everything on). This is one of your major problems in the code (the other is in the Short Version section.
You're using "0" and "1" which are ASCII values, and you haven't indicated how you're getting the number. So it may be ASCII (byte) or actually a byte value. ie, "0" is 48 (dec) or 30 (hex). Whereas a 0 is just zero. Funnily enough, because you're using modulo (%) it doesn't really matter because you're only interested in the lowest nibble, which for the sake of your code, doesn't matter what's encoded at the higher end. ie: 1 (0b00000001) is the same as "1" = 49 (dec) = 0x31 = 0b00110001 when used with %2.
Ditch your delay(2000). Delays are evil* :) You could write the values to the pins all day, you're not going to cause any problems, if you want to output less to your serial port (which you should do), you could do timed outputs back to Serial. ie, do your Serial.println() once a second, or record the values into backup/old variables and compare them, and only print the output if the value changes
The big one is in the next section

Short Version
This is your main problem, on this line:
digitalWrite(lights[i+11], (binaryNumber[i] == '0' ? LOW : HIGH));

I think you need:
digitalWrite(lights[i], (binaryNumber[i] == '0' ? LOW : HIGH));

You already have the pin value encoded in the array, you don't want to add 11 to the index, that's going to throw you above your three light values :)
* Delays are evil: It's a matter of opinion, and that's just how I feel, I actually googled it and this is just a random response. But it contains the crux of what I'd say anyway: http://www.makeuseof.com/tag/arduino-delay-function-shouldnt-use/

I was going to rewrite your code, but you've given it a pretty good stab anyway, so take my info above on board and give it another shot. If you have any problems post your new code in an update to the question and we can help you work on it further. If you're under the pump and just want an answer, let us know and I or someone else can give you how we'd do it, but there's nothing better to learning than doing it yourself. It will stick in your head a lot better after giving it another go yourself. You won't make mistakes like that index again (or not in that way, anyway)

Thanks! I actually originally didn't have the index mistake, but when I was looking back over it last night my tired mind though I had made a mistake where there wasn't one and changed it.

It is amazing what the tired mind does sometimes. I find I am often trying to finish "one thing" before calling it a night, and it can have me stumped for hours! At some point, I give up and call it quits. The next morning, refreshed, you take one look at it and see something that you simply can't believe you missed the night before, and in 30 seconds you've fixed the previous 4+ hours of angst. You think to yourself, the next time this happens, I'll just go to bed. But the next time it happens, you spend another night on one problem, that takes another 30 secs to fix the next day, again! lol

I'll definitely do that next time and save myself the trouble lol

You need to check that there are characters available before reading. Please see documentation of Serial.read() (and Serial.available()).
Cheers!


text:
Rotating a motor with L293D
I'm following this tutorial to control a DC motor with an Arduino.
I have the same problem as this stackexchange post arduino.stackexchange.com/questions/10049/problems-with-l293d where the motor is not rotating.

The chip is heading to the right. (5v pins are on the right)
Connecting directly the motor to the battery works.
Current (5V on the bottom & 2*1.5V) is flowing everywhere expected EXCEPT on the yellow & green wires of the motor (the red wire of the battery pack is connected to the second line of the breadboard).
Connecting directly the motor to the battery works.
I copied the code of the above tutorial which is basically : "digitalWrite(4,HIGH);", there is current on the cable.

Am I wrong into thinking that a L293D chip can output sufficient current ? Is the chip malfunctioning ?

Your picture shows a holder for two AA cells, yielding something in the neighbourhood of 3v.  That is far too little for an L293D.  (This isn't really your fault, as it appears you got this erroneous idea from following a bad tutorial, but it does demonstrate that not everything you read on the Internet is sensible.  Using a 9v "transistor" battery is also a bad idea).    3 cells would be about the minimum, but even there it would not work well, as that chip has two bipolar transistors in the path yielding a voltage drop of over a volt.
To use a an L293D you really want at least a 5 or 6 volt system, and a motor wound for low to moderate current at that voltage.
If you want to use a lower voltage, look at a more modern MOS-based H bridge chip - the TB6612FNG is an often used example.  You will however still want to choose motors wound for moderate current at a 3- or 4- cell voltage - those intended for 2-cell usage typically draw more current than is ideal for an IC driver chip.
It is entirely possible that there are additional issues with your attempt as well.  Normally, a question such as this would require a complete and accurate schematic diagram, which you have not provided.

I think you're right even though i've seen demonstration videos using 2 AA batteries and 2 DC motors working fine.
The goal of my project is to use a smaller DC motor than this and a small 3.7v rechargeable battery. So switching to a smarter motor contoler might be a better idea. I'll try the reference you gave me, thanks !

So I used a 4x1.5v battery pack. The L293D chip was faulty, I changed it. Still, the motor is running way slower than directly connected to the batteries. The TB6612FNG chip is not to be used for a small DC motor like this, it is meant for bigger scale projects.

Whoever told you the TB6612FNG is only for larger projects has no idea what they are talking about.  The L293D has a large voltage drop - effectively one of the cells in your battery is only to offset that loss, and part of a second too -  which is why you should not be using it.  In contrast the TB6612FNG and similar MOSFET bridges are much more efficient - a far greater fraction of your battery voltage actually shows up across the motor, and less is wasted as heat.

I ordered the TB6612FNG chip and will soon experiment on it. Thank you for your clear explanations and the reference of the chip.

Make sure you get or have plans to make a carrier PCB - the pins are about twice the density of your breadboard, so it won't be fun to hand-wire to.  It wouldn't make a bad introduction to toner-transfer PCB fabrication though, and it shouldn't be too hard to hand solder to a PCB as long as you approach it carefully: solder one corner, check alignment, solder the opposite, check alignment, and only then solder everything else.  Ultimately it is surface tension and flux which get the solder in the right place.  Have some of the finest size solder braid on hand to fix any accidental bridges.

source: Stack Exchange

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

sort: votes


text:
Linking Arduino Nano with ESP8266 Wifi module
I recently started playing around with Arduinos to connect a few sensors up. I used an Arduino Nano to measure temperature, humidity, air pressure and light level.
To store the data in a database, I used another Arduino that I connected to a Raspberry Pi, and let the two Arduinos talk wirelessly to each other via 433 MHz.
That all works pretty well, but the 433 MHz communication is not exactly the most reliable (I often miss a transmission). When I stumbled upon the ESP8266 module, it seemed like the optimal solution for communication. How cool would it be if I could just pull out the information via an HTTP call from the Raspberry Pi?
After toying around for many hours, uploading many different firmwares, getting more and more frustrated because I could not get it to do anything, I finally have it working through an FTDI module connected up like this:

I use an MB102 power module to provide the 3.3v required by the ESP8266. I turns out you need to connect the ground from the MB102 to the ground of the FTDI module to get any proper response. After doing that I was able to send AT commands and get the proper responses. I could even connect it to my home Wifi.
The next thing I want to do is connect it to the Arduino. I found a very simple schema for that (http://blog.huntgang.com/2015/01/20/arduino-esp8266-tutorial-web-server-monitor-example/), where you connect RX to TX and TX to RX. Using the MB102 I connected it like this:

Apparently I should now be able to upload a blank sketch to the Arduino, and then use the serial monitor again to sens AT command, exactly the same way I did it when using the FTDI module.
The problem is that I get nothing at all this way. I don't even see my own AT commands in the console. I do see the ESP8266 flashing every time I send a command (I even see it it still connected to my router, probably it remembered the info I send through the FTDI...?)
The question is, what am I going wrong? I read some posts about the TX from the Arduino also being 5v and that you need to do something to bring it back to 3.3v, but there are also many tutorials that say it's not required.

The easiest way to work with these devuces is to connect them to a spare pair of Arduino pins and use SoftwareSerial for communicating (unless you're using one of the Arduinos with more than one UART). SoftwareSerial work up to 9600 baud on 16MHz devices, 4800 on 8MHz devices, so you'll need to set the ESP8266 to accommodate that. They currently ship at 115200 baud. You can use the hardware UART on pins (0, 1) but then re-programming the Arduino means disconnecting & reconnecting the ESP temporarily each time, and gets old pretty quickly.
Here's what I do with new ESPs (If you've re-flashed your ESP, you'll need to download the AT instruction-set emulator and re-flash it with that, first):
# To configure a new ESP module:
# Connect the ESP and the FTDI as in your top diagram, set your
# terminal-emulator to 115200 baud, and enter the following:

AT                             # ESP should respond "OK"
AT+RST                         # Resets the ESP
AT+UART_DEF=9600,8,1,0,0       # Sets ESP UART: 9600,N,8,1,no flow ctl

# Now change the terminal emulator baud rate to 9600

AT+CWMODE=1                    # Set ESP to station mode (client)
ATE0                           # Set ESP's echo off
AT+CWLAP                       # List access points - after a short pause
                               # the ESP returns a list of WiFi access points

For future reference, here is a link to the ESP8266 AT Instruction Set.
Update June 2020: The above link was broken, now fixed. You can also find documentation at Espressif's github account (online readable, but not pdf, as of this date).

I just realized this question has been dredged up from the archive of unanswered questions from 6 months ago. Oh, well - maybe this answer will help someone else now or soon.

There might be an issue with the baudrate from the Nano FTDI chip to the RX/TX and the ESP8266. Did you disconnect when uploading the sketch?
How about trying this instead?
Cheers!

When I work with the ESP8266, it works om 115200 baud, everything else just gives garbage. I've tried the code from the linked blog (only changing the baud rate) , I see it's sending command to the ESP8266 (blue light flashing), but it fails when it tries to execute the Serial.find(">") command. I also see nou output from the ESP8266 whatsoever. I did disconnect the ESP8266 while uploading.

Stumbled on good tutorial here, tried and it does the job:
https://blogs.msdn.microsoft.com/abhinaba/2016/01/23/esp8266-wifi-with-arduino-uno-and-nano/

That will work except for the CIOBAUD command which has been replaced. The current command for all UART functions is: AT+UART_DEF=<baud>,<databits>,<stopbits>,<parity>,<flowcontrol>, or AT+UART_DEF-9600,8,1,0,0 to be compatible with SoftwareSerial. Replace "_DEF" with "_CUR" if this change is only for the session; the first command makes it the power-on default.

Please can you expand on the information from that blog into this answer if the link dies, but also to make it a better answer

Yes, if you are using different power sources the grounds always have to be connected, otherwise the boards don't know what zero volts is.
The TX of the Arduino is 5v, you need a level shifter to convert 5v to 3.3v, something like this (https://shop.pimoroni.com/products/adafruit-4-channel-i2c-safe-bi-directional-logic-level-converter?utm_medium=cpc&utm_source=googlepla&variant=302017581&gclid=CPqujsPxlc0CFcYcGwodb8YIoA)
The TX of the ESP8266 is 3.3v and the RX of the Arduino is 5V and you will need a level shifter to handle this.  You can use the same one as listed above, because it can convert 4 high (5v) signals into 4 low (3.3v) signals.
People say you can so it with resistors, but I have also read that they don't perform well enough to handle fast switching digital signals (so 300 Baud on your serial might be OK, but not 115000 :) )
People also say you don't need level convertors.  That's true things might work for a while without them, but sooner or later something will go pop.  Increasing the voltage will speed up the process so you can imagine what will happen if you connected a 230v supply directly to a USB device.
One final point, do you know the ESP8266 is a 80/160MHz processor with 256KB of RAM, when you compare that to you Arduino its like programming you PC via your phone.  What you could try is connecting the ESP8266 via a FTDI module and program it via the Arduino IDE in Arduino C.  Its a lot easier than all this connection stuff.

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

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


text:
How to learn electronics/programming with Arduino?
I want to learn core and mechanics of microcontrollers with Arduino, and I don't really know where to find good source of knowledge.
Every Arduino related tutorial is about very basic stuff like connecting the LCD display without explaining what every pin does. When it comes to programming tutorials only explain what functions are needed and do not explain what happens inside the hardware.
For example i know what delay() function does, and I know that I can find definition in the source files:
void delay(unsigned long ms)
{
    uint16_t start = (uint16_t)micros();

    while (ms > 0) {
        yield();
        if (((uint16_t)micros() - start) >= 1000) {
            ms--;
            start += 1000;
        }
    }
}

But what I really want to know what that code does, and how to write own functions. I would appreciate if you could provide me with any starting point. Should I just follow the source files until I get it or is there any better reference?
I have Arduino Leonardo, and experience in programming in C/C++.

For information about the “core and mechanics of microcontrollers with Arduino”, there are numerous articles with lots of details on the arduino.cc forum.  However, most of the code posted there sucks, as does most of the code posted here on Arduino Stackexchange.  That's a natural consequence of people posting code that doesn't work and they wonder why.
For a reasonably organized and accurate body of information about Arduino hardware and software, see Nick Gammon's Arduino pages.  Also see arduino.land pages.  For better understanding of Arduino software internals, see garretlab's “Internal Structure of Arduino Software” pages, which are well organized and quite informative about the subjects they cover.
Regarding the specific delay() code shown in the question, first consider this slightly simpler version, from Arduino 1.6.3:
void delay(unsigned long ms) {
    uint16_t start = (uint16_t)micros();
    while (ms > 0) {
        if (((uint16_t)micros() - start) >= 1000) {
            ms--;
            start += 1000;
        }
    }
}

Ignoring data type constraints, it's evident that the while loop counts down ms from its original value to zero.  The burden of the if executes about once per millisecond, because start advances 1000 microseconds each time within the if.
The casts of micros() – ie, where uint16_t appears in parentheses before micros() – tell the compiler to throw away the upper two bytes of micros() [which is actually an unsigned long, or uint32_t] and treat it as an unsigned 16-bit integer.  The low two bytes of micros() overflow every 65536 microseconds, on which occasions within a millisecond it will come to pass that although (uint16_t)micros() is less than start, due to use of unsigned arithmetic ((uint16_t)micros() - start) >= 1000.
The code you included has one more statement in the while loop:
    yield();

For most models of Arduino, yield() is an empty function, a do-nothing if compiled at all.  On the Due, with Scheduler.h in use to support cooperative (non-preemptive) multitasking using multiple stacks, yield() gives the scheduler an opportunity to schedule another task, if one is ready to run.  Note that if a  “cooperative” but malignant task always takes just under 65536 microseconds to do its work, it can happen that delay() as shown never returns.

There are two main topics there: Digital Electronics, and C++ programming, and the Arduino happens to bridge the gap between the two.
That's why it's hard to find tutorials in the style you want.  So instead of looking for Arduino tutorials that do what you want you need to split the topics apart and deal with them separately.
Search for C++ programming tutorials. That should help you understand the structure and syntax of a program better. Search for digital electronics tutorials. Good keywords are things like logic gates, combinational logic or digital interfacing and just digital electronics. That should help you understand things like logic levels, logical functions, inputs and outputs, and such like.
Once you have basic understanding in both fields you can begin to see how the two relate together. One of the most important skills any engineer has is understanding and interpreting datasheets. From datasheets you can find how the hardware operates and what you would need your program to do to make the hardware do what you want.


text:
nRF24L01 Problem
I'm trying to code a simple transmitter - Receiver program with nRF24L01
Very simple code. Compiles. But when I try to test it using serial monitor. But only the first character is printed on the screen just once.
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>

#define CE_PIN 9
#define CSN_PIN 10

const uint64_t pipe = 0xE8E8F0F0E1LL;

RF24 radio(CE_PIN, CSN_PIN);

int smth[1];  // the transmitter data
int x=0;  // the copy of the receiver data
char rec[1]; //the receiver data

int ledPin = 3; // choose the pin for the LED
int inPin = 7;   // choose the input pin (for a pushbutton)
int val = 0;     // variable for reading the pin status

void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);  // declare LED as output
  pinMode(inPin, INPUT);    // declare pushbutton as input

  radio.begin();
  radio.openWritingPipe(pipe);  //originally transmitter
}

void loop(){
  val = digitalRead(inPin);  // read input value
  if (val==HIGH) {         // check if the input is HIGH (button released)
    digitalWrite(ledPin, HIGH);  // turn LED OFF
    Serial.println('1');
    smth[0] = '1';
    radio.write(smth, sizeof(smth));
  } else {
    digitalWrite(ledPin, LOW);  // turn LED ON
    Serial.println('0');
    smth[0] = '0';
    radio.write(smth, sizeof(smth));
  }
}

Serial Monitor :
0

Instead of printing a zeros for infinite time till I change the mode of the switch, even though if I change the mode of the switch from low to high, nothing is printed on the screen.
I'm using Library for instance http://playground.arduino.cc/InterfacingWithHardware/Nrf24L01
Any help?

What library are you using?

Try changing int smth[1]; to byte smth[1];.

Solder capacitors to the power pins of the NRF24L01. 100uF would do.

I ran your code on my arduino pro mini / nRF24L01 with the "RF24 by TMRh20" library and got a continuous stream of zeros out on my monitor.

A quick look at the library header files shows you should call radio.stopListening() before calling radio.write() for the module to switch to transmit mode. This could be what is blocking the radio.write in the else block. I also recommend you try a byte array first, to get things working, just in case ints are the issue.

Completing TisteAndii reply I suggest to have a look at init. According to the RF24 classe list, it seems radio.begin(); and radio.openWritingPipe(pipe); are "void" function.
I personnaly use NRFLite from Dave Parson and his lib send a return value for his _radio.init function.
That's interesting because a lot of lib have a "send feature" which don't return until the receiver replied. So if you turn on your nRF and send data while the receiver is OFF, you're blocked. With a test at init, you can check that and loop until the receiver is available.
Note: I let my answer, but that's not the good one. As indicate in the coment, the init function dont tell if the receiver is avaible, but only if the nRF is connected (your nRF, so not the other one).

There's a bit of a point to not doing things blindly, yes.  But you have mis-stated it.  What Dave Parson's function returns has nothing to do with the status of the other end, rather it merely indicates success in communicating with the local chip by reading back the configuration - it does not indicate anything about the remote end being powered or not as you seem to believe.  With the normal RF24 you can easily read status to check wiring, also it does not block eternally but only for a given number of retires and only in the mode where it expects acknowledgement.

Agree! I suppose it depend on the LIB? In other cases, if you have a way to send and check the result, please tell as there is a lot of question about that and it seems the results are never as expected.


text:
ATTINYx5 usi for uart?
Can the ATTINYx5 use its universal serial interface for a better UART than the Sofware Serial library alone? If so, is there a library or tutorial for this?

An answer got deleted. Spooky. (it was about the hardware Serial lib)

Here is a receive only USI UART for the ATtinyX5 and ATtinyX4.

AVR307 describes implementation of a half duplex UART implementation using the USI. Note that full duplex is not possible due to the synchronous design of the USI.

That implementation uses ISR(TIMER0_OVF) to clock bits in and out. This is not needed on the ATtinyX5, since you will clock the USI from TIM0_COMPA and set timer0 to CTC mode instead of periodically reloading the seed.


text:
Looking for an existing lightweight RF protocol
I'm currently looking for an RF protocol that doesn't use much power (generally much less than wifi) Something similar to simple AM radio, but with an authentication library readily available. ZigBee has about 250kbps bandwidth. I don't need nearly as much, so something with ~5kbps (dial-up speeds) would be acceptable. Using the Arduino Yun; so i'm constrained to the 5V output.
I'm also trying to stay away from the 2.4 GHz band.
Is there anything out there with this in mind? I was thinking maybe Z-Wave?
As far as the ZWave chips go this is where i'm at: http://pastebin.com/B0Yif3LS

Have a look at http://www.anarduino.com/miniwireless/ or http://lowpowerlab.com/blog/category/moteino/ or even http://jeelabs.org/.


text:
ESP8266 Returns 'invalid' - Cause 4
I have tried to get the Ai-Thinker ESP8266 working at all. If you hook it up to an Uno you have garbage returned no matter what the baud rate is. Tried softwareSerial on D3 and D4 (switching pins doesn't help) and over D0 and D1 with no sketch (to send AT commands directly to the device because softwareSerial wasn't working).
I'm using a logic converter from 5v to 3.3v to handle the voltage correctly.
I also know for a fact you can do that. I've done it a bunch with Bluetooth. HC-05.
NOTE: Pins in the wrong order won't return anything, in order to get garbage it needs to be wired correctly.
I also have a FTDI module that functions as another passthrough unit for this. It has a jumper for 3.3v to 5v and will stay on 3.3v as these units are unable to handle 5v.
I used PuTTY in order to view the boot information of this chip. On boot it returns this information.
So here's my issue.
ets Jan  8 2013,rst cause:4, boot mode:(3,7)

wdt reset
load 0x40100000, len 816, room 16
tail 0
chksum 0x8d
load 0x3ffe8000, len 788, room 8
tail 12
chksum 0xcf
ho 0 tail 12 room 4
load 0x3ffe8314, len 288, room 12
tail 4
chksum 0xcf
csum 0xcf

2nd boot version : 1.2
  SPI Speed      : 40MHz
  SPI Mode       : QIO
  SPI Flash Size : 4Mbit
jump to run user1

sd▒C▒
Ai-Thinker Technology Co. Ltd.

invalid

At the end of the day this invalid line means that the wifi information (from what I understand) is corrupted. It also refreshes this information over and over and WILL NOT accept AT commands so I can't seem to chase it down.
I am afraid that by attempting to update it if this kind of issue happens it will be bricked.
Both of these modules are opened today and I have tested another 8266 with similar results.
Any help would be appreciated.

Try SoftwareSerial on other pins. D0 and D1 is not a very good idea. These are the HardwareSerial pins. What sketch are you using? And how do you wire the ESP8266? 3V3 power supply?

In order. I used it to be a conduit to get to the chip directly so you don't have to use arduino code. Yes I know how bad it can be for live. I was using software serial to prototype the pins for when it worked. D3 and D4 with everything through a logic 5v to 3.3v converter. No sketch currently. I'm also using A FTDI usb to attempt to access it directly as stated in the original. I'm going to append this information.

I have seen cause: 4 related to power issues on mine.  Try giving it external power >500mA, that can be a power hungry little chip.

I'll give it a shot

Alright so I figured it out. Thanks to user Butters for pointing me in the right direction.
The Arduino Uno DOES NOT have enough power to handle the ESP8266 itself. It needs a power source using a 5v to 3v stepdown chip. The 3v3 rail doesn't handle it by itself.

I don't know what this "invalid" means I am getting this on every boot but my device is working fine. I have tested downloading webpages and it's working. So maybe just ignore this. use cutecom it works there, didn't work in minicom maybe because of carriage return absent.

Invalid means your config is uninitialized or invalid


text:
How to prevent inclusion of unnecessary libraries?
How do you save space by preventing the inclusion of unnecessary binaries?
When I compiled the ROS Blink example, I received the warning:
Global variables use 1,951 bytes (76%) of dynamic memory,
leaving 609 bytes for local variables. Maxiumum is 2,560 bytes.
Low memory available, stability problems may occur.

Considering the example uses almost no libraries, I was surprised by this, but sure enough, the compiler pulls in a ton of libraries that are never used:
Scanning dependencies of src
Scanning dependencies of arduino
Scanning dependencies of ros_lib
src/main.cpp
arduino/wiring.c
arduino/wiring_shift.c
arduino/wiring_digital.c
arduino/wiring_pulse.c
arduino/WInterrupts.c
arduino/hooks.c
arduino/wiring_analog.c
arduino/USBCore.cpp
arduino/new.cpp
arduino/Tone.cpp
arduino/WString.cpp
arduino/HardwareSerial1.cpp
arduino/Stream.cpp
arduino/HardwareSerial3.cpp
arduino/HardwareSerial0.cpp
arduino/CDC.cpp
arduino/HardwareSerial2.cpp
arduino/main.cpp
arduino/HID.cpp
arduino/HardwareSerial.cpp
arduino/IPAddress.cpp
arduino/Print.cpp
arduino/WMath.cpp
arduino/abi.cpp
Linking libarduino.a
ros_lib/duration.cpp
ros_lib/time.cpp
Linking libros_lib.a
Linking firmware.elf
Converting to firmware.hex

Why are so many files being included in the compilation, and how do I filter them out?

It's 2015. What is compiled does not always become what is linked.

The Arduino IDE build script will actually copy all core source code file to the tmp directory, compile and generate an archive file. The sketch is compiled and linked with this library. Only the referenced (used) functions and data are linked in the binary.
The size (both program and data) of this blink is somewhat larger than the "standard" blink example but this is due to the publisher-subscriber run-time.
Cheers!
PS: If you google you can find commands to listing what is actually in the generated binary. Here is a starting point.

Part of the compilation process is what is known as garbage collection, which is controlled by the compilation flag -Wl,--gc-sections
This process goes through the compiled program and works out which sections (functions, blocks of read-only data, etc, each in its own section controlled by -ffunction-sections and -fdata-sections IIRC) and works out which are not needed in your compiled program.  It then deletes them.
The problem you have though is not with code or read-only data size, but with static RAM allocation size.  This is global variables and local static variables - things used for stiring data, maybe as serial buffers, etc.  Most of that is probably part of the underlying RTOS that you have elected to use. Which is the problem of using an RTOS to just blink an LED. It could be seen as a task that is beneath the RTOS and is complete overkill. Of course, since you're just testing, that is pretty irrelevant, however, as you add more functionality you will most likely find that the memory footprint doesn't increase much since it's the "background" stuff that of the RTOS that will always be there regardless of what tasks you are performing.


text:
Problem in RS485 Communication between Arduino and PC
I'm trying to sending and receiving data via RS485 communication. Interfacing Arduino and PC(laptop)
using SN75176 RS485. I wrote a program to send a string "Hello" from arduino via Tx pin. My intention is to receive
the "Hello" string in my PC's hyperterminal. After uploading the program im receiving junk data. The baud rate i've mentioned in
my program and i gave in hyperterminal are same. I've checked the wire connection, it is ok. Then, what is the problem?
Code:
#include <SoftwareSerial.h>
int Txpin = 1;
int ditpin = 5;  //for 1st rs485
int ditpin1 = 2; //for 2nd rs485
void setup()
  {
          // put your setup code here, to run once:
    Serial.begin(9600);
    pinMode(Txpin,OUTPUT);
    digitalWrite(ditpin, HIGH); //For transmit data from arduino
    digitalWrite(ditpin1, LOW); //For receive data to hyperterminal
  }

void loop()
  {
    Serial.println("Hello\r\n");
    delay(1000);
  }

Wire connection:

No ground on the PC side?

Thanks for the reply...No. I didnt connect. Will it be the problem?

Instead i short both rs485 GND.

The control pin, VCC and ground is not correctly wired on the PC side. Google how to connect RS485. Too many issues with this wiring. Please see this reference. http://www.gammon.com.au/forum/?id=11428

Hi @MikaelPatel. Thanks for the post. Actually i'm not connecting two arduinos, connecting one arduino to PC using RS232 converter. As you said i connected the rs232 converter's(5th pin) GND to RS485's GND, but i'm giving power supply 5v it from arduino board on PC side since my rs232 converter doesnt have power supply pins.

Please start by fixing the ground connection to the PC. There are other issues but start with that.

Hi @MikaelPatel. I did that ground connection correctly. Still can't receive the data.

Did you forget the 120 ohm resistors?

Is 120 ohm will be the problem? I read that "to use resistor for long distance". Is it should place? Thanks..

I think I understand what you are trying to do. You do know that the signal (R) is not RS232 levels? It is 5V. I think you are looking for a TTL to RS232 converter and not RS485. Something like http://pdfserv.maximintegrated.com/en/ds/MAX3222-MAX3241.pdf. Or http://www.ebay.com/itm/MAX3232-RS232-Serial-Port-To-TTL-Converter-Module-Male-DB9-COM-Serial-MAX232/221545502349?_trksid=p2047675.c100005.m1851&_trkparms=aid%3D222007%26algo%3DSIC.MBE%26ao%3D1%26asc%3D34875%26meid%3D8f4caa5def98499c9502dd70b3505a35%26pid%3D100005%26rk%3D1%26rkt%3D6%26sd%3D221022603873

Hi @MikaelPatel. what about using 5v to 3.3v voltage divider circuit? Will it work link

You cannot connect from Arduino serial input/output with RS485 circuit and then to the PC RS232 port. You need a TTL to RS232 adapter. For instance an adapter based on MAX3222.

Cheers!


text:
Convert Long to binary - least signifant bit first
I have found an Arduino function which converts a 2-bytes-long-value to a binary value.
e.g. I call sendCommand(0x05) And it gives me an output:
00000101
void sendCommand(unsigned long command){
  for (unsigned long  mask = 1UL << (7);  mask;  mask >>= 1) {

    if (command & mask) {

    Serial.print( "1" );
    } else {

    Serial.print( "0" );
    }
  }
}

my Problem is, that I want to have the Least significant bit first. How do I have to adjust this function to achieve this?
e.g.
sendCommand(0x05)
shall give an output:
10100000

void sendCommand(unsigned long command){
  for (unsigned long  mask = 1UL; mask<256UL;  mask <<= 1) {

    if (command & mask) {

    Serial.print( "1" );
    } else {

    Serial.print( "0" );
    }
  }
}

PS a long is actually 4 bytes long. But your code only uses 1 byte of it.


text:
powering RF on GPIO
I have been running a simple RF link between 2 arduini uno recently and everything went faily well. I am now trying a new project with an arduino mini pro (5V/16MHz) and the seeeduino RF link (@315MHz), and I see very odd results : when the transmitter is on USB cable, the link runs ok, but when on a 9V battery (as raw voltage input), I get very very limiter range (a few inches).
Because the setup works on USB, I'm assuming that the current limitation on the GPIO that powers the RF transmitter is not the issue here. It therefore has to be the battery itself or the regulator.
Somehow I need to use a GPIO to shut down the radio during power saving phases. My current design is very basic, I should probably add a transistor to enable power on the RF. I was also thinking maybe the RD oscilliator needs to settle down a bit, I may need to add some delays before starting to send data. I can see on the oscilloscope that the data and power PINs seem to behave correctly, although I have noticed a voltage drop on the power pin which is similar in pattern to the data transmitted (but again this is no issue unless using the 9V battery).

9V batteries can't provide that much current. You should measure the current consumption of the RF module. You could try adding a electrolytic capacitor, parallel to the battery. You could also power the RF module directly from 9v, to increase the range (higher voltage; better range). But I'd just use a battery pack, instead of a 9v battery.

You should never power anything from an GPIO pin except incredibly low powered things (<20mA), and an RF transmitter certainly does not fit into that category. Google "High Side Switch MOSFET" for a circuit that can help you

Thanks all, I appreciate that I need to use a power switch in a proper design, maybe then I can use the 9V directly. I'll be looking out for these high side switch.

As established in the comments, the issues here are powering the module directly from a GPIO pin, which are limited to 20 mA, and potentially the limited current of a 9V battery.
Personally I avoid using 9V batteries in projects, as they are comparatively expensive for the lifetime they provide. There are various boost/step-up converters that make a steady 5V supply from two AA batteries.


text:
Is it possible to create a standalone exe which can burn the code into a Teensy 3.1?
So here's the scenario.
I have sent my teensy 3.1 circuit to a client of mine
And now I need to update the code burned onto teensy without providing client access to the code
So is it possible to create an exe or an installer of a kind which on execution simply upload the new code onto the teensy?
Since the code is finally a hex file uploaded onto the controller I hope this must be possible
But on doing a quick google search i was not able to find any valid resource which would guide me how to go about it.

Yes, but note that while you can avoid distributing your source code, it will be hard to prevent the recipient from loading the hex file into multiple boards.

Yes, it is perfectly possible.
You will need three things:

The HEX file you want to program
The programming utility for your chosen board (would be in the IDE folder somewhere - not sure what Teensy uses off hand)
A text editor.

Then, using the text editor, you create a .BAT file which executes the programming utility with the right parameters to program the board.
It can help to do an upload in the IDE in verbose mode so you can see exactly what command and parameters are being executed.

Yes.  Teensy has a command line loader available at https://www.pjrc.com/teensy/loader_cli.html or https://github.com/PaulStoffregen/teensy_loader_cli
Given the hex file, the teensy_cli client could upload it without giving your client the source code.  For non-teensy devices, avrdude could be used similarly.
Alternately, one could fork the cli code, modify it to use an embedded copy of your hex file data in a hard-coded or encrypted constant, and then deliver that modified single-purpose executable file to your client.

So here it has been mentioned in 'Required command line parameters' that valid options for Teensy 3.2, Teensy 3.1 and Teensy LC are only applicable for mac and linux. Does that mean I cannot make this loader on windows?

Also here the hex files   for blink slow for Teensy 3.2, Teensy 3.1 and Teensy LC have been provided only for Linux operating system. Does that imply it is not possible on windows at all?

The hex files should be specific to the teensy/AVR hardware, not the host system.    As for the cli program not being able to work on Windows, I'm sorry I missed that--Mikael Patel's answer of the windows GUI solution might be best.

The simplest solution is to ask you client to install the TeensyLoader application. https://www.pjrc.com/teensy/loader.html
Send the new HEX file to the client. The client should then connect the board to the computer. Run the TeensyLoader and upload the HEX file. The TeensyLoader will recognize the board when the reset button is pushed. The HEX file will need to be located on disk (after download or mail attachment).
Cheers!


text:
Arduino IDE Based Data Logger - Stops Running
I have created a data logger that writes to a MicroSD on a user defined interval.  The data logger also has the ability to use an xBee unit to transmit the data received to a base station.
This is a link to the code and pictures of the data logger.
I use Arduino IDE for prototyping and coding.  After compiling the code, I use the temp HEX file and upload it to the boards using AVR Studio 4.
The problem I am experiencing is the data loggers will stop running after a random number of recordings.  This can be days or weeks of running before the problem is experienced. This issue rarely occurs when the logger is running in local mode, but occurs often when running with an XBee unit.
A temporary fix I have found for the problem is to add delay(10); before and after the SD card writes.  I do not know why this fixes the problem and would like to find a more appropriate solution.

Do you have any info on the memory foot-print (data, program, etc)? You are using String and that may end up with heap fragmentation.

This use of String is dangerous.  You are growing and shrinking the String in a loop and hoping the memory manager prevents any holes from forming:
void clockResetcheck() {

  char clkset[] = "CLKSET.TXT";
  if  (myFile.open(clkset, O_READ)) {

    uint16_t newYr;
    uint8_t  newDay;
    uint8_t  newMo;
    uint8_t  newHr;
    uint8_t  newMin;
    uint8_t  newSec;
    char data;
    String temp;
    int place = 0;

    while ((data = myFile.read()) > 0) {

    if (data == '/' || data == ':' || data == ',') {
      if (place == 0) {
        newDay = temp.toInt();
        temp = "";
      }
      if (place == 1) {
      newMo = temp.toInt();
      temp = "";
      }
      if (place == 2) {
        newYr = temp.toInt();
        temp = "";
      }
      if (place == 3) {
        newHr = temp.toInt();
        temp = "";
      }
      if (place == 4) {
        newMin = temp.toInt();
        temp = "";
      }
      if (place == 5) {
        newSec = temp.toInt();
        temp = "";
      }
      place++;
      if (place == 6) {
        myFile.close();
        break;
      }
    }
    else {
      temp = temp + data;
    }
  }
...

The line
temp = temp + data

is a danger flag.  This sort of concatenation is going to reallocate the buffer used by String to make it fit the result.  The reallocate will leave behind a hole with the previous smaller string.
String has logic to reuse the buffer if possible.  So if you start big, it should not have to reallocate.  Something like:
String temp("12345678");  // allocates the buffer at largest needed size
temp = ""; // clear out

That is a less likely to fragment memory.  You have a few other concatenates in code that are similar danger.
The best advice to long running programs I ever received:

Stay off the heap.

You are using String inside functions.  That means that buffers are allocated and freed again and again.
A better pattern is to remove all the local String's in functions.  Instead use one global String as a temp buffer.
String g_temp("                        ");
void function1() {
   g_temp = "";
   g_temp += char
}
void functionB() {
   g_temp = "";
   // do stuff with g_temp
}

With this pattern, the allocate happens once when the program starts.  If the size is setup large enough, if will never need to reallocate.  This means your high water mark for memory use is established at the time the program starts.  You don't have to monitor for a week to see if some corner case will run out of memory.


text:
Set an arduino software clock
Me and my friend are having some trouble setting up an software clock to our arduino uno.
It's for a school project and we´ve never done any programming before. thanks!

We try to. Just having some trouble setting the time for our project. We´re stuck and could really use some help.

Did you see my answer?

Thanks! But we're having trouble with the compilation. It says that there´s no such file or directory #include <Time.h>. Do you know what to do?

However, I will answer. Copy this line : #include <Time.h> and put it outside setup and loop i.e. at the top.

Please post any code that you have done so far. Is the project just a software clock or is there more? What is the project goal?

There is a Time library which you can import.
Here are things that I found on the Arduino website.
hour();            // The hour now  (0-23)
minute();          // The minute now (0-59)
second();          // The second now (0-59)
day();             // The day now (1-31)
weekday();         // Day of the week, Sunday is day 1
month();           // The month now (1-12)
year();            // The full four digit year: (2009,
                //  2010 etc)
setTime(t);              // Set the system time to the
                      //  give time t
setTime(hr,min,sec,day,month,yr); // Another way to set
                               //  the time
adjustTime(adjustment); // Adjust system time by adding
                     //  the adjustment value

timeStatus();   // Indicates if time has been set and
             //  recently synchronized
             //  returns one of the following
             //  enumerations:
* timeNotSet    // The time has never been set,
             //  the clock started at Jan 1 1970
* timeNeedsSync // The time had been set but a sync
             //  attempt did not succeed
* timeSet       // The time is set and is synced
             //  Time and Date values are not valid if
             //  the status is timeNotSet. Otherwise
             //  values can be used but the returned
             //  time may have drifted if the status is
             //  timeNeedsSync.

setSyncProvider(getTimeFunction);// Set the external time
                              //  provider
setSyncInterval(interval);    // Set the number of
                           //  seconds between re-sync

And obviously,
#include<Time.h>

Tell me in the comments if you need more help.

sorry! We´re trying to use the code

@Johanna It is still forbidden. I suggest you delete it, or else a moderator will get here first and may flag your answer.


text:
Converting ASCII value to String
I have this code.
String incoming;   // for incoming serial data

void setup() {
    Serial.begin(9600);  // opens serial port, sets data rate to 9600 bps
}

void loop() {

    // send data only when you receive data:
    if (Serial.available() > 0) {
            // read the incoming byte:
            incoming = Serial.read();
            String mysrr = String(incoming);
            // say what you got:
            Serial.print("I received: ");
            Serial.println(mysrr);
    }
}

A few of you will recognise this as an Arduino example.
However, when I run it ( I sent it the message "hi"), I get this in the serial:
I received: 104
I received: 105

Why is this happening?

Serial.read() returns an int not a String. https://www.arduino.cc/en/Serial/Read
Use an int for incoming (as the example). Or even better use a char and skip all the strings.
Cheers!


text:
Light leds on this board one at a time
I am playing around with this Tinycircuits 16 LED board and I can figure out how to persistently light two LEDs at the same time. The page comes with an example that i can modify but I can only do 1 at a time
How do I light more than one LED at a time?
/*
TinyDuino Edge LED Demo

April 9 2014, by Ben Rose

This example code is in the public domain.

http://www.tiny-circuits.com

*/

void setup()
{
  LedOn(0);//Pass a zero to turn all LEDs off
}

void loop()
{
  for(int i=1;i<16;i++){
    LedOn(i);
    delay(20);
  };
  for(int i=16;i>1;i--){
    LedOn(i);
    delay(20);
  };
}

void LedOn(int ledNum)
{
  for(int i=5;i<10;i++){
    pinMode(i, INPUT);
    digitalWrite(i, LOW);
  };
  if(ledNum<1 || ledNum>16) return;
  char highpin[16]={5,6,5,7,6,7,6,8,5,8,8,7,9,7,9,8};
  char lowpin[16]= {6,5,7,5,7,6,8,6,8,5,7,8,7,9,8,9};
  ledNum--;
  digitalWrite(highpin[ledNum],HIGH);
  digitalWrite(lowpin[ledNum],LOW);
  pinMode(highpin[ledNum],OUTPUT);
  pinMode(lowpin[ledNum],OUTPUT);
}

What is your question?

Sorry I copied over the question with the paste of the code.

Oh, okay. I get it. I'll undo the downvote.

This is your circuit.
I think you can take it from here by looking at the diagram, but please note that e.g. 1 0 0 0 0 will light up 3 and 1, so be careful.
To show more than one, turn on multiple LEDs in rapid succession. It will give the effect that more than one are on. This is known as multiplexing.
Update:
After Googling around, I understood it better. I also wrote this code.
int IO1 = 50;
int IO2 = 48;
int IO3 = 46;
int IO4 = 44;
int IO5 = 41;
int del = 1000;

void setup() {

  pinMode(IO1, INPUT);
  pinMode(IO2, INPUT);
  pinMode(IO3, INPUT);
  pinMode(IO4, INPUT);
  pinMode(IO5, INPUT);
  Serial.begin(9600);
}

// the loop routine runs over and over again forever:
void loop() {
    displayLED(1);
    delay(del);
    displayLED(2);
    delay(del);
    displayLED(3);
    delay(del);
    displayLED(4);
    delay(del);
    displayLED(5);
    delay(del);
    displayLED(6);
    delay(del);
    displayLED(7);
    delay(del);
    displayLED(8);
    delay(del);
    displayLED(9);
    delay(del);
    displayLED(10);
    delay(del);
    displayLED(11);
    delay(del);
    displayLED(12);
    delay(del);
    displayLED(13);
    delay(del);
    displayLED(14);
    delay(del);
    displayLED(15);
    delay(del);
    displayLED(16);
    delay(del);// light up LEDS 1, 2 and 3.
}

void displayLED(int a){
    clear();
    if (a == 1){o(1); o(2); h(1); l(2); Serial.println('1');}
    if (a == 2){o(1); o(2); l(1); h(2); Serial.println('2');}
    if (a == 3){o(1); o(3); h(1); l(3); Serial.println('3');}
    if (a == 4){o(1); o(3); l(1); h(3); Serial.println('4');}
    if (a == 5){o(2); o(3); h(2); l(3); Serial.println('5');}
    if (a == 6){o(2); o(3); l(2); h(3); Serial.println('6');}
    if (a == 7){o(2); o(4); h(2); l(4); Serial.println('7');}
    if (a == 8){o(2); o(4); l(2); h(4); Serial.println('8');}
    if (a == 9){o(1); o(4); h(1); l(4); Serial.println('9');}
    if (a == 10){o(1); o(4); l(1); h(4); Serial.println(10);}
    if (a == 11){o(3); o(4); l(3); h(4); Serial.println(11);}
    if (a == 12){o(3); o(4); h(3); l(4); Serial.println(a);}
    if (a == 13){o(3); o(5); l(3); h(5); Serial.println(a);}
    if (a == 14){o(3); o(5); h(3); l(5); Serial.println(a);}
    if (a == 15){o(4); o(5); l(4); h(5); Serial.println(a);}
    if (a == 16){o(4); o(5); h(4); l(5); Serial.println(a);}

}

void clear(){pinMode(IO1, INPUT);
  pinMode(IO2, INPUT);
  pinMode(IO3, INPUT);
  pinMode(IO4, INPUT);
  pinMode(IO5, INPUT);}

void o(int o){
    if (o == 1){pinMode(IO1, OUTPUT);}
    if (o == 2){pinMode(IO2, OUTPUT);}
    if (o == 3){pinMode(IO3, OUTPUT);}
    if (o == 4){pinMode(IO4, OUTPUT);}
    if (o == 5){pinMode(IO5, OUTPUT);}
}

void h(int l){
    if (l == 1){digitalWrite(IO1, HIGH);}
    if (l == 2){digitalWrite(IO2, HIGH);}
    if (l == 3){digitalWrite(IO3, HIGH);}
    if (l == 4){digitalWrite(IO4, HIGH);}
    if (l == 5){digitalWrite(IO5, HIGH);}
}

void l(int h){
    if (h == 1){digitalWrite(IO1, LOW);}
    if (h == 2){digitalWrite(IO2, LOW);}
    if (h == 3){digitalWrite(IO3, LOW);}
    if (h == 4){digitalWrite(IO4, LOW);}
    if (h == 5){digitalWrite(IO5, LOW);}
}

I probably couldn't take it any further without an example of code.

@Crash893 Okay, I'll edit.

@Crash893 Did the code work?

i left the device at work ill try when i get back after vacation

That is an interesting challenge. You should include the circuit diagram for this. It really helps understand the code.
.
There is excellent information on this technique to reduce number of pins here.
Cheers!


text:
TCP or HTTP connection between web server and arduino
If arduino works as a client and tries to connect to web server (the server is mine), should I connect to it via TCP or HTTP connection? Data will be simple strings (20 chars at max) so TCP connection should probably be enough?
The connection has to work in both ways - web server sending data to arduino and arduino sending data back to server.

It's time you learned the OSI 7 layer model: PDNTSPA.
HTTP is a Presentation (protocol) that runs over a TCP Session.  If you are interacting with a web server then you will be opening a TCP socket and sending HTTP requests.
There is no other way of talking to a web server. It only speaks HTTP, and you can only connect to it through TCP.

Oh god this is awkward, thank you. Somehow I thought HTTP/TCP are different things in my case.


text:
Arduino / BitVoicer Sending IR code on loop
I was designing a voice automated kitchen lighting system. I have led strips under the cabinets which are remote controlled by an IR remote, so I captured the IR codes and got an IR led to turn them on. Now I introduced BitVoicer so that I could use voice commands to control the LED. I have ran into the issue that the IR led keeps turning the lights on and off, but my IR codes worked prior to using BitVoicer.
Here is my arduino code:
#include <BitVoicer11.h>

int IRledPin = 13;

BitVoicerSerial bvSerial = BitVoicerSerial();

void setup()
{
 Serial.begin(9600);
 pinMode(IRledPin, OUTPUT);
}

void loop()
{
  bvSerial.getData();

  if(bvSerial.strData == "")
  {
    return;
  }

  if(bvSerial.strData == "wake")
  {
   LightOnCode();
  }
}

  void pulseIR(long microsecs)
   {
     cli();

     while (microsecs > 0)
      {
        digitalWrite(IRledPin, HIGH);
        delayMicroseconds(10);
        digitalWrite(IRledPin, LOW);
        delayMicroseconds(10);

        microsecs -= 26;
      }
     sei();
    }
   void LightOnCode()
{
  pulseIR(8940);
  delayMicroseconds(4380);
  pulseIR(520);
  delayMicroseconds(600);
  pulseIR(520);
  delayMicroseconds(560);
  pulseIR(560);
  delayMicroseconds(560);
  pulseIR(520);
  delayMicroseconds(580);
  pulseIR(520);
  delayMicroseconds(560);
  pulseIR(540);
  delayMicroseconds(580);
  pulseIR(520);
  delayMicroseconds(580);
  pulseIR(520);
  delayMicroseconds(580);
  pulseIR(540);
        delayMicroseconds(1660);
  pulseIR(520);
  delayMicroseconds(1680);
  pulseIR(520);
  delayMicroseconds(1660);
  pulseIR(540);
  delayMicroseconds(1680);
  pulseIR(520);
  delayMicroseconds(1680);
  pulseIR(500);
  delayMicroseconds(1680);
  pulseIR(540);
  delayMicroseconds(1680);
  pulseIR(520);
  delayMicroseconds(1660);
  pulseIR(540);
  delayMicroseconds(580);
  pulseIR(520);
  delayMicroseconds(560);
  pulseIR(560);
  delayMicroseconds(560);
  pulseIR(520);
  delayMicroseconds(600);
  pulseIR(500);
  delayMicroseconds(580);
  pulseIR(540);
  delayMicroseconds(560);
  pulseIR(520);
  delayMicroseconds(1680);
  pulseIR(540);
  delayMicroseconds(560);
  pulseIR(520);
  delayMicroseconds(1680);
  pulseIR(540);
  delayMicroseconds(1660);
  pulseIR(520);
  delayMicroseconds(1680);
  pulseIR(520);
  delayMicroseconds(1640);
  pulseIR(580);
  delayMicroseconds(1660);
  pulseIR(520);
  delayMicroseconds(1660);
  pulseIR(560);
  delayMicroseconds(560);
  pulseIR(520);
  delayMicroseconds(1680);
  pulseIR(520);

}

If anyone could answer my question as to why the led keeps sending extra signals I would appreciate it! If you have any questions don't hesitate to ask!

Taking a quick look at the Documentation on page 22, it looks like you need to use your bvSerial.strData calls within a function called void serialEvent() rather than inside of your loop.  I would recommend trying out their tutorial on that page just to make sure you get BitVoicer to work properly before scaling it for your application.
Hope that helps!

Sorry for the late reply, but thank you very much! I will try and mess around with it more tonight and post an update on the progress!


text:
Light up multiple LEDs with standard Arduino Uno
I am trying to find out if it is possible to light up multiple LEDs with a standard Arduino Uno. Say I have 500 LEDs and logically I give each one of them a number from 1 to 500. In my test scenario I'd like to say something like "LED No 275 On" and as a result only have this single LED turning on while all others remain off.
Is there a way to do that at all? Or will I have to use many different Arduino Unos for that?

With these kinds of amount, people generally use multiplexing. You could light 500 leds with "only" 45 pins. You can do this yourself, or use a dedicated IC like e.g. the MAX7219.

Probably the simple answer is to use 63 8-bit shift registers, with a LED and resistor attached to each shift register output pin. There are many good examples of using shift registers to add output ports on the internet.
The shift register solution will let you turn on just one LED at a time, or if your power supply can stand it, all 500 at once.
This question shows how to go about the expansion Is there a way to have more than 14 Output pins on arduino?
It also gives some other valid options.

Rectangular matrices and strips of dozens or hundreds of LEDs are available from places like Adafruit and Sparkfun, with added circuitry to allow you to address and manipulate single LEDs easily. Some are single color, some are RGB. Adafruit in particular has many products like this and many tutorials on how to use them.

authors: Коля Мельник


text:
Connect ethernet cable wires directly to pins
Is it possible to uncrimp a RJ45 plug and connect the wires directly to the Arduino pins? I guess I'd have to decrypt the ethernet signal then on my Arduino which might not have enough processing power at command for such a task.
I don't want to do it with an Ethernet shield, so please don't link any in the answers.

If it was that easy there wouldn't be any Ethernet shields around.  Ethernet is a complex system with specialist electrical requirements. It can't be interfaced direct.

I'm curious what you are trying to achieve.  Would you mind explaining?

@Butters i simply wanted to avoid the need of a shield and then i was curious if it would be possible. nothing exciting unfortunately :)

Does it need to be Etherenet, or is wireless okay?  You may be able to use the Adafruit Huzzah ESP8266 breakout.  Very flexible little chip, and way cheaper than an Uno and Ethernet shield.

I'm posting this question here because I do not have enough rep. Would you still be able to pass the communications through an unmanaged switch?

anything's possible: https://www.youtube.com/watch?v=XKnyAYKP434

Electrically, you don't have to worry about anything, as the previous answer stated, but Ethernet (Even 100Mbps FastEthernet, much less Gigabit) is way too fast for the Arduino to read.  digitalRead() is roughly 100x too slow, it takes roughly 4 microseconds, and even doing direct port reads is 5x too slow.  This doesn't take into account another operations, much less the fact that the clocks on the Arduino's don't run that fast.
100Mbps FastEtherent runs at roughly 31MHz, or 31,000,000 Hz.  That is FAST compared to our Arduino's, which have a clock speed of only 16MHz.
To answer your question in a word, no, it is not possible to do what you ask.

Ethernet is LVDS and requires isolation. You need some kind of extra hardware to turn that LVDS into a +5/GND signal. There is no ground in LVDS, so you cannot interface to it directly.

As others have stated, it's not physically possible for an Arduino to encode or decode standard Ethernet protocol messages over CAT5 cable with wires at one end connected directly to the Arduino pins, and the other plugged into a standard Ethernet device.
Standard Ethernet runs at least 10 Mbit/s for 10BASE-T, each bit Manchester encoded, so effectively 20 Mbit/s. See "TCP/IPv4 and Ethernet 10BASE-T/
100BASE-TX Debugging" for a lot of photos of what the standard Ethernet protocol looks like on an oscilloscope screen.
An Arduino running at 16 MHz can't sample a pin at 20 Mbit/s.
However, Arduinos can easily transmit and receive messages using a variety of other, slower communication protocols.
Devices that use such protocols can often be wired directly to the Arduino pins, with the Arduino programmed appropriately with that protocol.
Occasionally people use CAT5 cable (commonly called "ethernet cable") to carry those non-Ethernet messages from one device to another.
Sometimes people wire a RJ45 socket (also called a 8p8c socket) directly to an Arduino and corresponding RJ45 socket wired directly to the other device (often with a big "THIS IS NOT ETHERNET" warning on both sockets), and use standard off-the-shelf CAT5 patch cables with standard RJ25 plugs (also called 8p8c plugs) to carry those non-Ethernet messages between the sockets.
(For example, the connection between the Arduino-compatible "Motherboard 1.2 Generation 3" and the "Stepper Motor Driver 2.3 Generation 3" used in some early RepRaps; the TechZone Thermocouple A-D converter and other 1-wire devices that use the 1WRJ45 standard; etc.
As far as I can tell, none of the many CAT5 cables Nate connected to various Arduinos in "Lessons from Rebuilding Illumitune" actually carry any Ethernet messages.)
Sometimes people cut and strip the ends of CAT5 cable, using them as a convenient bundle of wires that can be used pretty much like any wire.
Hooking wires directly between two Arduinos (or an Arduino and some other device using some non-Ethernet protocol) often seems to work when both are plugged into the same power supply and connected by a short cable. The "extra hardware" people use to interface between an Arduino and a Ethernet network or CANbus or RS485 bus or MIDI or etc. helps avoid a variety of problems that happen when two devices are plugged into different power supplies or have long cable runs between them or both.

I am by no means an expert on this, this answer is ~20 minutes of me googling things, but I would say that in theory it is probably possible to do this with an arduino, at least at the lower transfer rates anyway, and certainly from a "will it kersplode my board" point of view - probably not since ethernet runs at +/- 2v (ish) and ~10mA (ish). However:
The ethernet protocol is exceedingly complex, with many layers needed to actually communicate with anything useful, all of which you would have to implement from scratch (there won't be a library to just drop in) and I'm not completely convinced that an entirely software-based implementation of the stack would fit on the arduino (but I could definitely be wrong there - and actually, on further thought, this probably is wrong, but I reckon I couldn't write it so it fit, but I'm a reasonably average human being).
Arduino is all about hacking and re-inventing wheels just for the fun of it but I am absolutely certain that there is no fun to be had re-engineering Ethernet and TCP/IP and all of the stuff in betweeen from scratch (obviously my opinion, I enjoy all sorts of things others don't, so YMMV).
My suggestion would be - if you don't like ethernet shields, look into getting a 'raw' ethernet controller chip (like the one soldered onto an ethernet shield) and build it directly into whatever device you're trying to make first, that'll give you plenty of exposure to how ethernet works at that level, then you can decide if you're still up for re-inventing the brain that invented the wheel. Good luck!

okay .. i might wanna reconsider if i want to do it without the shield :D I was just wondering if someone has ever done that .. would be a cool project for someone who wants to study TCP/IP though. thanks for the insight

What are you trying to achieve? There might be a more straightforward way to do it using the usb/serial connection to a computer or similar.


text:
port name showing up as gibberish
I'm running arduino 1.6.6 sketchbook, and been using the sketch book for my arduino uno for a couple of months. A week ago roughly it started acting weird, for a reason I haven't been able to figure out even after extensive googling.
I got Windows 10 educational version (free version thx to my uni).

In device manager, the board shows up correctly (named itself COM3 Arduino Uno)

I suspect it might have to do with drivers somehow, but reinstalls, updates, and every option I have tried so far has failed. The error that the sketchbook gives is avrdude: ser_open(): can't open device "\.\COM3?ðÕ&¬ôÕ&´æiúd??þÿÿÿÈð": The system cannot find the file specified.
Has anyone seen something similar before?

Can you bring up command line and run arduino.exe --port COM3 (you may have to first cd to the path where arduino is installed). See arduino manpage Just curious, did it stop working after the Tuesday update?

just did that, the load-in page for arduino runs for about 1 sec, and then the process kill itself.
About that update, it might be related, although haven't paid attention to updates so can't say for sure.

yes, as it should, but then when you re-launch the arduino IDE, it should remember the port setting as COM3. The menu will probably still be messed up, but the status bar should at least have the right port selected.

Correct, but doesn't solve my issue, as the status bar had the correct port selected already from before.

Ah well, that's why I didn't post this as an answer... I don't have a win10 system to test on. I thought maybe Arduino IDE was sending wrong port name to avrdude, but the --port setting should have fixed that.

Just noticed you're using Arduino 1.6.6 which was released only a couple weeks ago, can you try using the stable version 1.6.5 instead? Maybe this is a regression bug.

It looks like a badly terminated string in C - except it's java. Maybe you need a new version of Java installed?

I just tried installing the version 1.6.5, and downloaded&installed the latest version of Java, and restarted the computer. Didn't work though. Any other suggestions?

Problem was caused by the jdk, updating that solved it. Majenko's comment was helpful. Thanks

Unfortunately this problem is persistent. Same problem came back, and updating the jdk again doesn't fix it again. Any other ideas?

Try updating the IDE or restarting the computer.


text:
Arduino countdown timer for repeating actions
I have tried to find simple library for triggering timer after some time.
The idea is to retry network connection (RF24 network library).
I have following code now
while(!mesh.write(message, headerType, memSize)) {

}

This code will try to send packet until success
But I need to give up after for instance 10 seconds
I wanna to have something like this
bool timerTriggered = false;
Timer myTimer = new Timer(10000);
myTimer.setCallback(countedDown);

void countedDown() {
   timerTriggered = true;
}

And start timer before network request
myTimer.start();

while(!mesh.write(message, headerType, memSize) || !timerTriggered) {

}

Please suggest the best way to implement this.
Thanks.
EDIT
I have found problem as far as delay(); uses timer internally it conflicts with libraries or simple timer.
The solution is to use Alarm.delay(400); instead.
Maybe someone knows better solution ?

Something like this would work as a non-blocking, general purpose timer:
unsigned long startTimestamp;
unsigned long timestamp;
const unsigned long timer_length = 10000; //10 seconds

startTimestamp = millis();
timestamp = startTimestamp;

while ( (timestamp - startTimestamp) < timer_length)
{
    // keep doing thing

    timestamp = millis();
}

// stop doing thing now

To expand on the other answer and combine it better with your situation:
Just check the current time in your while loop:
unsigned long startTime = millis();
while((!mesh.write(message, headerType, memSize)) && ()millis() - startTime) < 10000)) {
}

That is, while it's not transmitted properly, and the difference between now and when you started transmitting is less that 10 seconds, keep trying.
There is no need for any special libraries or asynchronous timers - it can all be done by examining millis().


text:
Negative voltage output Or Controling negative voltage
I've got an RGB led strip I'm trying to control. It's a 12v, 4 pin strip.
Pin layout seems rather odd to me as 1 pin takes 12v of power and 3 pins (that go to ground) control the colors. In other words, the LED colors are controlled by limiting outgoing voltage.

White- +12v
Green- Green in negative voltage
Red - Red in negative voltage
Blue - Blue in negative voltage

I've already made a similar setup that uses n-channel MOSFETS (or at least I think that's what they are) between the colored cables and the ground and Arduino power the MOSFET gates as necessary.
So my question is: is it possible to hook these LEDs up directly to arduino and control the negative voltage without aditional electronics?
As a slightly off topic question: Is there a specific name for elements that are controlled with negative voltages.

By the way, I'm using Arduino nano, although I don't think it is relevant at this point and I've got Mega and Uno aswell if needed.

It seemed weird to me too, at first. But you'll find out it actually makes it a lot easier to connect. Switching the cathode side only requires an n-channel transistor/mosfet, which you can drive directly from 5v arduino pins. Switching the anode side would require additional components since the transistor/mosfets would require 12v signals.

No, it's not possible, since the voltages and currents involved (12V) are too high.  It will damage your board.
Your arrangement with N-channel MOSFETs is the correct arrangement.
By the way, you are not working with "negative" voltages at all - it's all positive - you just happen to be between the "load" and ground.
This is called a Low Side Switch since it is on the "low" (i.e., between the load and ground) side of the circuit.
The LEDs you have are in an arrangement called Common Anode in that the anodes (+ pins) of the LEDs are all tied together (common) and you control the cathode (- pins) of the LEDs.  It means you can use cheap N-channel MOSFETs that are (as you have seen) easy to control with a microcontroller.  The other arrangement, Common Cathode, where all the cathodes (- pins) are tied together and you switch the power to the anodes (+ pins) requires P-channel MOSFETs and N-channel MOSFETs to switch the P-channel MOSFETs, which increases costs.

Just for the reference If I used 5v LEDs would it be possible then?

If you used 5V LEDs and the total current for all the LEDs on one colour channel was below around 20mA then yes it would be possible.

I'm still far from understanding the limits of arduino, but. I just checked the leds. They are just under 4mA/channel.
Wouldn't that work with VIN pin powered arduino?

Then if they are 5V LEDs you can run around 5 channels in parallel without any extra hardware. Any more than that and you will need the MOSFETs regardless to handle the extra current.

It doesn't have to be MOSFETs, a bog-standard cheap NPN BC547 or similar would be fine.


text:
Infrared distance sensor picks up distances that are not there
I have connected an Infrared sensor to my Arduino Uno and I've set this code up to blink whenever a distance of less than 50 cm is picked up. If there is an object less than 50 cm away, it does pick it up. However, with nothing in front of it it still blinks at random intervals. The sensor is new. Where do you think the problem is?
int sensorPin = 0;
int ledPin = 13;

void setup() {
  pinMode(ledPin, OUTPUT);
}

void loop() {
  float distance = 12343.85 * pow(analogRead(sensorPin),-1.15);
  if(distance < 50){
    digitalWrite(ledPin, HIGH);
    delay(1000);
    digitalWrite(ledPin, LOW);
  }
  delay(50);
}

Maybe some specks of dust, or just electrical noise. You could try averaging the measured value. What I generally do is take 10% of the current value, and 90% of the old averaged value.

Have you read this reference? http://bildr.org/2011/03/various-proximity-sensors-arduino/. It explains some of the issues with this sensor. It is great for a closed box with no "extra light". It is easy to disturb the sensor with IR from a remote or just sun light.

I see one problem with your code and how it relates to this device.
The output from the sensor is not the monotomic function you describe; not over its entire range.  Your conversion function describes only a section of the response.  The device is only intended to be used when an object is in range 10-80 cm.
You should check that the voltage at the analog input is valid before performing the math:
int v;

v = analogRead(sensorPin);
// sensor is valid in range 0.4 to 2.5 V
if((82 < v) && (v < 512)) {
  // voltage is in usable range, can convert
  distance = 12343.85 * pow(v,-1.15);
  if(distance < 50) {
    digitalWrite(ledPin, HIGH);
    delay(1000);
    digitalWrite(ledPin, LOW);
  }
}
else {
  // no valid reading - probably just skip and try again on next loop
}

With that the false triggers may be eliminated.

Scaling to voltage is unfortunately missing; float voltage = sensorValue * (5.0 / 1023.0); https://www.arduino.cc/en/Tutorial/ReadAnalogVoltage

I am presuming that OP's formula does convert ADC counts to distance.  But I have corrected that the conditional is in counts.

Looks to me like there could be a signficant figures issue. Arduino can really only handle 7 digits of precision. You hit that right at your first constant in your distance variable, then you multiply by an integer to a power of -1.15. It's likely there are errors there that trip to less than 50, which would give you false positives.
As for the Sharp IR sensors, just buy an IR photodiode and LED for less than $1 USD and build and calibrate your own IR detector. You can calibrate it to a range of about 1 m. That's my recommendation. I did something similar after being frustrated by the cost of the Sharp IR Detectors. Wrote about it on my blog, if you're interested:
https://engineersportal.com/blog/2018/1/17/infrared-obstacle-detector-for-less-than-1


text:
exit(0) function shows up an error
So I have been trying to write a code where I use the millis() function to print the milliseconds of on-time of the board using Serial. But the condition is I want to stop printing the value once it reaches 10 seconds (10000ms).
I have been trying to use the exit() function but I get no output then.
#include<stdlib.h>

void setup()
{

  Serial.begin(9600);          //  setup serial

}

void loop()

{

unsigned long timer1;

while(timer1%10000!=0)

{

timer1=millis();

Serial.println(timer1);

}

    exit(1);

}

What do you imagine exit() is supposed to do in an embedded system?

exit() is probably a bad idea in a bare-metal embedded system unless you know for a fact how the environment will respond.  Consider either an infinite while(1); loop explicit in your own code, or shutting down the processor.  Make sure to wait until the serial output buffer is empty before shutting down or disabling interrupts, or you may see your messages truncated.

Where do you suppose exit() would exit to in a microcontroller? Your desk?

The AVR library documentation for exit() is great help. It explains that the interrupts are turned off and an infinite loop is entered. As the interrupts get turned off the last characters in the Serial buffer are not transmitted.
You can use Serial.flush() to wait for the transmission to complete before calling exit().
Cheers!


text:
Counting loops or if..else
What I would like to do is,
 step 1:
led1 fades from black(off) to green (max-on 255)
led2 fades from black(off) to red (max-on 255)

this happens at the same time.
If the max value is reached, then both leds fade out (to black, off)
so step 2:
led1 fades from green to black
led2 fades from red to black

Then step 3, almost same as step 1 but opposite colours:
led1 fades from black(off) to red(max-on 255)
led2 fades from black(off) to green(max-on 255)

And step 4, both fade to black
led1 fades from green to black
led2 fades from red to black

This is the code that fades led 1/3/5 from red to black and back to red
and led 2/4/6 from green to black, and back.
#include <FastLED.h>
    #define NUM_LEDS 6
    #define DATA_PIN 3

        CRGB leds[NUM_LEDS];

           void setup() {
               Serial.begin(9600);
       FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
   }

       void loop()
{

  int x = 1;
   for (int i = 1; i > -1; i = i + x){

     leds[0] = CRGB(i,0,0);
     leds[1] = CRGB(0,i,0);
     leds[2] = CRGB(i,0,0);
     leds[3] = CRGB(0,i,0);
      Serial.println(i);
      FastLED.show();
      if (i == 55) x = -1;             // switch direction at peak
      delay(100);

   }
}

****Original question****

I am trying to fade a led (WS2812B) from black to green or red, and
  back to black. (that is working)  But now I want the same led fading
  to blue.
How could I do that? I was trying a if..else but can't figure it out
  Or should I count the for loops?
This is the starting code I am using
maybe something like
    if (i==0)
{
             leds[0] = CRGB(i,0,0);
             leds[1] = CRGB(0,i,0);
             leds[2] = CRGB(i,0,0);
             leds[3] = CRGB(0,i,0);
}
    else
{
             leds[0] = CRGB(0,0,i);
             leds[1] = CRGB(0,0,i);
             leds[2] = CRGB(0,0,i);
             leds[3] = CRGB(0,0,i);
}
              FastLED.show();
              if (i == 100) x = -1;
              delay(100);

But that is not working. Any suggestions?

Please provide your entire code, which doesn't work. Please tell us what it does, and what you expect/want it to do.

the same led fading to blue. Please elaborate.

added some new info

The maximum value is 255 for each RGB value, you are stopping it at 100.

I would do that based on the clock. This lets you run each one independently.
On the off-chance that your project runs that long, the clock rolls over (resets) every 50 days.
I'm going to assume the 55 in your code should read 255.
I would do something like this (this is a code snippet, but should get you started):
const int phase_milliseconds=2500; // each phase lasts 2.5 seconds.
const phase_progress_length=256;   // each phase goes from 0 to 255
const phases=4;                    // numbered from 0 to 3, will repeat forever.

// This is the time since your Arduino turned on
unsigned long time=millis();
// how far we are through the current phase?
int progress= time%phase_milliseconds)*phase_progress_length/phase_milliseconds;

// which phase are we in?
int phase=(time/phase_milliseconds)%phases;

if (phase==0) { // first step
         leds[0] = CRGB(progress,0,0);
         leds[1] = CRGB(0,progress,0);
} else if (phase==1) { // second step
         leds[0] = CRGB(255-progress,0,0);
         leds[1] = CRGB(0,255-progress,0);
} else if (phase==2) { // third step step
         leds[0] = CRGB(0,progress,0);
         leds[1] = CRGB(progress,0,0);
} else if (phase==3) { // fourth step
         leds[0] = CRGB(0,255-progress,0);
         leds[1] = CRGB(255-progress,0,0);
}

Since this is time based, it doesn't matter much how often it runs, you don't need a delay (you can still put one in if you like). You can extend this to more steps.
Also note that I rattled this off, off the top of my head, so there may be errors.


text:
Seeking help - Using CJMCU 8*8 LED matrix with arduino
The CJMCU 8*8 LED board is a grid of 64 W2812 (addressable) LEDs. The board is configured as if it was one long LED strand (just a single  DIN, 5v and GND). For some flipping hair pulling reason, my code works fine on 2812 LED strands, but I get nothing on the board. Just random flickering when I jostle the 5V wire. Any ideas? Am I completely missing something here? Pretty sure the board is fine, just can't seem to take any input...
(Here's a link to the board: http://www.aliexpress.com/store/product/CJMCU-64Bit-WS2812-5050-RGB-LED-Development-Board-Built-in-RGB-Driver-White-SKU-11481/933826_32249197598.html)

Looks a lot like https://www.adafruit.com/products/1487. Do you have more details to how you have connected it. It requires a lot of power! At least 5V 2A.

The link no longer works.

I just received 2 of these from 2 different suppliers on EBAY.
None work using the pins called [GND +5V DIN]. As it turns out the DIN is actually NOT DIN. The other connector area [GND +5V DOUT] is the DIN. Ugh!
These boards are marked CJMCU-8*8 on the back side and on the front they say "WS2812B-64 RGB LEDS". Which is another issue. They are using the 6 pin WS2812, not the 4 pin WS2812B.
So if this is what your board looks like then perhaps try the pin marked DOUT for your DIN. Or try to psych out the traces to make sure first.

Had the same issue, turned out that DOUT swapped with DIN. Thanks for a hint.

Thanks for the awesome tip about DOUT. I hooked up that one instead and now the matrix works fine. Geez.

Unbelievably, as I've just discovered, this has been a known issue with these boards for at least a year and a half, yet they are still shipping them. The silk screening process of labeling the board is the problem. Just poor quality control. The front (LED) side of these low quality CMJCU-8*8 boards are incorrectly marked "SM2812B RGB LEDS". (The actual LEDs are 6 pin SM2812's, not 4 pin SM2812B's), but the real problem is with the back side of the board. The manufacturer printed the boards upside down, so that the input and output labels are reversed (DIN is really DOUT and vise versa).
I just purchased one of these defectively printed boards on line and received it a few days ago. Took me awhile to figure out why I couldn't get it to work, but I finally did. When hooked up backwards, the CMJCU-8*8 will do nothing at all (no LEDs will come on), because of the built in reverse polarity protection, but if you run your thumb hard (it's just +5V) over the other pins (the ones that include the erroneously marked DOUT) while the board is powered up, one or more of the SM2812 LEDs will magically come on. This is because your thumb makes an intermittent connection between the real DIN and the +5v rail, providing a forward bias to a few random LEDs. Once lit, these LED's will actually stay on until you cut power to the board, so if you keep ding it, you can get quite a few of the SM2812s to come on.

My CMJCU-8*8 board is labelled correctly, so try they DIN pin first.

Hi, I wouldn't have any of the leds come on if this were still the case with my board, right ?
I can only get the first two rows (or columns) to light up. They're not lighting up in a way that I would expect if the rest of the LEDS was broken (random colors, random brightnesses, no apparent logic)

I just tried it, only one LED will come on, bright blue, somewhere on the third row...

Literally spent hours painstakingly chasing same problem. Complained bitterly to supplier that board refused to respond or operate when received. They responded by trying to tell me I had no clue about how to connect, but eventually agreed to send replacement after I proved had connected correctly, while waiting for replacement came across this post, went and found original board and reconnected, 5V to DIN side, and DIN to DOUT (Instant operation) because the reverse polarity protection does not prevent being energized this way. if supplier comes good, will have another board to compensate my trouble.


text:
What's wrong with my IR sensor
I bought some 'lucky dip' IR sensors from China, no idea what they are, but they appeared to get lost in the post so instead I bought some of these from a reputable place in the UK that come with a datasheet.
The next day, both items arrived together!
I'm trying to build a very simple proximity sensor for a robot, I built the following circuit:

simulate this circuit – Schematic created using CircuitLab
and stole this code to test it out:
#define IRledPin 8
#define D13ledPin 13
#define IRsensorPin 9

void IR38Write() {
  for(int i = 0; i <= 384; i++) {
    digitalWrite(IRledPin, HIGH);
    delayMicroseconds(13);
    digitalWrite(IRledPin, LOW);
    delayMicroseconds(13);
  }
}

void setup(){
  pinMode(IRledPin, OUTPUT);
  digitalWrite(IRledPin, LOW);
  pinMode(D13ledPin, OUTPUT);
  digitalWrite(D13ledPin, LOW);
}

void loop(){
  IR38Write();
  if (digitalRead(IRsensorPin)==LOW){
    digitalWrite(D13ledPin, HIGH);
  } else {
    digitalWrite(D13ledPin, LOW);
  }
}

If I hold my hand in front of it, nothing happens (LED on-board arduino should light up), however if I point a TV remote at it and press a button, the LED lights up. I tested 2 of the 'fancy' sensors that I got and both behaved the same.
Then I tried one of the 'lucky dip' sensors, swapped it straight in and the whole thing works perfectly - point a TV remote and the LED lights, hold my hand ~10cm in front of it and the LED lights!
So, where have I gone wrong?

@NickAlexeev - this is not actually an Arduino question, rather it revolves around the behavior of the IR receiver module.  Migrating it was improper - you have to read these things, not just trigger off of keywords.

I did wonder about that - this isn't really an Arduino-specific issue, it just happens that I'm using one in this instance.

What happens to these questions? Do they get migrated back to EE or just lost?

See page 5 of your datasheet - that 'fancy' sensor suppresses "• Continuous signals at any frequency".
So you'll need to pulse your 38.4kHz signal for the sensor to produce an output.

Wow, thanks. Datasheets are hard! It's actually quite hard to do that all on the same board - by the time the sensor starts looking for the signal, it's pretty much stopped bouncing back. I did manage to get it to trip with my hand by making it pulse but it's really unreliable. I chose entirely the wrong sensor for what I'm trying to do, I had no idea some were that clever! Thanks

You should be able to put a delay at the start of your loop, perhap 100ms, and adjust the number of cycles of output to be in range of what the detector considers a pulse.  It would be better if you checked for results while transmitting, subtracting the time to do so from the delays (probably use a scope to calibrate).  Or you can probably use a hardware timer to transmit.  Best proximity results will be with a synchronous detector, ie, lock-in amplifier rather than a remote receiver blob.

yes, perhaps you can use one of the PWM outputs on your arduino to drive the LED

The answer I've accepted is the correct answer, but I wanted to add this extra bit for completeness. I reworked my code to use non-blocking delays for the IR LED so the sensor actually gets a chance to see it before it stops transmitting and it works! Range is quite a bit shorter than the 'lucky dip' sensor (~ 2cm).
#define IR_LED 8
#define LED 13
#define SENSOR 9

unsigned long burst_timer;
unsigned long gap_timer;

unsigned long timestamp;

char led_state;
char burst_count;

const char BURST_MAX = 20;

void setup()
{
  pinMode(IR_LED, OUTPUT);
  led_state = LOW;
  burst_count = 0;
  digitalWrite(IR_LED, led_state);

  pinMode(LED, OUTPUT);
  digitalWrite(LED, LOW);

  pinMode(SENSOR, INPUT);

  timestamp = micros();
  burst_timer = timestamp;
  gap_timer = timestamp;
}

void toggle_led()
{
  if (led_state == LOW)
  {
    led_state = HIGH;
  }
  else
  {
    led_state = LOW;
    burst_count++;
  }

  digitalWrite(IR_LED, led_state);
}

void loop()
{
  timestamp = micros();
  if (timestamp - burst_timer > 13 && burst_count < BURST_MAX)
  {
    toggle_led();
    burst_timer = timestamp;
    gap_timer = timestamp;
  }

  if (burst_count >= BURST_MAX && timestamp - gap_timer > (13*2*BURST_MAX) )
  {
    burst_count = 0;
    burst_timer = timestamp;
    gap_timer = timestamp;
  }

  if (digitalRead(SENSOR) == LOW)
  {
    digitalWrite(LED, HIGH);
  }
  else
  {
    digitalWrite(LED, LOW);
  }
}

Every time I use delay() (or delayMicroseconds()) I find a new reason not to!

That's a good lesson learned then. Delay() is second in line to String in the evil stakes.


text:
Nokia32/RCMM IR decoding issues
I am trying to decode the IR signals from a remote. I'm using an Arduino Pro Micro, and a TSOP38238 IR receiver.
I found out that the remote uses the Nokia32(RCMM) protocol, and I have been able to partially decode it using cyborg5/IRLib (specifically this one: rcmm.ino). I tweaked the values of the example using the LIRC file corresponding to my remote, mainly the absolute error tolerance (Freebox_V5.lircd.conf).
Compared to other remotes I tried (with different protocols) the RCMM algorithm doesn't manage to decode the signal every time. Around 40% of the time when I press a button I got an "Unknown type received" output from the decoder.
The following is three outputs (for the same button) of the algorithm for a successful decoding and below two other outputs corresponding to two failures. Could anyone tell me what could be done to increase the success of the decoding algorithm?
Successful
Decoded RCMM: Value:2400A601 (32 bits)
Raw samples(36): Gap:63264
  Head: m410  s290
0:m160 s290 1:m160 s590      2:m210 s390    3:m210 s240
4:m210 s240 5:m210 s240      6:m210 s240    7:m210 s240
8:m210 s540 9:m210 s590      10:m210 s390   11:m210 s590
12:m160 s290    13:m160 s290         14:m160 s240   15:m210 s440

16:m160
Extent=9810
Mark  min:160    max:210
Space min:240    max:590

Failure 1
Unknown type received. Ignoring.
Decoded Unknown(0): Value:0 (0 bits)
Raw samples(36): Gap:3148
  Head: m410  s290
0:m160 s240 1:m210 s590      2:m210 s390    3:m210 s240
4:m210 s240 5:m210 s240      6:m160 s290    7:m160 s290
8:m160 s590 9:m210 s590      10:m160 s440   11:m210 s590
12:m160 s240    13:m210 s240         14:m210 s240   15:m210 s390

16:m210
Extent=9810
Mark  min:160    max:210
Space min:240    max:590

Failure 2
Unknown type received. Ignoring.
Decoded Unknown(0): Value:0 (0 bits)
Raw samples(32): Gap:27904
  Head: m410  s290
0:m160 s290 1:m160 s590      2:m160 s490    3:m160 s240
4:m210 s240 5:m160 s290      6:m160 s290    7:m160 s290
8:m160 s290 9:m160 s590      10:m160 s490   11:m160 s590
12:m160 s1190   13:m160 s440         14:m160
Extent=9460
Mark  min:160    max:210
Space min:240    max:1190

Are all three of those for the same button?

yes, my bad I edited the text to be more clear

I can see where the third one went wrong (not why, only where so far), but just correlating them all together at the moment in a spreadsheet. Manually decoding :)

the timings are left unchanged from the original file (https://github.com/cyborg5/IRLib/blob/master/examples/rcmm/rcmm.ino line 35). The tolerance line 60 is set to 100.

The problem is very much with the timing. I don't yet know whether that is the reception timing or the transmission timing, but there are some big errors in the numbers.

Hmmm... Manually decoding the values - the second one should have worked (better than the first one actually). The third is a complete failure of course.

Incidentally, from those figures, a tolerance of 75 should be good to use.

Sorry not to have been able to answer earlier. Here is the output of 10 clicks on one button with a tolerance of 75 : http://pastebin.com/jrZaDQty. What is quite wierd is the decoding value when there is a success (it's either 2400A601 or 24002601). I'm a bit lost ...

I'm unable to provide a complete answer yet but my research so far into a similar quest to use a similar remote can at least answer why you are getting two values for the same button on the remote. This is by design: the Nokia-32 RCMM protocol of this remote uses toggling codes that flip between one value and another on alternating presses of the same button.
My quest and the challenges of decoding this remote are documented in this thread: https://github.com/bengtmartensson/harctoolboxbundle/issues/97 where I discover that my IR remote uses Nokia 32 protocol but with mark and space timings slightly different from what most Arduino libraries are programmed for requiring a tweak to the signal in order to enable other libraries to decode it successfully.
Further information here: http://www.avsforum.com/forum/93-remote-control-area/1517341-theater-master-mx-500-remote-won-t-learn-bell-fibe-remote-any-help.html#post24345872 where we learn:

it is different from most IR signals, because it has 4 different off durations, denoting zero, one, two , or three, while traditionally IR protocols have used just two off durations signifying zero or one.

Could you please highlight the most important parts of the websites you've linked? If at one point those links break this answer will be unfortunately useless and we'd like to avoid that.

done... an upvote would be encouraging