text:
Manchester.h message format
I'm sending some data by 433Mhz transmitter using manchester.h library from here https://github.com/mchr3k/arduino-libs-manchester and I'm trying to wrap my head around message format. In manchester.cpp it is described very poorly.
I'm sending number 1. Here is the code for that:

#include <Manchester.h>
/*
  Manchester Transmitter example
  Try different speeds using these constants, your maximum
  possible speed will depend on various factors like transmitter
  type, distance, microcontroller speed, ...
  MAN_300 0
  MAN_600 1
  MAN_1200 2
  MAN_2400 3
  MAN_4800 4
  MAN_9600 5
  MAN_19200 6
  MAN_38400 7
*/
  #define TX_PIN 4  //pin where your transmitter is connected

  uint8_t transmit_data = 1;
  void setup() {
  man.setupTransmit(TX_PIN, MAN_4800);
}
  void loop() {
  man.transmit(transmit_data);
  delay(200);
}

Here is the screenshot from oscilloscope:

And here is the message for sending 0:

In manchester.cpp you can find message format:
/*
    format of the message including checksum and ID

    [0][1][2][3][4][5][6][7][8][9][a][b][c][d][e][f]
    [    ID    ][ checksum ][         data         ]
                  checksum = ID xor data[7:4] xor data[3:0] xor 0b0011

*/

But when you look at the actual oscilloscope readings it does not fit at all! Maybe I'm missing something? I'll be very grateful for any help in understanding this topic:)

Looks correct according to the code. The format above is not used for transmit. It is 4-bit sync, 16-bit data, and trailing 3-bit sync. Total 23 bits.

@MikaelPatel But if I'm sending 0, then all 16 bits of data should be 0, which is not the case, Or maybe I'm not seeing something?

The data is xor'ed with a decoupling mask (0b11001010 in this library). https://github.com/mchr3k/arduino-libs-manchester/blob/master/Manchester.cpp#L162 explained here https://github.com/mchr3k/arduino-libs-manchester/blob/master/Manchester.h#L114

The data is sent MSB first with least significant bit first per byte.

@MikaelPatel Ahhhh.... thanks a lot!!!! Do you understand why it is so? It would be far less complex if data was sent just straight bit by bit

An explanation for this design is available in the header file; "it's common to zero terminate a string or to transmit small numbers involving a lot of zeroes those zeroes may be mistaken for training pattern, confusing the receiver and resulting high packet lost, therefore we xor the data with random decoupling mask". This can be avoided by a start symbol in the preamble. Please example in https://github.com/mikaelpatel/Cosa/blob/master/libraries/ManchesterCodec/ManchesterCodec.hh. This is the Ethernet preamble. https://en.wikipedia.org/wiki/Ethernet_frame#Preamble_and_start_frame_delimiter


text:
Input voltage from circuit drops despite Arduino turned off
I'm using an Arduino Uno to emulate an old Atari disk drive as described here:
http://whizzosoftware.com/sio2arduino/
As both the Atari and the Arduino use 5V TTL serial communication, the hardware setup is pretty simple, RX and TX are crossed over, GND is connected an an additional line is used for status information.
All works fine when the Arduino is the only device connected to the Atari's serial port (called SIO). Since the SIO bus is a daisy-chain bus, I should be able to hook up serval devices after each other. However, once I connect an original floppy drive together with the Arduino, both the original floppy drive as well as the one emulated by the Arduino stop working.
What made me wonder is that the original drive couldn't be accessed even if the Arduino was turned off but the wiring left in place. Only after I removed the RX and TX pins from the connection, the original drive could be accessed.
I checked with a scope and realized that data transmission was still reaching both devices, however idle voltage was just around 2V instead of 5V. I then checked the resistance on the Arduino between the digital input pins as well as RX/TX in relation to GND and got (varying, depending on the scale I set my multimeter) values that probably have the effect of a voltage divider and thus reduced the voltage on the whole bus by about half.
I was thinking to add a resistor on the RX/TX lines coming from the SIO bus in order to maintain the voltage on the bus, but that would effectively mean that also less current reaches the Arduino RX/TX pins and might therefore render it useless if the voltage drops below the point where the Arduino can distinguish between logical high and low.
Or is there a way to circumvent these internal resitors between the digital inputs and GND? Does this have anything to do with the pull-up/pull-down resistors which I could probably only influence when the Arduino is on?
Thank you in advance for any pointers (other than adding another switch to physically remove RX/TX from the bus when the device is off ;) )!

Let me know if you need a more formal answer.  But, in short, you can not connect  unpowered logic circuits inputs to powered logic circuits.

You could look at the atari 810 schematics and see how they did it: http://www.jsobola.atari8.info/dereatari/literatdere/810fsm.pdf

Thans for the link, Craig, I'll have a look at it.

To protect the internals of integrated circuits many contain diodes at most input and output pins to VCC.  In normal operation where the voltage at these pins are not expected to become greater than VCC, these diodes are not in forward bias.  However, should the unexpected happen and the voltage at these pins does become higher than VCC the diodes are in forward bias.
 That is to say, the diodes try to keep the voltage at the pin no higher than VCC.
When you removed the power from the Arduino you essentially lowered VCC to zero.  This will likely forward biased the diodes inside the Arduino and drive the voltage at the pin toward zero.
There is a good discussion of this in this Electrical Engineering StackExchange question & answer.

Thanks, the diodes would probably also explain the varying Ohm readings I got depending on the scale of my multi-meter.

Although st2000 already answered my question, I still wanted to add how I solved the problem in case someone else faces the same situation:
What in the end worked for me was to add a 560 Ohm resistor each at the entry points of the RX/TX lines. This was low enough that the Arduino was still be able to distinguish logical high and low, and high enough that the SIO bus is still working when the Arduino is powered off. 470 Ohms was already too low to shield the SIO bus, 680 Ohms was too high for the Arduino to function properly when in use. I don't know if there is a way to calculate these values properly, but at least they work for me.

source: Stack Exchange

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

sort: votes


text:
Trying to Serial.write RAW code properly
I have a SIM800L Module connected to my arduino Nano. I want to open a TCP connection from the sim800l module to my own server and send a text string. The connection is working however I am not able to send text, because there is an issue with the arduino write() function I think... Below is the code I am trying to execute. Right after the message is sent, I need to send the stop value 0x1A (byte 26) to tell the sim800l module that the message end is reached and to send out the message.
My problem is, that it is not working in the arduino IDE and I don't know why.
My arduino code:
#include <SoftwareSerial.h>

#define SIM800_TX_PIN 8
#define SIM800_RX_PIN 7

SoftwareSerial serialSIM800(SIM800_TX_PIN, SIM800_RX_PIN);

void setup() {

serialSIM800.println("AT");
delay(500);

serialSIM800.println("AT+CIPSTART=\"TCP\",\"IP-ADRESS-HERE\",\"9999\""); //connection works
delay(500);

serialSIM800.println("AT+CIPSEND");
delay(500);

serialSIM800.print("TEXT MESSAGE HERE");
delay(500);

serialSIM800.write(26);
delay(500);

serialSIM800.println("AT+CIPCLOSE");
delay(500);
}

void loop() {
  //Empty
}

On my server I am running this python script that opens a socket:
import socket
import sys

HOST = ''   # all available interfaces
PORT = 9999 # Arbitrary non-privileged port

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
print 'Socket created'

#Bind socket to local host and port
try:
  s.bind((HOST, PORT))
except socket.error as msg:
  print 'Bind failed. Error Code : ' + str(msg[0]) + ' Message ' + msg[1]
  sys.exit()

print 'Socket bind complete'

#Start listening on socket
s.listen(10)
print 'Socket now listening'

#now keep talking with the client
while 1:
  #wait to accept a connection - blocking call
  conn, addr = s.accept()
  print 'Connected with ' + addr[0] + ':' + str(addr[1])
  data = conn.recv(1024)
  print len(data)
  print data
s.close()

Once I execute this, I see the connection is working because "Connected with IP:PORT" is printed on my console. However right after that "len(data)" is printed (0) and "data" is an empty string. I even upped the delay from 500 to 5000, still same result.
However, if I leave the arduino IDE and send the message using the program "HTerm", it is working! In HTerm I typed in the text message and hit enter. After that I switched from ascii to hex mode (there is a checkbox) and I just typed 1A and sent it. That way it worked. Anybody can help me? Why is it not working @arduino?

After typing 1A into HTerm hex mode, did you hit ENTER?

Yes I hit Enter and it worked in HTerm.

Replace serialSIM800.write(26); with serialSIM800.write(0x1A);, also  change serialSIM800.print("TEXT MESSAGE HERE"); with a println or add a carriage return \n.

good idea. I already tested this. serialSIM800.write(0x1A) didn't help and I even replaced all println with print and added a \n to the end of each string. That all didnt work... even with \r\n it didnt work.

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


text:
Melzi 2.0 Board Firmware Upload problem
I'm trying to flash the repetier Firmware to my Prusa i3 3D Printer, which uses Melzi 2.0 board. I uploaded it successfully 2 days ago with same settings  but now is failing always.
@avrdude -p m1284p -b57600 -c arduino -P COM%x% -e -U flash:w:%filename%.hex
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.02s
avrdude: Device signature = 0x1e9705 (probably m1284p)
avrdude: erasing chip
avrdude: reading input file "newa.hex"
avrdude: input file newa.hex auto detected as Intel Hex
avrdude: writing flash (114266 bytes):
Writing |                                                    | 0% 0.00s
avrdude: stk500_paged_write(): (a) protocol error, expect=0x14, resp=0x64
avrdude: stk500_recv(): programmer is not responding

How do I solve this problem?

The Electronics Stackexchange question avrdude error - stk500_paged_write() protocol error has answers that suggest three different tactics for protocol errors:
• Upgrade the Arduino IDE from 1.00 to 1.05, or install "AVR-GCC Toolchain" via Homebrew;
• Disconnect everything from TX / RX (Arduino digital pins 0 and 1);
• Use shorter or different USB cables, hooked to a USB port on computer instead of on a hub
I've seen dozens of answers here on arduino.stackexchange with such suggestions, as well as webpages elsewhere with ideas like those in an answer to AVRDUDE Error (Arduino Leonardo).
You could go through this list of programmer-is-not-responding arduino.stackexchange questions, and report back on what works and what doesn't:
• "avrdude: stk500_getsync(): not in sync: resp=0x00," aka Some Dude Named Avr Won't Let Me Upload My Program,
• How do I resolve "avrdude: stk500_recv(): programmer is not responding"?,
• avrdude: stk500_recv(): programmer is not responding after serial,
• avrdude: stk500_recv(): programmer is not responding + avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x47,
• avrdude: stk500_rcv :programmer is not responding,
• Arduino Nano Update failure - avrdude: stk500_recv(): programmer is not responding,
• avrdude: stk500_getsync(): not in sync: resp=0x00,
• Arduino Uno cannot upload any sketch: avrdude: stk500_recv(): programmer is not responding,
• "avrdude: stk500_recv(): programmer is not responding" when uploading sketch,
• Arduino not working / not uploading [duplicate],
• Problems uploading sketch to Arduino Due,
• FTDI stdk 500k not responding,
• Arduino Prototype on Breadboard: "avrdude: stk500_recv(): programmer is not responding",
• Arduino Nano - programmer is not responding,
• How do I resolve "avrdude: stk500_recv(): programmer is not responding"?,
• Arduino not in sync unique error,
• Arduino nano stopped working,
• Not in sync: resp=0x00,
• How to troubleshoot the Arduino Mini and Arduino usb2serial?,
• Atmega328P-PU: Programmer is not responding,
Note, click the “see more linked questions…” link in the sidebar to get a nice webpage with the above list and the opening lines of each question.

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


text:
Converting Arduino Uno with Ethernet Shield sketch for Arduino Yún
I'm new to the Arduino Yun and I'm trying to convert a sketch written for the Arduino Uno with a Ethernet Shield. The sketch does HTTP posts to Azure Mobile Services.
I've added in the Bridge.h and YunClient.h libraries in place of the Ethernet.h one for the Uno.
My modified sketch compiles, however, I don't think the http posts are working. I don't see my table updating in Azure.

    /*
    ** This sample Arduino sketch uploads telemetry data to Azure Mobile Services
    ** See the full article here: http://hypernephelist.com/2014/07/11/arduino-uno-azure-mobile-services.html
    **
    ** Thomas Conté @tomconte
    */
#include <Bridge.h>
#include <YunClient.h>
//#include <Ethernet.h> // removed as not used by Yun
#include <SPI.h>

// not sure if these libraries are required?
#include <HttpClient.h>
#include <Process.h>

// Ethernet shield MAC address (sticker in the back)
//byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
// 90:A2:DA:F8:28:38

// Azure Mobile Service address
// You can find this in your service dashboard
const char *server = "myhost.azure-mobile.net";

// Azure Mobile Service table name
// The name of the table you created
const char *table_name = "my_data";

// Azure Mobile Service Application Key
// You can find this key in the 'Manage Keys' menu on the dashboard
const char *ams_key = "HJRxFXXXXXXXXXXXXXXXXXXXNQoMcXXXXXXx99";

//EthernetClient client;
YunClient client;

char buffer[64];

/*
** Send an HTTP POST request to the Azure Mobile Service data API
*/

void send_request(int value)
{
  Serial.println("\nconnecting...");

    Serial.print("sending ");
    Serial.println(value);

    // POST URI
    sprintf(buffer, "POST /tables/%s HTTP/1.1", table_name);
    client.println(buffer);

    // Host header
    sprintf(buffer, "Host: %s", server);
    client.println(buffer);

    // Azure Mobile Services application key
    sprintf(buffer, "X-ZUMO-APPLICATION: %s", ams_key);
    client.println(buffer);

    // JSON content type
    client.println("Content-Type: application/json");

    // POST body
    sprintf(buffer, "{\"value\": %d}", value);

    // Content length
    client.print("Content-Length: ");
    client.println(strlen(buffer));

    // End of headers
    client.println();

    // Request body
    client.println(buffer);

}

/*
** Wait for response
*/

void wait_response()
{
  while (!client.available()) {
    if (!client.connected()) {
      return;
    }
  }
}

/*
** Read the response and dump to serial
*/

void read_response()
{
  bool print = true;

  while (client.available()) {
    char c = client.read();
    // Print only until the first carriage return
    if (c == '\n')
      print = false;
    if (print)
      Serial.print(c);
  }
}

/*
** Close the connection
*/

void end_request()
{
  client.stop();
}

/*
** Arduino Setup
*/

void setup()
{
Serial.begin(9600);
Serial.println("Starting Bridge");
Bridge.begin();

}

/*
** Arduino Loop
*/

void loop()
{
  int val = analogRead(A0);

  send_request(val);
  wait_response();
  read_response();
  end_request();

  delay(1000);
}

Ok I figured this one out, I was missing the code to connect to the web service
if (client.connect(server, 80)) {

(Updating answer from comments.)
The OP answered their own question, they missed the code to connect to the web service
if (client.connect(server, 80))

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


text:
Arduino Mega prototype analog timer interrupts: newbie question
I am currently using an Arduino Mega with a fast vibration sensor to trigger the components operation (force sensor, temperature sensor) and also toggle sleep mode.
I am very new at this and I have been doing some googling, but I just can't seem to understand it.
So, my questions are:

How would I toggle(on/off) sleep mode?
How would I use interrupts (timer, pin change interrupt?) for an analog pin that triggers when the vibration sensor is triggered, resulting in other components operating?

I am currently working on a Mega, but I will eventually move on to the Arduino Mini Pro. I hope there are no exclusive problems later on.
I realize that this is not a professional question, but I find these tasks very challenging.
Please help me. An example link or perhaps example code to help me understand better.
Thank you very much.

What do you mean by “an analog pin that triggers when the vibration sensor is triggered”?

so when the vibration sensor gets triggered, then then the analog pin goes out of sleep mode(or the entire board goes out of sleep mode) and the analog pin will start getting inputs from external components in a specific frequency (how much is the analog reading [every 15 sec ])

You don't sleep an analog pin, you sleep the CPU. Given your current understanding level, you should really forget about your project for now and focus on learning the basics. Then go through tutorials about sleep mode and interrupts. If you get stuck on your learning process, you can use this site to ask focused questions. Once (and only once) you are comfortable with all that material, you can come back to your original project. You want to run an obstacle course: you should first learn to walk.

How would I use interrupts (timer, pin change interrupt?) for an analog pin that triggers when the vibration sensor is triggered, resulting in other components operating?

Thee best and most authoritative answer to that and all your other questions about the chip can be found in thee device data sheet and the compiler manual. Read them thoroughly and then write code to the data sheet to experiment.
Your can fire example have an analog interrupt where the chip constantly does ADC on the pin attached to the sensor and you can test the value of the ADC to see if certain trigger conditions are met and take appropriate actions.
The same with timers, etc. The data sheet is your best friend.


text:
Powering Arduino through 12V USB communication unstable
When powering Arduino through Japan Jack at 12V USB communication becomes unstable and frequently interrupts/disconnects. Using Arduino Uno R3 and Linux on the connected computer.
Does anyone have any insight why this might be happening?

This is a guess but since 12V is at the upper edge of what the board can accept over its jack is your PSU stable?  If it isn't your regulator should heat up.  You could measure this by monitoring the output from the VIN pin (apparently its bidirectional).
This link might help https://www.open-electronics.org/the-power-of-arduino-this-unknown/

@Matt can you point me to where they say this? according to the arduino page 12V is the upper limit of the recommended voltages, but it can work up to 20V (in fact, the regulator has a maximum voltage of 20V, but there is also a diode). So... Why 12V is the maximum?

@frarugi87 the effective limit is not the maximum voltage the regulator can accept when supplying tiny currents, but rather the voltage at which the heat produced by the difference between accepting power to satisfy the actually needed current at a high voltage and emitting only a much smaller amount of power at a low voltage, is more than can be removed from the device while it remains at an appropriate temperature.  So the actual voltage limit depends on current draw and cooling situation.

@Matt ok, so 12V is not the limit of what the board can accept. According to this blog, the uno draws 46.5mA when no load is present. The datasheet says that with a 1cm*1cm copper pad, the 1117 has a thermal resistance of around 100°C/W, thus saying that 1.2W can be safely dissipated without triggering the thermal protection. At 46.5mA and 20V the 1117 dissipates only 0.7W, so it is perfectly safe to give 20V to a board without external loads. The 1117 can deliver up to 1A, thus leaving about 950mA of loads applicable... continue

So when you have 950mA of current absorption (from the 5V) 1.2W mean that you can have at most a 6.2V voltage on the input of the regulator (about 7V on the input pin, since there is a diode). I'm not saying that you can power everything, I'm saying that claiming that 12V is at the edge of the board voltages is wrong, since it only depends on how much current you are drawing (up to 30mA of current draw even 20V are fine)

Could it be possible that it is related to disconnected grounds.  I originally assumed that the 12V supply and the computer share a common ground via the same mains circuit.  Is that the case?  Also is there a reason you are supplying 12V?  What is the current draw of your connected items?

@frarugi87 - I got the 12V from the link in the comment and also https://www.arduino.cc/en/Main/ArduinoBoardUno.  Yes you can supply up to 20V, but the recommended is 12V.  I'd just assumed it was recommended for a reason. If the 1117 can dissipate the heat from an unloaded board with a 20V supply, how much load would the board need for it to generate 1.2+W with a 12V supply?  I think you are right its unlikely to be a heat issue and unless the PSU is seriously flaky then its unlikely to be an issue with unstable voltages.

12V is a little on the high end for what the arduino can handle by itself. If I were you I would use a DC step down Buck Converter module to hold the voltage at somewhere around 6v.
http://www.ebay.com/itm/like/400673913185?lpid=82&chn=ps
They're super cheap and pretty easy to use. Simply solder the + and - leads from your 12v power supply to the +in and -in on the buck converter. Then the + out and -out to the + and - for your arduino. Turn the potentiometer until you get somewhere around 6V.
Edit:
Actually I was just reading online, and some people have trouble communicating with the arduino through USB while an external power source is connected. Internet says this problem is related to sharing voltages.
https://forum.arduino.cc/index.php?topic=194598.0

I disagree. According to the arduino page 12V is the upper limit of the recommended voltages, but it can work up to 20V (in fact, the regulator has a maximum voltage of 20V, but there is also a diode). So 12V is perfectly fine. 6V, on the other hand, is undervoltage: dropout of the regulator is around 1V, the diode has a 0.6V dropout, so the minimum voltage should be around 6.6V...

The thoughts are not bad in the general sense, but unlikely to be related to the observed problem.  Setting the output to 6v however is erroneous advice - the Arduino's on-board regulator needs a higher input voltage that than, while 6v is too high to safely bypass the on-board regulator.


text:
How to handle low temperatures using Arduino Uno?
I want to create a simple electronic temperature sensor using the Arduino Uno.
The environments I want it to handle is inside a fridge and near a heater.
Although I am sure the Arduino can easily handle a heater; my issue is that the Arduino may not be able to handle a fridge.
A fridge also has the added problem of causing water vapor (and we all know water + electronics is never a good idea).
So my question is:

How would I create a temperature sensor using my Arduino Uno, that I can put in my fridge?
Are there any other problems I have not considered and how do I solve them?
Will I need a special type of casing? If so, which type?
Is an Arduino Uno even the best tool for this task?

Condensation is mostly a problem when you take the cold Arduino out of the fridge, into the warm room. Putting the entire project into a ziplock bag is probably sufficient protection.

Your Arduino does not have to be in the fridge, just the sensor. You can always choose waterproof sensor like this one to use with the arduino. Then you can always store your arduino outside the fridge. Same goes for the heater. Try to keep the arduino at room temperatures to avoid decreasing its life unnecessarily.
As for an actual answer to the temperature ranges, here is a good answer

That makes sense, but I kinda want the entire object in the fridge for my specific use case. The reason being is that I'm making a game, where the player is tasked to put this cube (i.e. a packaged arduino) in different temperatures (although the player of course doesn't know that). If the correct temperature is found it does something (like open a door via wifi).

in that case you just need an airtight box (look up one on google). Any box will do, like the food boxes. You can also drill holes for probes and seal them with silicon. here is a commercial box

My other issue is ensuring enough ventilation. Wouldn't a airtight box cause humidity?

Regarding moisture you could use a moisture absorbing package (e.g. filled with salt or some silicate).

like @LStrike said, use a moisture absorbing package to absorb the moisture already in the box. Since it is airtight moisture from the fridge will not get in. The component on the board in your case do not need any special cooling, especially in such a cold environment.

Humidity would be your biggest enemy. The fridge is a very moist environment for two reasons:

The colder the air temperature, the less moisture it can hold overall, thus saturating more quickly and reaching a higher relative humidity.
Lots of moist foodstuffs in an enclosed space.

You should be OK as long as the enclosure you choose has plenty of ventilation to avoid a temperature differential or trapping moisture.  Either of those two conditions could cause and even larger increase in humidity or, worse, condensate to form.

But how can I ensure I have a container that is both waterproof and enough ventilation

You don't need a waterproof case unless you plan on submerging the Uno in water as well.


text:
Arduino Saint Smart Chapter 7 Tri Color Module
I am very new to Arduino, I bought a starter's kit and I am working with the user manual that is available. I am in chapter 6 Tri Color Module
I am using the following code:
// Defining the LED driver pins and some other
// variables.
const int numLEDs = 3;

int blueLEDPin  = 3;
int greenLEDPin = 4;
int redLEDPin   = 5;
int ledPin[3];
int ledPinIndex = 0;

// the setup routine runs once when you press reset:
void setup() {

  Serial.begin(9600);

  // initialize the digital pin as an output.
  ledPin[0] = blueLEDPin;
  ledPin[1] = greenLEDPin;
  ledPin[2] = redLEDPin;

  for (int i=0; i < numLEDs; i++)
     pinMode(i, OUTPUT);

}

// the loop routine runs over and over again forever:
void loop() {

  digitalWrite(ledPin[ledPinIndex%numLEDs], HIGH);
  delay(1000);
  Serial.println(ledPinIndex%numLEDs);
  delay(2000);
  digitalWrite(ledPin[ledPinIndex%numLEDs], LOW);

  ledPinIndex++;
}

My problem is that in the setup() method where the following code is
for (int i=0; i < numLEDs; i++)
         pinMode(i, OUTPUT);

From my understanding pinMode OUTPUT is use to send power out of the specific pin. As the code displays pin 3, 4, and 5 are used but the above code is setting pinMode for 0, 1, 2. Is this write? And even if I comment out the two lines up my project no differently as to the previous code.
Can someone verify if the above code is correct, or should it be setting pinMode for 3, 4, and 5.

This code is broken.  Like a lot of cheap import electronics, it shipped "only half finished"  There can still be value if you know what you are getting and are ready to do what was left out, or plan to use things in a different way anyway.

This line pinMode(i, OUTPUT); should probably be replaced by pinMode(ledPin[i], OUTPUT);
Otherwise it won't make sense.


text:
For loop broken?
This is a pseudo code from my LED cube project
void loop(){
  //switch( map(constrain(analogRead(pt),10,1020),10,1020,1,4));  - for select pattern
  //show(1);
 for(lp=128;lp>=1;lp = lp/2){
  runfor(1000,lp,1,0,0,0,0);
  //Serial.println("HI");
 }
}

void runfor(short mills,byte a,byte b,byte c,byte d,byte e,byte f){
  timer = millis();
  Serial.println(a);
  while((millis()-timer)<=mills){
    light_L1(a,b);
    //light_L2(c,d);
    //light_L3(e,f);
  }
}

the variable 'lp' here never changes its value and remains 128
Why is this?

What makes you believe lp does not change?

Tested using serial.println, second line in the runfor()

I run it. no surprise. the value changes as expected.

@Juraj Is this a problem with my chip or IDE then?

no. it is a problem of your snippet. it makes something else like the sketch from which you extracted it and didn't test

So maybe another function is affecting it?

Let us continue this discussion in chat.

Don't ever use a global variable for for loop.
You use the same variable in functions for loops which count down to zero. If lp is zero for loop in loop() ends and new loop() starts.

When I ran your code as you presented it in the chat, lp stayed at 128. When I commented-out the "light_L1()" call in "runfor()", lp decremented by 1/2 its value per step as you would expect. The issue is that lp is global and therefore, accessible by any other function. One of your lower functions is resetting it.

so I induced the asker to post the code and the problem showed itself. but you didn't explain why the value jumps to 128

The value changes because one of the lower functions changes it. Why didn't I continue to debug it down to the last detail? 1) To not steal a potential learning experience from the OP; and 2) because it really doesn't matter to the question: "the variable 'lp' here never changes its value and remains 128  Why is this?". I pointed the overall problem - modification of a global from multiple places in the code. The rest is up the OP, who can ask for further help if s/he wants it.


text:
Programming an Arduino over the air using an ESP8266
This question stems from this article (Originally in Spanish/English) which Hack a Day summarizes (Includes link to partial English translation). These articles show that it is possible to update an Arduino Uno via an ESP8266 over WiFi.
I've modified the code so that when I hit the reset button on the Arduino connects to an "Update" server via the ESP8266, configured in "transparent" mode, to check for an update. If one is present the ESP8266 updates the Arduino which reboots itself. If there isn't an update I reset the ESP8266 and quickly tell it to drop any connection before it can reconnect to the "Update" server thus allowing me to connect to a "Logging" server instead for normal operation.
There is a slight difference in how one connects. The "Update" server is connected with the ESP8266 in "transparent" mode. While connecting to the "Logging" server the ESP8266 is in "normal" mode.
At present I have wired an additional connection to the reset pin of the ESP8266. Whenever it doesn't do what I want it to do I drop the power on the reset pin, confuse it and Zap in a command before it's managed to re-establish any "transparent" connection. This works but seems a little like black magic.
I was curios to know if there is a better way to force the ESP8266 out of "transparent" mode.
Note: I have not flashed the ESP8266 with NodeMCU/ESPLink or some other firmware.
Aside: There is an ESP8266 Arduino Core library does this also flash the ESP8266 in a manner similar to NodeMCU/ESPLink or does this run on the Arduino and facilitate over the air updates using the native firmware as I am trying to do ? I've only just started reading their documentation. (As this is a first post I've run out of links to share)

I think you should consider using ESP-LINK

@NccWarp9 I'll do so the next time I try this. For this project the main communication module is actually a GSM unit and I was using the ESP8266 simply for eavesdropping/debugging purposes. I am still curious to know what the proper procedure is. I've had to do something similar before and no doubt I'll have to do so again. It feels hacky to simply drop the power on the ESP and I am just curious to find a better/best practice.


text:
Chat between Xbee and Arduino
I'm very new with this devices so I'm a bit confused. I've got two Xbee modules series 1 and an Arduino UNO. I want to make like a chat between the two Xbee modules, one of them connected to the PC through a Xbee Explorer USB and the other one assembled in the Arduino Board through a shield.
I've configured the two Xbee modules with the same PAN ID and Channel, and the Xbee module 1 has MY = 0 and DL = 1 and the Xbee module 2 has MY = 1 and DL =0.
I've connected the Xbee module 1 to the PC through the Explorer and the Xbee module 2 connected to the PC through Ardunino+Shield.
I've uploaded the following code to Arduino:

#include <SoftwareSerial.h>

SoftwareSerial mySerial(4, 5); // RX, TX

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

  Serial.println("Goodnight moon!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  mySerial.println("Hello, world?");
}

void loop() { // run over and over
  if (mySerial.available()) {
    Serial.write(mySerial.read());
  }
  if (Serial.available()) {
    mySerial.write(Serial.read());
  }
}

In my shield the jumper of the RX digital is the 4th pin and the TX jumper in the 5th pin.
When I open the serial monitor window I get the message "Goodnight moon!" but when I send a message from the XCTU console or from the serial window I don't get that message in the other interface (XCTU console or serial monitor window).
In the shield (this one http://www.seeedstudio.com/wiki/XBee_Shield_V2.0) I've 4 leds: first one (power) is on, the second one (signal strength) is off, the third one (association) blinks all the time, and the fourth one (on/sleep) is on.
Why I don't get the messages like a chat? What am I missing?
Thank you!!

Are both Xbees in AT mode (instead of API mode)? Do both have a baud rate of 9600?

Yes, they are in AT mode and 9600 baud rate

Did you try switching rx and tx pins mySerial(5, 4);? Are they in broadcast mode? What is the led flash rate of each?


text:
I have cooked 3 regulators applying 12 V to RAW pin. Am I doing something wrong or did I get a bad batch?
I'm trying to make a simple keypad lock that has a 12 V magnetic lock.  I supplied 12 V to the RAW pin on the Pro Mini with plans to actuate the relay with the 5 V from VCC pin.  The lock was grounded on the terminal strip that the 12 V came from, and then the positive 12 V was switched through the relay.
Everything was working well until I powered the board through the RAW pin with 12 V.  When I did that all three failed the smoke test.
My question is, am I doing something incorrectly or did I happen to get a bad batch (all three of the boards came in the same shipment, I assume they came from the same lot)?

Can you post your circuit diagram?

And part numbers of your regulators.  What current is involved?

do you have common grounds?

The Pro Mini's 5V regulator (MIC5205) can supply a maximum of 150 mA, from which the Pro Mini uses about 20 mA, leaving around 130 mA for other applications.

Check the data sheet of the relay, to get the maximum current draw. For example, the RWH-SH-105D relay requires around 70 mA in the "on" position. While this is under the 130mA limit, you may be using other IOs or powering other modules.
To reduce the current draw, use a transistor to drive the relay like this:

Correct analysis of the problem (or at least one of them), but your solution has a bit of an issue in that it is for a relay with a 12v coil, while the poster appears to have one with a 5v coil.  So the poster will need a different relay, to find a high current regulator to power it, or perhaps to play very carefully calculated games with a power resistor in series with the relay coil.  Alternately, they may be able to use a much better transistor than the 2N3904 or perhaps a power NFET, and drive the lock solenoid directly.

A magnetic lock will be based on a solenoid, which will probably draw quite a high current from the 12 V rail. When that load is switched, a voltage spike will appear into the 12V rail due to the inductance of the supply wires. The longer the wires and the higher the current, the bigger the voltage spike.

simulate this circuit – Schematic created using CircuitLab
If the spike goes above 20V (and it can easily happen, believe me) then it will exceed the maximum rating of the MIC5205 voltage regulator and fry it unless you prevent that with some extra components. The voltage rating of the regulator input capacitor in the Pro Mini probably isn't up to the task of handling 20+ V spikes either and may be getting damaged too.
Note that the Pro Mini is specified to work with input voltages only up to 12 V, so you are operating it with no margin whatsoever! You should consider reducing that voltage in first place. You could use a DC/DC converter module to step down the 12V to a more suitable 7V and provide isolation from the spikes at the same time.
Apart from that, consider using a transient voltage suppressor (TVS or transzorb diode) and/or a large decoupling capacitor (with an adequate voltage rating) as close as possible to the input of the Pro Mini or the DC/DC converter (if you use one). You might want to try decoupling your magnetic lock with a properly selected capacitor as well.

Bonus: thermal considerations
Thermal issues shouldn't be the main culprit here, but be aware that the tiny MIC5205 can get extremely hot and enter thermal shutdown mode when operated at 12 V input voltage.
The junction to ambient thermal resistance of the regulator is 220 C/W. Its maximum operating junction temperature is 125 C. At 25 C ambient temperature that means the maximum allowable temperature rise is 100 C and the maximum allowable power dissipation is 455 mW. Because the regulator is dropping 7V, the maximum allowable current will be only 65 mA (instead of the 150 mA max that the MIC5205 can source in more favorable conditions). The consumption of the Pro Mini is around 20 mA, so that leaves you with only 45 mA for your application. You should consider whether this is enough for your application or not (some 5V relays draw around 80 mA, which will greatly exceed this 45 mA calculated limit, when connected to the VCC pin of the Pro Mini).


text:
Measuring voltage from -12 to +12 VDC
I'm making a -12 to +12V DC regulated power supply, on which I want to measure voltage and current with Arduino (through a voltage divider, of course).
I'm not sure, how to either detect nor measure negative voltage. I could "detect" it via a Schottky diode, but I'd get about 0.3V voltage drop, but that's not what I want, because any voltage between 0.0V and -0.3V wouldn't be measured. I want also to be able to measure positive and negative voltage on the same Arduino analog input pin.
And furthermore, how to measure current, flowing into both ways? (not an AC current, but will change during operation).
I will make additional PCB for this application, so size and number of components isn't important at all.

What magnitude of current do you need to measure?  Microamps?  Amps?

We're discussing range from 0 to 5A, I'd really like to measure it on at least 2 digits, while measuring amperes, and if the current would be <1A, I'd like to show it in miliAmps.

Measuring voltage
Use the following interfacing circuit for measuring voltage:

Resistors R1, R2, R3 (1% tolerance or better recommended) will map the voltage input range (-12 to +12V DC) to an output range that can be read will the Arduino ADC  (+0.5 to +4.5V DC, in order to have some slack from the top and bottom end of the ADC range). The actual theoretical input range would be -15 to 15V DC.
The optional (but recommended) Schottky diodes D1 and D2 will protect the Arduino analog IN pin that you connect to Vout from any input under/overvoltage outside the -15 to +15V DC range.
This is the resulting input to output voltage translation curve:

Measuring current
For measuring current, use a current shunt (i.e., a very low resistance resistor, in the milliohm range) and measure the voltage drop on it via a high input impedance differential amplifier, then sample the output of the amp with the Arduino ADC.

simulate this circuit – Schematic created using CircuitLab
Follow this link to an article in EE Times to learn more about the main options available for current measurements using a shunt.

The Schottky diodes have too much leakage current, the measured voltage will be less accurate. It is better to use 1N4148 diodes with a extra resistor to the Arduino pin (100 ohm to 1k). The diodes are probably not needed at all, since it is allowed to push 1mA into a pin or pull 1mA from a pin. It is therefor safe to apply larger voltages than -15 or 15v.

With only those three resistors with those values (20k, 6.65k, 10k) the input may be +/- 40V.

I have already selected the values of R1, R2 and R3 so that the leakage of the 1N5819 doesn't distort the measurement. The simulated curve reflects that. The diodes are optional and are there just for protection purposes, it's up to the OP to get rid of them, as I said myself.

@Jot I don't get your point.

The leakage of the 1N5919 is very unpredictable, what if one is close to a voltage regulator that is very hot ? The leakage could be 0.1 to 10mA.

My leakage numbers are wrong, I found graph in the ST datasheet. The typical leakage according to that graph are can be 1µA to 0.3mA (at 100°C).

@Jot I'm happy you finally got your numbers right.

@EnricBlanco: That's just perfect, thank you for the reply!
I just can't figure out, what actually means Vin, Vout and VS. I mean, I know that Vin stands for Input voltage, Vout for output voltage, but what am I supposed to connect to those pins? Which voltage to be accurate?

Connectivity: Vin -> the -12/12V voltage you want to measure; Vs -> 5V from Arduino of from a stable, accurate voltage reference; Vout -> any analog input from Arduino.

@EnricBlanco: Thank you thank you THANK YOU!!!


text:
On extending scrolling 8x8 bitmap to 32x32 or 32x64 (see clip)
I am using an Adafruit 64x32 RGB LED panel with my Arduino Mega 2560. I tried to find/construct working examples of a 32x32 or wider scrolling text/bitmap but have failed.
The smaller version is working and is calling two functions for it to implement:
loadSprite(IMAGES2,60);
bildmittig_sprite(data,dpink,300);

IMAGES2 is of type const PROGMEM byte IMAGES2[][8] and is an array
of several 8x8 bitmaps
data is a buffer data array element,    containing the dynamic
movement of bitmaps, called in the void loop()

For the whole code here. For the video clip smaller scroller here.
For the video clip to what I would like to extend to:

 Russian Letters: http://dropbox.com/s/n2ilxqgubn83ii9/MOV_0056.mp4?dl=0
 Or Chinese Letters: http://dropbox.com/s/9rad116adc575u1/MOV_0057.mp4?dl=0

loadSprite() looks like this:
void loadSprite(const PROGMEM byte bild[][8],int anzahl) {
  for(int row=0; row < 8; row++) {
    //iterate through each row
    data[row] = 0;
    //reset the row we're working on
    for(int column=0; column < 8; column++) {
      //iterate through each column
      data[row] = data[row] + ((powers[column] & (pgm_read_byte(&(bild[index][row])) << offset)));
      //loads the current charachter offset by offset pixels
      data[row] = data[row] + (powers[column] & (pgm_read_byte(&(bild[index+1][row])) >> (8-offset)));
      //loads the next charachter offset by offset pixels
    }
  }
  offset++;
  //increment the offset by one row
  if(offset==8){offset = 0; index++; if(index==anzahl){index=0;}}
  //if offset is 8 load the next character pair for the next time through
}

The displaying function (places it i the middle of 32x32 panel) like this:
void bildmittig_sprite (byte bild[8],word cchsv, int duration) {
  for(int i = 0; i <8; i++) {
    for(int ii = 0; ii<8; ii++) {
      int bit = (bild[i] >> ii) & 1;
      if(bit == 0) {
        matrix.drawPixel(7-ii+12, 12+i, black);
      } else {
        matrix.drawPixel(7-ii+12, 12+i, cchsv);
      }
    }
  }
  delay(duration);
}

Working for 8x8 bitmaps, It eludes me how I could possible extend the coding (scrolling) for bitmaps like this:
const PROGMEM unsigned char rus5[] = {
  0x00, 0x00, 0x00, 0x00,
  0x00, 0x00, 0xff, 0x03,
  0x00, 0x00, 0x78, 0x00,
  0x00, 0x00, 0x38, 0x00,
  0x00, 0x00, 0x3c, 0x00,
  0x00, 0x00, 0x1c, 0x00,
  0x00, 0x00, 0x1c, 0x00,
  0x00, 0x00, 0x1e, 0x00,
  0x00, 0xfc, 0xde, 0x0f,
  0x00, 0x8f, 0xef, 0x1f,
  0x80, 0x07, 0x3f, 0x3c,
  0xc0, 0x03, 0x0f, 0x3c,
  0xe0, 0x01, 0x0f, 0x3c,
  0xe0, 0x01, 0x07, 0x3c,
  0xf0, 0x80, 0x07, 0x3c,
  0xf0, 0x80, 0x03, 0x3c,
  0x70, 0x80, 0x03, 0x1e,
  0x78, 0xc0, 0x03, 0x1e,
  0x78, 0xc0, 0x03, 0x0f,
  0x78, 0xe0, 0x01, 0x0f,
  0x78, 0xf0, 0x81, 0x07,
  0xf0, 0xf8, 0xc3, 0x03,
  0xf0, 0xef, 0xf6, 0x01,
  0xe0, 0xf7, 0x7c, 0x00,
  0x00, 0xf0, 0x00, 0x00,
  0x00, 0x70, 0x00, 0x00,
  0x00, 0x70, 0x00, 0x00,
  0x00, 0x78, 0x00, 0x00,
  0x00, 0x78, 0x00, 0x00,
  0x00, 0x7c, 0x00, 0x00,
  0x80, 0xff, 0x03, 0x00,
  0x00, 0x00, 0x00, 0x00
};

I tried variants of concatenation, like:

4 bytes as a row, stitching together several with beforehand created
data (data1 ... data4) elements (also adjust coherence for vertical elements).
And then have them displayed at the correct place to be able to use
the existing code but so far only vertical concatenation seemed to
work briefly.

I am at the end of my wits for this project, but maybe somebody else sees a better way.

I've looked at your code briefly, long enough to get the impression that each array like rus5[] contains 32 groups of 4 bytes each, with each 4-byte group representing a row of a character.  [If not, let me know.]  Also, I read the question a time or two, but don't see specified what direction you want to scroll, and whether you will scroll a string of characters or just one character.  Anyhow, in following I suppose you want to scroll a string horizontally with characters entering at the right end of the display and scrolling off the left end.
To support horizontal scrolling, arrange your bit maps such that each group of 4 bytes represents the 32 bits of a single column of the display.  Regarding four bytes as an unsigned long, suppose the LSB (least significant bit) corresponds to the top LED in a column.  Use code like the following to set pixels, supposing cn = current column number; d = number of character columns already scrolled off, in range 0 to 31; maxCol = number of display columns; and t[] is a three-character string corresponding to three characters currently on the 64x32 display.  [That is, a right-hand part of t[0] is at the left end of display; then all of t[1] appears; then a left-hand part of t[2].]  [Generally, where this sets cc=0, you would set it to point at a current-character in a longer string, instead of at the first character in a three-character array t[]; and would advance one character each time d gets up to 32.]
cc = 0;     // index of first character to display
c = t[cc];  // first character to display
e = d;      // how far we have scrolled so far
for (cn=0; cn<maxCol; ++cn) {
  unsigned long colData = pgm_read_dword(charData[c][e]);
  for (ro=0; ro<32; ++ro) {
    matrix.drawPixel(cn, ro, (colData&1)? cchsv : black);
    colData >>= 1; // discard used-up bit
  }
  ++e;
  if (e >= 32) {  // Done with current character?
    c = t[++cc];  // Set c to next character
    e = 0;        // Start with leftmost col of character
  }
}

Edit 1: In the code above, charData[c][e] is an unsigned long int.  Its 32 bits represent column e of ascii character c, with the LSB representing the top-row pixel.  To create charData[][], write a program on your development system that reads whatever bitmaps you have now and writes out code to properly set up charData[][] in ProgMem.
Note, for initial scroll-testing, you could skip writing a development-system program to re-orient characters and instead test with character-data arrays as they are.  Characters might display sideways or upside down, but would scroll ok anyway.  Or, if bytes are not in proper Endianness to be an unsigned long, they would display in four mis-ordered slices.
Edit 2 With the following code,
void  scroller (const PROGMEM byte bildo1[][4],const PROGMEM byte bildo2[][4],int maxCol, word cchsv) {

int d = 0;
int cc = 0;
unsigned long c[32];

for(int ii=0;ii<32;ii++) {
  c[ii]=0;
  c[ii] += (long) pgm_read_byte(&(bildo1[ii][0]))<< 24;
  c[ii] += (long) pgm_read_byte(&(bildo1[ii][1]))<< 16;
  c[ii] += (long) pgm_read_byte(&(bildo1[ii][2]))<< 8;
  c[ii] += (long) pgm_read_byte(&(bildo1[ii][3]));
}
int e = d;      // how far we have scrolled so far
for (int cn=0; cn<maxCol; ++cn) {
  unsigned long colData = c[e];
  for (int ro=0; ro<32; ++ro) {
    matrix.drawPixel(cn, ro, (colData&1)? cchsv : black);
    colData >>= 1; // discard used-up bit
  }
  ++e;
  if (e >= 32) {  // Done with current character?
    for(int ii=0;ii<32;ii++) {
      c[ii]=0;
      c[ii] += (long) pgm_read_byte(&(bildo2[ii][0]))<< 24;
      c[ii] += (long) pgm_read_byte(&(bildo2[ii][1]))<< 16;
      c[ii] += (long) pgm_read_byte(&(bildo2[ii][2]))<< 8;
      c[ii] += (long) pgm_read_byte(&(bildo2[ii][3]));
    }
    e = 0;        // Start with leftmost col of character
  }
}}

chrisoutwright reports getting an image like the following [cropped from a larger dropbox.com image]:

Cutting this into 4 equal-size horizontal slices and swapping slices top to bottom, we get:
That image suggests packing the bytes in reverse order, eg via
c[ii] += (long) pgm_read_byte(&(bildo2[ii][0]));
c[ii] += (long) pgm_read_byte(&(bildo2[ii][1]))<< 8;
c[ii] += (long) pgm_read_byte(&(bildo2[ii][2]))<< 16;
c[ii] += (long) pgm_read_byte(&(bildo2[ii][3]))<< 24;

Continuing on, if we rotate the left half of the above 90° then flip the rotated image left to right we get a reasonable facsimile of the letter 春 :

The "flip left to right" amounts to reading bits out MSB first instead of LSB first.  During testing, one might do that by saying
matrix.drawPixel(cn, ro, (colData&(1<<31))? cchsv : black); colData <<= 1;

instead of
matrix.drawPixel(cn, ro, (colData&1)? cchsv : black); colData >>= 1;

but in the longer run, a development-system program should be used to re-orient characters instead of using up MCU memory space and time for bitmap organizing.

To make the characters scroll, add a parameter (eg, byte escroll) to the calling sequence.  Discard variable d if it isn't used within scroller, and instead of initializing e to d (which is always zero hence does not allow for scrolling) initialize it via
e = escroll;

In the routine that calls scroller(), say something like
byte es=0;
while (scrolling) {
  scroller(bildo1, bildo2, maxCol, cchsv, es);
  delay(msPerScrollStep);
  ++es;
  if (es >= 32) {
    es = 0;
    // do stuff here about next characters to display
  }
}

That is, call scroller() within a scroll-timing loop (or perhaps put the timing into scroller(), whichever meshes better with overall design).
Note, with the code as it stands, plus suggested changes, bildo2 will scroll in a second time1 unless a third character is supplied to scroll in.
1For example, with maxCol of 64, if es is 16, whenscroller() is called, e will go from 16 to 31 displaying the second half of bildo1, then from 0 to 31 displaying all of bildo2, then from 0 to 15 displaying the front half of bildo2.

I have taken a brief look at the code above. How is charData[c][e] defined exactly?
Also is it true that one would not see a combination of "bitmaps" with the code above, as the column-scanning needs finishing the first letter?
Nevertheless I will have a go with it as soon as I am at the working table.
Thank you very much so far jwpat7

@chrisoutwright, see edit 1.   The code shown displays characters adjacently as it scrolls them across, so portions of first and third characters show up, plus all of the middle, 1-2-3 left to right.  If you need a blank column between chars, do that within the “Done with current character” section.

at jwpat7, would you mind to integrate the code into a callable function?
I tried it myself but am getting invalid types when trying to obviate the charData[c][e] step (can I use a pointer variable to store rus5[]  and others together to get something like the mentioned  t[cc] ?)

I suppose, for testing purposes only testing two bitmap[32][4], such a function  would not work?

In that code the type of c[][] isn't shown, but probably should instead be unsigned long c[32], with the loop that loads c something like for(int j=0; j<32; ++j) { c[j]=0;     for(int i=0; i<4; ++i) {                               c[j] = (c[j]<<8) | pgm_read_byte(&(bildo1[j][i]));}} (if I correctly understand bildo1) and if an endianness problem occurs, try bildo1[j][4-i] instead.

I have re-uploaded another version of the code in the link above.
Now the letter 春 (being used twice and rotated is from my side), looks like this, with no scrolling sadly. What did happen exactly?

thank you for the excellent explanation in the edit2. Apart from the flipping matrix.drawPixel(cn, ro, (colData&(1<<31))? cchsv : black); colData <<= 1; The scrolling works now. Only the speed is a bit slow, (end-version) when the delay is set to minimum, it might be because of the many loops or else.

I finished to soon my scrolling test. In this Version the scrolling is stopped intentionally at 32 (so one letter) everything beyond, the output is jumbled till the beginning cycle. Any ideas on how to remedy that last bit? I think speed issues arise naturally in this sort of programming.

Let us continue this discussion in chat.


text:
Servo motors not working when called upon using I2C
So I'm using this movement() function inside the slave Arduino Uno, which basically handles two stepper motors and one servo motor. When I call this function through the Serial.read() of the Arduino Uno, it works perfectly, both the steppers and the servo.
I have a master Arduino Mega interfaced with the Uno (mentioned above) when I send a wire message from the Mega to Arduino to run the movement() function in the Uno, the steppers work fine, but the servo does not work. Although, again I mention that when the function is called upon using the Serial.read() of the Uno, it works absolutely fine.
I'm using an Adafruit motor shield on the Arduino Uno as well.
OK so this is the Uno (slave code)
void setup() {
  servo1.attach(9);
  Serial.begin(9600);
  Wire.begin(5);
  Wire.onReceive(receiveEvent);
  Serial.begin(9600);
}

void loop() {
  //other stuff
}

void receiveEvent(int howMany) {
  while(Wire.available()) {
    char c = Wire.read();
    int From = Wire.read();
    int To = Wire.read();
    int x = 0;
    movement(From,To);
  }
}

int movement(int from,int to) {
  int X_From = from / 10;
  int X_To = to/10;
  int Y_From = from % 10;
  int Y_To = to % 10;
  /* First we have to get the motor position and move the motor to the from position */
  /* === START === */
  int diff_X = X_From - motor_X;
  int diff_Y = Y_From - motor_Y;
  int Y_Value = abs(diff_Y * Y_Steps);
  servoDown();
  if(diff_X != 0) {
    if(diff_X > 0) {
      /* Positive value means the X_Axis motor will move in the forward direction */
      int X_Value = abs(diff_X * X_Steps);
      X_Forward(X_Value);
    } else if(diff_X < 0) {
      /* Negative value means the X_Axis motor will move in the backward direction */
      int X_Value = abs(diff_X * 400);
      X_Backwards(X_Value);
    }
  }
  if(diff_Y != 0) {
    if(diff_Y > 0) {
      Y_Forward(Y_Value);
    } else if(diff_Y < 0) {
      Y_Backwards(Y_Value);
    }
  }
  Serial.println("Motor movement done");
  /* === END === */
  motor_X = X_From;
  motor_Y = Y_From;
  int diff_X_2 = X_To - motor_X;
  int diff_Y_2 = Y_To - motor_Y;
  int Y_Value2 = abs(diff_Y_2 * Y_Steps);
  servoUp();
  if(diff_X_2 != 0) {
    if(diff_X_2 > 0) {
      /* Positive value means the X_Axis motor will move in the forward direction */
      int X_Value2 = abs(diff_X_2 * X_Steps);
      X_Forward(X_Value2);
    } else if(diff_X_2 < 0) {
      /* Negative value means the X_Axis motor will move in the backward direction */
      int X_Value2 = abs(diff_X_2 * 400);
      X_Backwards(X_Value2);
    }
  }
  if(diff_Y_2 != 0) {
    if(diff_Y_2 > 0) {
      Y_Forward(Y_Value2);
    } else if(diff_Y_2 < 0) {
      Y_Backwards(Y_Value2);
    }
  }
  motor_X = X_To;
  motor_Y = Y_To;
  Serial.println("piece movement done");
  return 1;
}

void servoUp() {
  for (i = 100; i >= 0; i--) {
    servo1.write(i);
  }
}

void servoDown() {
  for (i = 0; i < 100; i++) {
    servo1.write(i);
  }
}

This is the master Mega Code:
void setup() {
  Wire.begin();
}

void loop() {
  //check if a condition appeared from sensor and then send the data to Uno to run the movement function through sendData()
  sendData(From,To);
}

void sendData(int From,int To) {
  Wire.beginTransmission(5);
  Wire.write('f');
  Wire.write(From);
  Wire.write(To);
  Wire.endTransmission();
}

Any suggestions what's wrong?

For the start - I am afraid, that you call the movement from interrupt, and so interrupts are disabled - so if movement uses interrupts, it is blocked. Next thing is, that I suppose the movement is running 'long time' as it manipulates some physical device (motor), which is slow compared to 16MHz of Uno. So you are blocking interrupt for 'long time', which is not good too. I suggest to have the From and To static volatile global (and some locking mechanizmus around to block concurent access) and use that from the loop where interrupts are enabled and not blocked.

Don't cross post questions.

If you are using Servo library, which uses timer (and so interrupts) for manipulating the servos then you may have the problem, that from loop it works (as interrrupts are enabled), but from interrupt (ISR) it does not work, because while serving interrupt (from I2C) all other interrupts are (temporary) disabled.
In receiveEvent() you are inside interrupt serving, so other interrupts are disabled and so anything, what depends on interrupts does not work, until you leave the function.
So it is the more probable cause, why your servo does not move, while called from receiveEvent(), while it moves, if called from loop()
And you wait inside the interrupt routine, until all Wire input is read fully and then while the (slow, as it probabely involves mechanical components like motors or servos) movement(from,to) ends (if it can even end with interrupts disabled).
The solution would be to do all movement(..) in the loop and int the receiveEvent() just store the already aviable values and put them into some static volatile variables, when transfer ends together with mark, that some change was done.
static volatile int from;
static volatile int to;
static volatile int changed;

void loop() {
int my_from,my_to;
  if (changed) {
     noInterrupts();  // critical, time-sensitive code here
       my_from=from;
       my_to=to;
       changed=0;
     interrupts(); // enable interrupts, so I2C, servo and such can work again
     movement(my_from,my_to);
  }
}
void receiveEvent(int howMany)
{
  if(Wire.available())
  {
    char c = Wire.read();
    from = readInteger();
    to = readInteger();
    changed = 1;
  }
}

Not totally perfect (mainly reading the Wire, which I would just tak as much as is ready to some buffer and decode it only when buffer is sufficiently full and syntactically correct, but if would make the idea here more complicated), but should work much better, than the current version.
Better version of `receiveEvent can look like this:
char buf[20];
int buf_pos;
void receiveEvent(int howMany)
{
  while (Wire.available()) {
    buf[buf_pos] = Wire.read();
    buf_pos++;
    if (buf[0] == 'f') { // starts with known command
      if (buf_pos>= sizeof(char)+2*sizeof(int)) { // have all data already collected
        from=0;
        for (i=0;i<sizeof(int);i++) from=from<<8+buf[sizeof(char)+i];
        to=0;
        for (i=0;i<sizeof(int);i++) to=to<<8+buf[sizeof(char)+sizeof(int)+i];
        changed = 1;
        buf_pos=0;
        } // end of buf_pos>= ...
     } else { // not started with 'f' (or anything it should know) - throw all transfer away as bad
        while (Wire.available()) Wire.read();
        buf_pos = 0;
     }
}

This is exactly what I did to resolve the problem earlier. Great!!

I don't know if this is the whole problem, but if you call sendData (0, 270) you are only going to send 3 bytes to the Uno 0x66, 0x00, 0x01.  You should be sending 5, 0x66, 0x00, 0x00, 0x01, 0x0E
The Uno only reads three bytes and receives:
    c = 0x66;  // 'f'
    From = 0x00; // 0
    To = 0x01; // 1
This is because Wire.write() and Wire.read() send/read a single byte (when you call them like this).  What you need is:
void sendData(int from, int to)
{
    Wire.beginTransmission(5);
    Wire.write('f');
    Wire.write(&from, sizeof(int));  // Write an array of 'size of int' bytes
    Wire.write(&to, sizeof(int));
    Wire.endTransmission();
}

int readInteger (void)
{
    int result= 0;
    for (int byte = 0; byte < sizeof(int); byte++)
    {
       result = result << 8;  // Left shift the current data (multiply by 2^8)
       result += Wire.read(); // Add the next byte as the LSB
    }
    return result;
}
void receiveEvent(int howMany)
{
  while(Wire.available())
  {
    char c = Wire.read();
    int from = readInteger();
    int to = readInteger();
    int To = Wire.read();
    movement (from, to);
  }
}

This code sends and receives the complete integers, so it should work.
Sorry I can't compile it, but I think its right.

Oh and like I said this probably isn't the only problem, I don't think you should read all this data from the I2C bus with a blocking loop in you interrupt handler.  And The interrupt should tell the running code (non-ISR) to do the movement by setting a static flag, rather than doing it itself.

Reading the data isn't the problem really, I'm receiving the data accurately. But the thing that I cant figure  out is, during the movement function the steppers work fine, but the servo isnot working. That is the main problem. I've Serial.print out the data received and it looks accurate

It you can read the data you must be using angles less than 256.

No worries I've resolved the problem now

good to hear, please share your solution as example for others solving similar problem, who find this question in future :)

authors: นายประสาน ภัทรประสงค์


text:
Arduino IDE: Board nodemcuv2 (platform esp8266, package esp8266) is unknown
I am receiving this error after reinstalling Arduino IDE (everything was working fine [same components, same code]):

Board nodemcuv2 (platform esp8266, package esp8266) is unknown

I have recently reinstalled ESP8266 libraries. Could that have caused this issue?

Did some digging and found a solution that worked for me:
Uninstall (by logically deleting folders) and reinstall ESP Libraries.
Open Arduino IDE
Go to FILE -> PREFERENCES

Open the preferences folder (this works in Linux, Mac and Windows)
Go to PACKAGES > ESP8266 > HARDWARE > ESP8266

Delete all libraries (if your issue is similar to mine and to others', you should have 2 or more folders, with different versions).
Restart Arduino IDE.
Go to SKETCH > INCLUDE LIBRARY > MANAGE LIBRARIES
Install ESP8266 Community
Go to TOOLS > BOARD and scroll down to your model of NODEMCU
Run compile and your problem should be fixed.

Good work finding a solution and answering your question! I feel like this wording: "Delete all libraries" could be confusing. I'm not sure if maybe it's common to call folders "libraries" but in the context of Arduino, where the term has a specific meaning which is not applicable here, I think it would be better to instead say "Delete all folders".

FYI,  it should not be necessary to delete both version folders. The problem is caused by the Arduino IDE not completely removing the previous version when you update to a different one so you could just delete the previous version's folder only, which saves you from having to do the reinstall step. However, your instructions work fine to solve the problem.

i tried deleting just the oldest, but it did not work.  You are correct: delete all libraries in the ESP8266 folder.

Many thanks! In fact, my another computer and Mac does not show this and my working PC seems before was installed something causes this error. even though I un-install the arduino the problem still there. without your sharing I cannot fix it. thanks again!


text:
Why analogue pins affect each other?
I have a sensor and it generates an analogue signal.
I am reading all analogue data and sending it to my computer.

uint8_t sensors[] = { A0,A1,A2,A3,A4,A5,A6 };
const int len = sizeof(sensors) / sizeof(sensors[0]);
void loop(void)
{
    for (size_t i = 0; i < len; i++)
    {
        auto sensor = sensors[i];
        int sensorValue = analogRead(sensor);
        // Convert the analogue reading (which goes from 0 - 1023) to a voltage (0 - 5V):
        float voltage = sensorValue * (5.0 / 1023.0);
        char t[100];
        sprintf(t, "%d:%d$\n", sensor, sensorValue);
        uint8_t t1[100];
        //PrintSerial.println(t);
        memcpy(t1, t, 100);
        wifi.send(t1, strlen(t));
    }
    delay(300);
}

I plotted the analogue reading. Why does the graph look like this?

breadboards have a few puff of capacitance between rows

This is to be expected.
The other pins have nothing connected to it, so their voltage is floating.
The Arduino MCU only has a single ADC. To read the different analog pins, it uses a multiplexer to connect the pin you want to read to the single ADC. The ADC inside the MCU have a "sample and hold" capacitor inside it.
To read the voltage at the pin, it will connect the pin, to charge the sample and hold capacitor. It will then disconnect and measure the voltage of the sample and hold capacitor, one bit at a time.
So in your case, by reading the voltage at the connected pin, it will charge the capacitor. It will then read the unconnected pins. But because nothing is connected the sample and hold capacitor will stay at about the same voltage, because the unconnected pin will neither charge, nor discharge it.
Measuring the voltage on the sample and hold capacitor will slightly lower this voltage, so that's why in the graph the lines will be lower than the previous measurement.
PS Also, because all the pins are placed in a breadboard, you'll have some capacitive coupling between the adjacent pins.

So there is no problem?It wouldn't decrease the accuracy if there is another pin?

Not really. Unless the signal you are trying to read has a very high output impedance. You could connect the unused pins to ground, if you want to get a cleaner graph.

The acc is really a little capacitor. As you switch channels, the charges in the acc capacitor get carried from one input channel to the next. If the next input channel is of very high impedance, or very low capacitance, the charges on the acc capacitor dominate and its voltage changes little.
In addition, poor code can cause it too - usually from a lack of sufficient time for the add to complete.

You mean I need add a delay in for loop?


text:
Is it possible to make normal pins act like ground pins?
So what exactly I am trying to do is control a motor and be able to turn it both ways without any extra parts.
So if the hmp was on (the plus pole) and the hmm (the minus pole) acted like ground the motor should start turning right.
But if the hmp acted in this case as ground and the hmm like the plus pole it should start turning the other way.
I know that it's probably not going to work. I'm just experimenting.
int Hmp=12; // the plus pole
int Hmm=11; // the minus pole

while (HR=0 || Sr > Sl+300) {
  pinMode(Hmp, OUTPUT);
  digitalWrite(Hmp, HIGH);
  pinMode(Hmm, INPUT);
}

while (HR=1 || Sl > Sr+300) {
  pinMode(Hmp, INPUT);
  pinMode(Hmm, OUTPUT);
  digitalWrite(Hmm, HIGH);
}

"I know that it's probably not going to work." it will work. it is called low-side switching. most bi-directional motors are in part driven this way for example.

@dannyf - no, it won't work, and the user already stated that it did not work.  This is because while topologically similar to a half-bridge of power FETs, the output drivers on chip aren't up to the task of running a motor.  You've developed a very bad habit of posting throwaway incomplete and as a result at times misleading things like this, though fortunately at least this time you didn't abuse the answer form to do so.

No, it's not going to work - even worse, you risk frying your Arduino -, for the following reasons:

The Arduino data pins can't source (neither sink) enough current for that to work.
The inductive kickback of the motor could fry Arduino pins.

The right way to do what you want to do is using an H-bridge controlled by your Arduino data pins. There are lots of Motor Driver PCB modules for Arduino (most of them based on the inefficient L298 driver IC, which you should ignore and look instead on those based on the TB6612FNG driver IC or similar, because it would be a far better solution) that implement this function.

The L298 and L293 are very antiquated high-loss devices best avoided.  Especially in a battery powered application, one cell of the battery pack will go largely to feeding the losses of those driver chips, rather than turning the motor.  These really need to stop being mentioned by default - use an FET solution instead, for example the TB6612FNG replaces the L29x on better motor shields.

Thank you for your comment, @ChrisStratton. I agree with you and I'll update the answer accordingly.

I don't think that's going to work.
You'll be better off using a cheap module like the Pololu Pololu DRV8838 which implements a MOSFET H-bridge.
(Note: I'm not related in any way with Pololu.)

I just tried what you suggest, and it works fine, with only one (big)
caveat: you can only power this way very low power motors. I did this to
drive the linear motor that moves an HDD head assembly. This motor works
perfectly fine with less than 18 mA.
Note that I switch the Arduino pins between the HIGH and LOW states,
not going through INPUT. Setting the pin to INPUT would send the
motor's inductive kickback through the pin's protection diodes. On the
other hand, the inductance of this motor is presumably tiny...
For anything that can draw more than 40 mA, I would use an
H-bridge. For something between 20 and 40 mA, I may take the
risk of driving it directly if it's for an experiment where I am not
too much concerned about the risk of loosing my Arduino.

I just tried what you suggest, and it works fine,... It shouldn't surprise anyone that it worked. Because the structure of a typical GPIO pin is a h bridge or a low side switch. So it has to work. That's just basic electronics.

with only one (big) caveat... And that's no surprise as well. Whenever you drive a load, you have to understand its limitations. And in this case the limitation is severe in terms of drive current and drive voltage.

A big advantage is that those pins generally have clamping diodes. For inductive loads, they act as free wheeling diodes.

is it possible to make normal pins act like ground pins?

the answer is yes: i'm looking right now at a blinking led that straddles between two GPIOs with one of them permanently (via code) grounded so i can blink it via the other GPIO pin.
Obviously the usual limitations that apply to a GPIO pin apply here.

This is bad, bad advice. The LED you're looking at likely draws 30 mA maximum. Even a small DC motor will draw many times that amount, and far more than the GPIO pins can sink.


text:
Using voltage divider to read voltage from sensor
Good morning,
I would like to use an Arduino Duemilanove to read the voltage signal generated from a current sensor (CSLA2CD). The datasheet for this sensor can be found here.
The problem is that the sensor requires a supply voltage of 6 to 12v. The signal output voltage is half the supply when no current flows through the sensor. I am using a 8v regulator for its supply, so the signal voltage may range from 4v (no current sensed) all the way to about 6v (about 60 amps).
Unless I'm mistaken, the arduino's analog pin can detect from 0v to 5v. So it would only accurately provide me data up to the 5v signal mark.
My questions are:

Would a voltage divider be a good solution to reduce the signal voltage to a range the Arduino can read? If so,
what would be the best resistor combination to use?

If there are better solutions than a voltage divider then please share.
Thanks very much!

It should work, but I don't know if its the best way.
Because the maximum voltage is 12 volts (I know you are only giving it 8, but you don't want to fry your board) you need the divider to send the Arduino 5/12 of the power.  You don't need much current, so you can use big values or resistors.  10K and 24K should work, but you should research or test this before you hook it up to you kit.

Thank you for the quick reply!
The Arduino will never receive the full 12v  because i'm powering the sensor separately from the Arduino. The Arduino is only connected to the sensor via the analog pin and ground. The most voltage it would ever get into its analog pin would be 8v if there was a catastrophic failure with the sensor and it sent the full supply. That may still be enough to kill the pin, but probably not the whole Arduino, as far as I know.
So you're recommending that I test the system using 10K for R1 and 24K for R2? Just want to clarify.

@Andres: If you know for sure that the input voltage will never be more than 8 V, then you could use 10 kΩ between the sensor and the Arduino and 15 kΩ between the Arduino and ground. The Arduino will then read no more than 4.8 V.

Honeywell has also Current Sensors for 5V (the CSNX series). If you are only reading DC currents, then you can add a little capacitor parallel to the 15k resistor of about 10nF (1nF to 100nF) to reduce some noise. Do you have a modern 3.3V Arduino Due or do you really have a very old Duemilanove ? For the Duemilanove it is allowed to pull or push 1mA into a Arduino pin. That means with 10k and 15k the Arduino is protected for voltages from -10V to 19V. A voltage divider is accurate and works very well, anything else (for example OpAmps) would only introduce more inaccuracy.


text:
Can I share the VCC (5V) on my Arduino Pro mini with multiple modules?
Right now I am onto a new project where I am building an obstacle avoiding landrobot.
I use an arduino pro mini as my board and I have a few hc-sr04 sensors here at home. The problem I have right now is that many pins is occupied with other modules, motors and bluetooth.
So right now on my Pro Mini the VCC is occupied by my BLE device and I was wondering if there is a possibility to solder a few wires together so that my BLE device share the same VCC with 4 other hc-sr04 modules? I do this regularly with the GND where I solder multiple wires together and share the GND across different modules which works fine.
I have soldered a wire looking like this:

The idea is to power the arduino itself through the "RAW" pin. I have a power distribution board that connects to my battery/motor and the VIN pin of the PDB goes to the "RAW".
I try to avoid a breadboard to decrease the size as much as possible so if it were to be possible then that would be the optimal solution for this project.
Something I am also wondering is if it is possible to use these hc-sr04 on both the analog pins and also the digital pins. I do not have enough space to fit all the sensor cables on the digital pins but if I use the analog pins also then they all would fit. Is this possible? Each HC-sr04 has two cables that needs to be inserted (Trig and echo) and right now I have 3, 4 free and all the analog pins 0, 1, 2, 3, 4, 5 which is enough to fit them all.

You can indeed use analog pins as digital pins.

if your Vin=Vcc, then you can go up the supply's limit, if not, then limit it to the capabilities of your voltage regulator.

I use the "VCC" pin on the arduino pro mini to power the BLE and that is the pin i was thinking about sharing. I do not have a VIN on my arduino pro mini i think

This is how I will setup the entire project: I use a power distribution board that connects to my 4s lipo battery/motor. The GND of the power distribution goes to the GND and the VIN goes to the "RAW" of the arduino pro mini.

RAW is connected to the input to the regulator, whereas VCC is connected to its output. As a thumb of rule, you should connect your power source (battery, AC/DC adapter, whatever...) to RAW and then supply power through VCC to all the remaining modules (as long as maximum current output and power dissipation in the regulator are respected).

You mention motors. These typically consume a lot of power in comparison to the electronics in a project and it's not unusual to power them separately, as in this answer. That's where I would start, and then look at using on-board regulators on other boards, where available, as discussed in the answers to this question.

Yes, you can do that as long as the total current draw of the modules you attach to VCC doesn't exceed the on-board regulator maximum current output.
The Arduino Pro Mini has a MIC5205 regulator capable of delivering up to 150 mA, which is quite low if you plan to attach many modules to its output. So you should look through your modules datasheets and find out the total current draw, including the Pro Mini board itself, and check that against the 150 mA limit.
According to the HC-SR04 datasheet, each module draws 15 mA. The Arduino Pro Mini itself draws about about 20 mA. The BLE module peak current consumption is 12.5 mA at active RX and 11 mA at active TX, so lets say 25 mA peak current draw for the BLE module.
Everything adds up to a worst case 105 mA peak current draw, within the maximum 150 mA limit. So it should be fine, but I would avoid connecting much more modules to that VCC rail.

ADDED according to your additional question:
If you run out of digital I/O pins, you can use the analog pins as digital pins if needed.
Additional note (thanks go to @jwpat7 for pointing this out in the comments):
However, this is true only of A0–A5 on most Uno and Nano Micro Arduinos, and not true of A6, A7 (except on -PB MCU models like ATmega168PB and ATmega328PB, where A6, A7 can be used as digital pins).

Alright! I added a bit more info also if you missed it (in case it changes anything in your resonse).I use a power distribution board that connects to my lipo battery/motor. The GND of the power distribution goes to the GND and the VIN goes to the "RAW" of the arduino pro mini. So my lipo 4s will power the arduino pro mini itself

If i try it out, can it harm/damage the arduino pro mini/the other modules?

Avoid using the data pins as supply rails for your modules, at any cost. It may work but it's a bad idea.

what is a data pin? is that the "raw"?

@EnricBlanco: why is it a bad idea if it works?

@dandavis Because 1) it will increase power dissipation in the ATmega, 2) the supply current will be limited to 20 mA per pin, and 3) the output voltage of the pin isn't regulated and will drop with increasing load.

So just to confirm. This is the schematic (but I use a pro mini instead of uno) https://i.sstatic.net/tpb43.png so on Uno it is named "VIN" but on Arduino Pro Mini it is named "RAW" and that is where I insert it. Then I hook the BLE and all the hc-sr04 VCC/VIN to the VCC of the arduino pro mini that should land at 105mA peak as you mentioned above. Should work fine right?

Sorry, but I don't understand your diagram. What are the 4 ESC modules? How do the motors relate (connection-wise) to the arduino and its modules (including those ESCs), and how are the motors powered? Are you aware that switching high currents on/off (something that happens often when motors are involved) can induce high voltage spikes in shared power supply rails that can easiky fry regulators unless properly decoupled? Please understand that is unrealistic for you to expect that we can debug your entire project in the comments of a limited scope answer of a Q&A site.

I'm happy to keep helping, but it would be better to ask new focused and scope-limited questions as you come across new challenges and or doubts, instead of updating this post. That would be a better fit to the Q&A nature of this site, and will probably get you better overall answers and help.

Ok! I insert the lipo battery to the power distribution board and that powers both motors and the arduino. I succesfully make it work with a arduino uno so it should work with a arduino pro mini also i assume! :) Anyway aprpeciate your help a ton

If the Uno tolerated it then the Pro Mini should be fine as well.

I see a lot of demos powering LEDs (~2-15ma) from GPIO, and a lot of modules (ADCs, DHTs, etc) use less than 1ma; "at all cost" is too broad imho; follow the datasheets and you're fine.

@dandavis Fair enough. I agree that powering a LED from a GPIO should be fine because it's fairly tolerant to voltage as long as more than the forward voltage can be supplied and current is limited by a resistor. But I'll be very hesitant of connecting the power rail of any IC to a GPIO pin for a lot of reasons from noise to load effects. Of course, YMMV.

“If you run out of digital I/O pins, you can use the analog pins as digital pins if needed”,  is true only of A0–A5 on most Uno and Nano Micro Arduinos, and not true of A6, A7 [except on -PB MCU models like ATmega168PB and ATmega328PB, where A6, A7 can be used as digital pins]

@jwpat7 Thank you, I'll correct  that.

I connected everything now and powered up the arduino through USB and it seems to work well! :) The BLE is starting up and i seem to get results from all the hc-sr04 sensors. I will test it further tonight. Now it will be interesting to see if I can power up the arduino itself through the RAW via a lipo/power distribution setup!

To be frank you can use even your analog pins as digital pins as the analog pins are also digital pins but they are more enhanced
If you use a common Vcc you may not have enough power left for your board and when you share your ground it doesn't matter a lot as it is the -ve lead of your power  source and you may use an external power source

Ok. So sharing VCC can be problematic then but can work? If it doesnt work I assume breadboard is the only option left

I think it will not work

Of course! This one: https://learn.adafruit.com/getting-started-with-the-nrf8001-bluefruit-le-breakout/hooking-everything-up

I think it will not work as you have tied too many things to a Mini board You may use an external battery or power source

This is how I will setup the entire project: I use a power distribution board that connects to my lipo battery/motor. The GND of the power distribution goes to the GND and the VIN goes to the "RAW" of the arduino pro mini. On the "VCC" i have the BLE currently and that is where I also plan to put the hc-sr04 sensors

So the idea is that the lipo battery will power the arduino through the "RAW" pin

Yes you can but I prefer to use a lm805 ic

Sagnik Peadhan, regarding “you can use even your analog pins as digital pins as the analog pins are also digital pins”, see my comment to Enric Blanco's answer


text:
Using millis() function to start at potentiometer reading
I am trying to use the millis() function to start a countdown of 3 seconds when I turn my potentiometer to high travel. My code so far starts the timer at the beginning of the loop or when reset is hit or when the sketch is uploaded to the board. I need the countdown to start when the potentiometer reaches high travel.
The goal of the program is that when the potentiometer reaches high travel, PumpOne starts (HIGH) and if the potentiometer does not reach low travel before 3 seconds, PumpTwo will come on (HIGH). I am trying to simulate a water tank with two pumps (LEDs in this case) and the potentiometer high and low travel representing the high and low levels of the tank respectively.
I've updated the code since the original post but the timer still starts from the beginning of the program and not when L > Plim1.
Here's the code:
int Pump1 = 3; // Declare Blue LED in pin 3 to simulate Pump 1
int Pump2 = 4; // Declare Green LED in pin 4 to simulate Pump 2
int Alarm = 2; //Delcare Red LED in pin 2 to simulate Alarm
int TDCRPot = A0; // Declare Potentiometer(TDCRPot) an int and assign to pin A0

int L; //Declare L a variable to read the High and Low
//travel of the potentiometer

float Plim1 = 1000; // pot reading for pump 1 turn on
float Plim2 = 1000; // pot reading for pump 2 turn on
float Llim = 100; //pot reading to turn both pumps off
unsigned long T; // current time
unsigned long T1 = 0; // P1  on time
boolean P1 = false;
boolean P2 = false;
boolean Alarmstate = false;
unsigned long Tlim = 3000;

void setup() {
  Serial.begin(9600); //Turn on Serial monitor for troubleshooting
  //purposes and set to 9600 baud
  pinMode(Pump1, OUTPUT); //Declare Blue LED(PumpOne) an output
  pinMode(Pump2, OUTPUT); //Declare Green LED(PumpTwo) an output
  pinMode(Alarm, OUTPUT); //Declare Red LED(Alarm) an output
  pinMode(TDCRPot, INPUT); //Declare Potentiometer(TDCRPot) an input
}

void loop() {
  L = analogRead(TDCRPot); //Read the voltage from the Potentiometer pin
  if (!P1 && L > Plim1) {
    T = millis();
    digitalWrite(Pump1, !P1);
  }
  if (Pump1 != P1 && T - T1 > Tlim && L > Plim2) {
    digitalWrite(Pump2, !P2);
  }
  if (Pump1 != P1 && L < Llim ) {
    digitalWrite(Pump1, P1);
    digitalWrite(Pump2, P2);
  }
}

The statement TDCRLevel = analogRead(TDCRPot); will almost always set TDCRLevel to a non-zero value; hence the && TDCRLevel term of your last if statement almost always is satisfied.  The only time it won't be satisfied is when TDCRLevel is exactly zero.
When TDCRLevel >= 1000 is first satisfied, it's likely to be true for some while; during that time, each pass through loop() will toggle Bluestate and set previousMillisBlue = currentMillis.  This happens many times per millisecond while TDCRLevel has a high value.  Whether Bluestate is on or off when  TDCRLevel goes below 1000 is a fairly random outcome.
To handle the process properly, set up a state machine, using either one state-number variable or several variables to maintain state.  Change states when conditions tied to state, TDCRLevel, and time are met.
More simply, something like the following might work.
loop:
  if !P1 and L > Plim1:
    Set P1; record T1
  if P1 and T-T1 > Tlim and L > Plim2:
    Set P2
  if (P1 or P2) and L < Llim:
    Turn off pumps, clear P1 and P2

where P1, P2 represent pump states; T represents current time and T1 represents time that P1 most recently turned on; L = analogRead(TDCRPot); Plim1 and 2 are pot levels for pump turnons; Llim = low level for pump turnoffs; Tlim = desired time delay before pump 2 comes on.

Edit 1:  The above is pseudocode, rather than any simulacrum of valid C or C++.  As such, you may need to add sets of parentheses and brackets, substitute meaningful variable names, etc.
Note that the constants Plim1, Plim2, Tlim, Llim should be declared via either const int declarations, or via enum {} constructs (enum declares only integer constants), if they are integers rather than floats.  For example, do like either of
const int Plim1 = 1000; // level for pump1 turnon
const int Plim2 = 1000; // level for pump2 turnon
//etc

or
enum { Plim1=1000, Plim2=1000, Tlim=3000, Llim=100};

The phrase “Set P1; record T1” corresponds to code like
P1 = true;
digitalWrite(Pump1, HIGH);
T1 = millis();

in braces.  If you don't set P1 and record T1 as current time, the process won't work.  P1 and P2 represent state variables, not constants.
The phrase “if P1 and T-T1 > Tlim and L > Plim2: Set P2” corresponds to code like
if (P1 && (T - T1 > Tlim) && (L > Plim2)) {
  P2 = true;
  digitalWrite(Pump2, HIGH);
}

The phrase “if (P1 or P2) and L < Llim: Turn off pumps, clear P1 and P2” corresponds to code like
if((P1 || P2) && (L < Llim)) {
  P1 = P2 = false;
  digitalWrite(Pump1, LOW);
  digitalWrite(Pump2, LOW);
}

I've re-edited the question, The timer should start after Plim 1* but starts at the beginning of the sketch

@AbramsM101, see edit 1


text:
Best way to send text to ESP8266 remote display
I need a remote display to show information sent via WiFi from another ESP8266. What needs to be sent is a string along with some variables, for example a string to be displayed along with two integers for the position on the display:
0, 12, "message to display on screen"

As I am absolutely new to network stuff, what would be the best way to achieve this?

Sending a POST request through REST API?
Use UDP instead?
Or better use a framework like MQTT?

Define "best".  For example, easiest to implement?  Most reliable?  Most flexible?  Smallest code size?  Most easily extensible?  Easiest to expand?  Or, maybe you don't want best, but adequate..?  There are examples in the SDK of how to connect to wifi and send and receive data.

Try the esp8266 UDP messages
With UDP you can send and receive messages quite easily and without consuming lots of resources.

Thank you! I'll check back as soon as I've learned something about UDP.

UDP was exactly what I need.

I set up one esp8266 as an access point sending udp messages to multiple displays. The remote displays connect to the access point and then can receive whatever is sent. The displays are esp8266 devices as well. This works well and I can have multiple displays all listening to the same udp messages. This thread is pretty old but I would just lend support to the reply of using udp for a remote display. You will occasionally miss a message so that needs to be considered. In my testing it was rare, like maybe 1% of the time. If you must get the message there, another protocol might be more approp


text:
Why won't my iMac recognize my Mega32u4 Arduino Pro Micro board (I've tried several cables)?
I bought this Pro Micro on eBay a while back, and I never really got around to using it. But now that I do my iMac won't recognize the board. I plug it into my iMac and open Arduino and go to the board tab, and it doesn't even have a Pro Micro choice, so I just choose Micro.
In ports it isn't showing up like my other boards do. Is it my computer, because my Chinese clone Uno and Mega weren't being recognized a while ago? I downloaded the CH340 chip driver for them because they used the CH340 chip and now they are recognized and work perfectly!
The thing is the Pro Micro does not use that chip so is there something else I have to do like another driver to download? It is not the cable because I have tried 5 cables and some had the symbol with the circle triangle and square connected on them, which is the usb serial symbol I think, so they aren't just power cables. If anyone knows what the problem is, that would be awesome! Here is the error it gives me when I try to upload it.
 Arduino: 1.6.9 (Mac OS X), Board: "Arduino/Genuino Micro"

failed MSpanList_Insert 0x31dea0 0x29ab70fa1fa 0x0
fatal error: MSpanList_Insert

runtime stack:
runtime.MSpanList_Insert(0x2c70d0, 0x31dea0)
/usr/local/go/src/runtime/mheap.c:692 +0x8f
runtime.MHeap_Alloc(0x2c6d20, 0x6, 0x10000000034, 0xf989)
runtime.MCentral_CacheSpan(0x2d10d8, 0x30c270)
/usr/local/go/src/runtime/mcentral.c:85 +0x167
runtime.MCache_Refill(0x308000, 0xc200000034, 0x30c270)
/usr/local/go/src/runtime/mcache.c:90 +0xa0

 goroutine 1 [running]:
 runtime.switchtoM()
/usr/local/go/src/runtime/asm_amd64.s:198 fp=0xc2082b7468          sp=0xc2082b7460
 runtime.mallocgc(0x2200, 0x19ff80, 0x0, 0xc2080d68e9)
/usr/local/go/src/runtime/malloc.go:178 +0x849 fp=0xc2082b7518     sp=0xc2082b7468
 runtime.newarray(0x19ff80, 0x20, 0xa5ca)
/usr/local/go/src/runtime/malloc.go:365 +0xc1 fp=0xc2082b7550    sp=0xc2082b7518
 runtime.hashGrow(0x1b4300, 0xc2080dc150)
/usr/local/go/src/runtime/hashmap.go:744 +0x86 fp=0xc2082b7580    sp=0xc2082b7550
 runtime.mapassign1(0x1b4300, 0xc2080dc150, 0xc2082b7698, 0xc2082b7688)
/usr/local/go/src/runtime/hashmap.go:456 +0x568 fp=0xc2082b7620  sp=0xc2082b7580
  arduino.cc/builder/props.PropertiesMap.Merge(0xc2080dc150,      0xc2082b7748, 0x1, 0x1, 0x3)
/Users/jenkins/jenkins/workspace/arduino-builder-     macosx/src/arduino.cc/builder/props/properties.go:162 +0x153     fp=0xc2082b7718 sp=0xc2082b7620
 arduino.cc/builder/props.PropertiesMap.Clone(0xc20803ce40, 0xb2f5f)
/Users/jenkins/jenkins/workspace/arduino-builder-    macosx/src/arduino.cc/builder/props/properties.go:170 +0xad fp=0xc2082b7770     sp=0xc2082b7718
 arduino.cc/builder.(*RecipeByPrefixSuffixRunner).Run(0xc20801e300,     0xc208068000, 0x0, 0x0)
/Users/jenkins/jenkins/workspace/arduino-builder-    macosx/src/arduino.cc/builder/recipe_runner.go:53 +0x2c4 fp=0xc2082b78e8    sp=0xc2082b7770
arduino.cc/builder.runCommands(0xc208068000, 0xc2082b7af8, 0x1c, 0x1c,     0xc208038001, 0x0, 0x0)
/Users/jenkins/jenkins/workspace/arduino-builder-   macosx/src/arduino.cc/builder/builder.go:181 +0x139 fp=0xc2082b7978    sp=0xc2082b78e8
 arduino.cc/builder.(*Builder).Run(0xc2082b7ce0, 0xc208068000, 0x0,   0x0)
/Users/jenkins/jenkins/workspace/arduino-builder-  macosx/src/arduino.cc/builder/builder.go:116 +0xe8e fp=0xc2082b7cc0   sp=0xc2082b7978
 arduino.cc/builder.RunBuilder(0xc208068000, 0x0, 0x0)
/Users/jenkins/jenkins/workspace/arduino-builder- macosx/src/arduino.cc/builder/builder.go:212 +0x49 fp=0xc2082b7ce8  sp=0xc2082b7cc0
 main.main()
/Users/jenkins/jenkins/workspace/arduino-builder-   macosx/src/arduino.cc/arduino-builder/main.go:316 +0x171b fp=0xc2082b7f98    sp=0xc2082b7ce8
 runtime.main()
/usr/local/go/src/runtime/proc.go:63 +0xf3 fp=0xc2082b7fe0   sp=0xc2082b7f98
 runtime.goexit()
/usr/local/go/src/runtime/asm_amd64.s:2232 +0x1 fp=0xc2082b7fe8    sp=0xc2082b7fe0
arduino-builder returned 2
Error compiling for board Arduino/Genuino Micro.

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

Click the apple logo in the top left corner ; click About This Mac; click More Info…; click System Report…; then under Hardware click USB and see if anything gets added when you plug in the Arduino. Let us know if or if not. It could be a bare board without bootloader.

No nothing shows up what do i do?

Try and upload the bootloader to the Arduino. You might need to use a second Arduino to do this.

Ok how do i do that?

https://learn.sparkfun.com/tutorials/installing-an-arduino-bootloader

Your error appears to be with compilation not uploading.  To make sure, try the verify button rather than the upload one.  If it still fails, the problem is the sketch and/or Arduino install, not the board or USB.

no it's with uploading

you cannot upload until the device is recognized by the Mac, so do not waste your time with uploading. .... try another USB cable. ... check if the device is recognized on another computer

From what you say here:

I plug it into my iMac and open Arduino and go to the board tab, and it doesn't even have a Pro Micro choice, so i just choose Micro.

and from the dump you provide:

Arduino: 1.6.9 (Mac OS X), Board: "Arduino/Genuino Micro"

It looks to me like you're selecting the wrong board. Instead of just picking a "similar" board from the Tools menu, what you should do is add the Sparkfun board manager package and then select the Pro Micro from it.
Here you can find the procedure step by step. Follow it and you should be all set.
EDIT:
If you tried to upload a sketch with a wrong board selection, then your your Pro Micro may have become "bricked". In order to unbrick it, follow this procedure (same link as above, different section).
Once you unbrick it, upload the specific blink example code for Pro Micro that you can find in another section of the same link.
If it keeps not working, READ THE ENTIRE ARTICLE linked and try out all troubleshooting instructions before anything else.

Let us know whether it worked or not. :)

Ok i downloaded the sparkfun thing and choose the correct board, and I downloaded the boot loader to it using an Uno and it still doesn't show up in my serial port tab!!

no port is even coming in not only is it not working it isn't existent!!

Please help me :(

If its any help i downloaded the boot loader to the pro micro and the two red lights that were on it turned off and only a green light is present now, what does that mean??

Have you tried to upload the blink example from the link in my answer?

what blink example??

Please read the full article that I have linked to you. There is a section with a Pro Micro specific "blink" example code. Copy it to a new sketch, try to upload it and see what happens.

There not even a port to connect to on my computer, it doesn't show up on my computer that's the problem.

If i upload anything it just says there's no board but I have one plugged in and it won't show up in the serial com tab.

I've updated the answer with additional information regarding how to unbrick your board. And, for God's sake, READ THE FULL ARTICLE.

C'mon... It seems you're not following the procedure. Does the serial port show up when you force the bootloader mode? Don't use another Arduino, but the USB port of your Mac. Once you force the bootloader mode, you have an 8 seconds window to check whether it appears or not in "Tools -> Serial Port", so be quick!

It does not show up on the serial port, How do I force boot loader mode?

Are you trolling me or what? How can you ask how to force bootloader mode, when I've pointed that information to you several times. I've got tired of this, sorry. You've shown no effort to follow any single piece of advice, starting by ignoring the article I linked to. Good luck!

OK thanks i'm not trolling, just confused. I'll try my best hopefully

Ok sorry for being lazy, i did what you have told me to do I wired up a button to the reset and ground of the pro micro and clicked it twice then looked at the port tab and there was still nothing it didn't do anything! :( What's the problem, because I should just buy more at this point, but I still want to fix these I paid for :(

Let us continue this discussion in chat.