text:
Measure total microcontroller current?
So I have a Duemilanove board and am utilizing 7 output pins, I power a Pixy camera and pan/tilt servos from the ICSP header, i also power an HC-SR04 sonar snsor directly from the board.
Of those 7 output pins, 4 are PWMs for the motors (don't ask why), 3 are for servo control (tower pro mg-995)
when I try to output these 7 pins simultaneously things don't work, i get "components at a time" behavior. Like servos turn first, then the motors spin (servos stopped).
Initially we thought it must be a power supply problem (8 1.2v NiMh bat series) which powers the l298n h bridges (two of them) and also powers the board and servos. But now im starting to fear that it's the board itself and that it can't handle simultaneous outputs.
I've read from here (method #10) that taxing the board more than 200mA is a problem. But what exactly happens if you do just that? And is my case exactly like this one? If so, how to fix it?

Edit +

Here's how the circuit looks.

Edit:
Yes i do think there is a need for decoupling capacitors but im not sure where to put them. They dont seem to work. The bounty goes to the best answer on the proper decoupling of this circuit.
Edit:
Here's some images on the Pixy camera

Edit:
Actually from the original problem I noted when I posted this question, things don't work as expected. WHen the big servos move, the pan/tilt camera don't move when they are supposed to, or the motors briefly stop. I'm wondering if is also an Arduino idiosyncrasy because when I don't run the servo.attach(servo_pin)  code everything works fine.

Try having the power wires go directly from the battery to the motors/h-bridge, instead of via the Arduino. Adding an capacitor to the power rail might help too.

I think the main issue with your circuit is a lack of decoupling between the various big current consumers (motors, servos). Adding a few decoupling caps should help.

You should not be trying to run servos off the Arduino's 5V regulator.  Give them their own.

My experience of high power draw from an Arduino is that it endlessly re-boots so maybe not the issue for you.
The Servo library and PWM pins are probably sharing the same timer therefore motors stop while servos are running.
You could try a different Servo library.
This article is useful to understand the timer/pwm/pin relationships

the second sentence is spot on... it happens. If you could provide a solution for the motors stopping while servos are running?

okay but let's be clear. you are not causing more than 500ma to be drawn through the Uno voltage regulator because you are going to get erratic and confusing results?

i dont think i understand your question clearly. the only components directly powered by the arduino board are: Pixy (cmucam5), sonar (HC-SR04), two tower pro sg-90 servos (pan/tilt).

You are right. Prob not a good question. Should have been what happens if you disconnect the power to the servos and the cam. Do the motors run without halting when you know the servos and cam would be working? You could use a debugger or serial messages to tell you when the servos and cam should be working. This test proves if the power is related to the any issue(s)

ok good question. The servos being connected is not the problem. The problem is when there is that 'servo.attach(servo_pin)' in the code.

good that proves it is a timer/interrupt issue.  What pins are servos and motors connected to?

Here are a few suggestions that might help:

Provide its own power supply to Arduino UNO, so that no voltage drop can occur on the board itself due to high energy consumers as servos and DC motors. As someone suggested in an answer, a voltage drop on Arduino MCU may trigger the Brown-Out Detection (BOD) which will stop the MCU until voltage rises up again, above a given threshold. You could for instance power the UNO with a 9V battery (or the equivalent 7.2V rechargeable pack). Those batteries don't have much energy but it should be OK as long as they are not used for powering motors. Of course, then you'll have to remove the Vin wire to your 8-batteries pack.
Add decoupling caps (between V+ and GND) as near as possible to every energy consumer: that means adding decoupling for each motor driver power-in pins, for each servo power pins, and ALSO for the HC-SR04 sonar sensor (in my experience, it can drop voltage a lot, more than you could expect); note that you may also need decoupling for the camera, but I'm not sure on this one, because I have never used one yet.

Note on decoupling caps:
The value of caps to use depend on many factors, which would be too long to explain here (and I admit that I don't necessarily understand each of these); but typically, you would use a small cap (100nF) when you expect fast (and short) voltage drops, and a bigger cap (>=10uF) when you expect longer voltage drops.
When you don't know, you can just experiment and see what works best.
Using both kinds of caps at the same time (in parallel) does no harm (I have done this in several situations).
For higher caps, you will have to use an electrolytic cap, which is polarized: do make sure that you wire them correctly (+/+, -/-) otherwise they may blow up.
Also, choose a breakdown voltage for the cap that is much above (I'd say 50% above is fine) your power voltage; 16V is a common value that would fit your needs; of course, you can use higher breakdown voltages as well.

the pixy camera, along with the pan/tilt servos, are powered through the SPI header in the Arduino board. When the bigger servos are moving, the pan/tilt servos don't move when they're supposed to (im assuming they are experiencing brownouts). How do you propose to decouple a connection through the SPI header?

I don't see the pan/tilt servos in your circuit; you mean they are directly part og the pixy camera and get their power directly from the SPI header? I'd be surprised about that! I could not find a complete datasheet for TowerPro SG90, but I think it should be powerable by your 7.2V AA batteries pack.

If those servos are really powered through the same SPI power pins as the pixy camera then, I'm afraid you will have to set an extra 5V power supply (regulated) just for it.

yes they are powered by the pixy camera by regulating power off the 5V SPI power pins. Im planning to power them from the regulated 5V of the Arduino board instead. Would that be fine?

That would be the same: the SPI 5V is the Arduino regulated 5V. I can't remember the max current you can draw from here, but I guess it must be quite limited. I doubt just adding a decoupling cap here would be enough.

From the Servo library documentation:

On boards other than the Mega, use of the library disables analogWrite() (PWM) functionality on pins 9 and 10, whether or not there is a Servo on those pins.

This is, as has been suggested, because of conflicting usage of the timers. You should just move your DC motors to other PWM-capable pins.

I know this is after the fact but "Back EMF " is more than likely the issue with the starting and stopping of the servo's and most likely the DC motors.
The power supply could receive a pulse 4 to 5 times its supply voltage. The cpu could be scrambled or reset. Or pulses sent to servos corrupted. Divert the energy of a motor's collapsing magnetic field back into itself with a diode, cathode to the positive supply rail. Basically any time you stop or start a motor its magnetic field has to go somewhere.Digital hates that.

When power goes through a wire, it heats up the wire. The more current you draw, the more it heats up. The "wires" inside a chip such as the one that adjusts the power aresmall, which means it heats up more, and also it takes less to burn it out.
A fuse is essentially a very thin wire. If you draw too much current (amps) through it, it will burn out (melt the wire). Wires inside a chip or on a PCB are much the same, It may recover when it cools down, or not. Some devices have protection, some do not - you may find the arduino shuts itself off to protect itself, to restart after a period. Or it may not.
As has been suggested, you can bypass the board to power the h-bridge - there should be one or two pins to power the h-bridge separate from the signalling, specifically for this reason.
Also, if the board is powered by batteries, the batteries may not be able to supply the current, causing one or more parts not getting enough power.
If you do bypass the voltage regulator and use power directly from the power source, remember that you are using a different voltage - the voltage from the power source, not +5v.
If you are powering your board from USB, then be aware that there are limitations to the power able to be supplied via USB - the USB specs say 150milliamps; any higher power has to be negotiated with the host (PC), so you may get different answers for a laptop vs. a desktop vs. a mains power adapter.

as a matter of fact im using 2 h bridges to drive 4 motors. 4 PWMs connect to the in1, in2, in3, in4 of the drivers (the drivers share a pin for the same "in").

I noticed that my assumptions about powering direct were wrong, and rewrote about half the answer.

my circuit power supply is a series of 8 1.2V NiMH AA batteries. It directly powers the arduino and the motor drivers. Refer to the uploaded image.

when i try to output all the 7 pins to drive all the components (yes all), the board keeps flashing. And the servos merely jitter instead of turning, the motors turn from time to time but not how they were programmed to, and the Pixy (including pan/tilt) doesn't even work.

i also noticed that at this state, when I pull off some of the control wires from the output pins, things start to work for the remaining control pins.

Perhaps you are getting brownouts. I suggest running as many motors as work reliably at the same time, then using a multimeter to measure the voltage between 5V and GND (5v is the one hooked up to HC-SRO4 VCC by the look of it). If this ever drops below 4.3 volts, your chip will shut down ("brown out detection") ; the will typically shut down the motors, raise the voltage, and restart the chip - this results in "flashing" of the power led.

You might also want to measure the voltage across the batteries - this will drop as you draw more power. You will need at least 7 volts across the batteries to run the Arduino at 5v.

Let us continue this discussion in chat.


text:
Aptotec PN532 shield power consumption
I am currently planning a battery-powered project, where one of the tasks involves reading Desfire EV1 tags. Since the cheap RC522 based NFC shields are reported not to work with the Desfire EV1 tags, I wanted to make an attempt with a PN532 based shield. Due to offering the fastest shipping option, I ordered an Aptotec PN532 shield, although there are many other, and likely cheaper options out there as well. The Aptotec shield seems identical to the Seeed NFC Shield V2.0.
Communicating with the Desfire EV1 tags works as expected, but I am not understanding the shield's power consumption. If I understand the PN532 datasheet correctly, the chip itself should only draw 45µA when in standby mode, some 30mA when active, but not transmitting and additionally up to 150mA more during actual transmission.
After sending an 'InRelease all targets' command to the PN532, the shield however still draws about 50mA, although the PN532 should be in stand by mode. Using the RFConfiguration command to turn the RF field off completely still does not decrease the shield's power consumption. Activating the RF field e.g. by issuing an InListPassiveTarget command, the current draw increases to about 80mA, which matches with my assumption that the PN532 now draws 30mA more than when idle. There seems however to be something else on the shield causing a 'base line' 50mA current draw, which is not caused by powering the PN532 chip.
Does someone know where this power is lost, if it is possible to software-based turn off whatever is causing the power draw or if other PN532 shields show the same behaviour? Since my project must run on a battery, the 50mA unexplained current draw is not acceptable.

Please provide an exact reference of the shield you used, so that we may take a look at its specs (if any). Note that power consumption of an IC may be different for a shield or more complete circuit that integrates this IC. I have had this problem in the past with NRF24L01P modules, which consumed far more than the IC itself.

@jfpoilpret Sure. I've linked to Aptotec's web page, but there is not much documentation available from them. The board seems identical to the 'Seeed NFC Shield V2.0', where some more documentation is available, but no technical specifications explaining the power consumption.

After some trial and error, I think I can answer this one myself.
The circuit schematic from the Seeed module is actually broken and the Apotec model is built almost identically. The PN532 chip has an SVDD output pin to power an optional security access module for cryptography support. In the Seeed design, this pin is connected to the 3.3V input voltage from the voltage regulator, which is simply wrong and the pin sinks an essential amount of current.

Good catch about the SVDD being an output is connected to 3.3V! I too am facing the same problem. Have your tried to cut the trace on the PCB coming out of SVDD (pin 37), and connected this pin to ground (or left floating?). Do let me know if you have tried this. Thanks
Tilak.

@user31092 Sorry that I missed your comment. No, I haven't tried to fix the module. If you cut the PCB trace to the SVDD pin, you have to let the output pin float and should not connect it to ground.

source: Stack Exchange

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

authors: โอ๊ด อภิชาติ

sort: votes


text:
Arduino Sending faster/more data to a web server
I'm working on a project that reads vibration on a building using an accelerometer and displaying it's data on a web server. The plan is to read 10 samples/second from the accelerometer and send that data every 5 seconds to a web server using arduino yun.
So there would be 10(samples/sec) x 5(seconds) x 3(3 axis - x,y,z) = 150 data points that will be sent to the webserver, I tried this with the client.get() command but it cannot send that much data to a web server, I also tried POST request but i've had trouble with the sending it multiple times since it needs to have a delay.
What are the other options that I can do in order to achieve this? Any suggestion would help and please if you think my question is bad or not stated properly don't report me, I'm still new here in stack exchange. Any help/suggestion is much appreciated
Arduino Code for POST request
#include <Bridge.h>
#include <HttpClient.h>
#include <YunClient.h>

//IPAddress server(192,168,1,200);
byte php_server[] = {192,168,1,9};

YunClient client;
String data = "", datax="", datay="", dataz="";
unsigned long ts_0 = 0, tr_0 = 0, t_read = 100;
int counter=0;

void setup() {
  // put your setup code here, to run once:
  Bridge.begin();
  Serial.begin(115200);

}

void loop() {
  // put your main code here, to run repeatedly:

  if((millis()-tr_0>=t_read)) {

    if(counter<49) {
      counter++;
    }
    else if(counter == 49) {
      //Serial.print("sent");
      String dat = "0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12,0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12, 0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12,0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12, 0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12,0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12, 0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12,0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12, 0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12,0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12, 0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12,0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12, 0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12,0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12, 0.24,1.24,4.56,8.97,3.15,7.23,9.34,0.12,6.21,8.12";

      send_to_ws(dat);
      Serial.println(dat);

      counter = 0;
    }
    tr_0=millis();
  }
}

void send_to_ws(String data) {
  if(client.connect(php_server, 80)) {
    Serial.println("Connected");
    client.println("POST /arduino/add.php HTTP/1.1");
    client.print("Content-Length:");
    client.println(data.length());
    Serial.println(data.length());
    Serial.println(data);
    client.println("Connection: Close");
    client.println("Host:192.168.1.9");
    client.println("Content-Type: application/x-www-form-urlencoded");
    client.println();
    client.println(data);
  } else {
    Serial.println("Connection error");
  }
}

Serial monitor output when running this sketch, It prints it in the serial monitor but only blank data is being pushed in the database of the server

Its not clear from your question, are you sending 150 POST requests or one request with 150 points of data?  What are the minimum and maximum values of the points and who many decimal places are you using?

one request with 150 points of data, i think the maximum value wouldn't exceed the 10 so probably between +/- (0.00 - 9.99) considering i will have 2 decimal places,

Could you show us your code? As in principle both method would work. There is probably something in the code, like e.g. a buffer, that limits the amount of data that can be send.

@Gerben I haven't really integrated all the things i wan't to do in a sketch, but what i did was sending a request and hardcoded the data that i want to send. I found out that it is too large especially using the client.get() method of the httpclient library since sending a small string can be done without a problem but when i try to increase the size (up to 60 data points) it can still send but it takes so much time sending the data, approximately 20 sec and when I'm using POST request which uses delay i dont know how  i can still read every 100 ms while having a delay for 1-2 sec in sending

Could you show us your code? I don't care that it isn't finished. It's even better like that, as there is no other code that can have side effects. Why does POST use delays? That makes no sense.

@Gerben sorry for the late reply, when you said using delays in POST makes no sense, i tried removing it and it still works, the code is attached above and I hardcoded 150 data points but it seems like no data is pushing through my server

data.length() returns 0. There might be a problem there. Does it work when you use a shorter string? It might also be a good idea to use the F("text") macro to save some memory. Lastly the data string isn't x-www-form-urlencoded, so your PHP script will have to get the raw POST data instead. So there might also be a problem at the server's side.

no problems when i send shorter data length like 186, it sends every 5 seconds but when somewhat longer than that like 400+ it can still send data but it cannot send every 5 seconds, instead it reaches up to 20 sec for each request to be made. Where should I apply F("text") in the client.println(data)? or in my serial.println(). Oh yeah I forgot to edit that though, but I edited it already in my code. thanks! Any thoughts on how to make this possible?

Option 1.
Send a single message from the client to the server.  This message should contain all 150 points of data.
Option 2.
Send the data in a format other than as a string.  Base64 encoding of the raw numeric values would be ideal, but its going to add extra load to the CPU.  Depending on the range of the data (0-359) and the resolution (use 2 DP) you might be able to use just 4 bytes for each data point.  Because you are using a fixed length value to represent each point you no longer need separators in you data so a single reading goes from 21 bytes to 12 bytes.
Option 3.
Hand off the data to a second processor that is dedicated to sending the data.  The Yun would write the data into a shard circular buffer and the other processor (possible another Yun or an ESP8266) would read the data from the buffer, convert it and write it to the server.
I can't say which is best, because I don't know enough about you system, but if you could expand on your details we should be able to narrow it down.

After reading you answer above.  If you ranges are 0-10 with two DPs then I would look at option 2 first.  If each reading can range from -9.99 to +9.99 you take the absolute value and multiply by 100 and write that as a 2 digit hex number to your message body.
uint8 number = ((reading < 0) ? 0x80 : 0x00);  // Set the high bit for negative.
number += (abs (reading) * 100);
messageBodyString += String (number, HEX);

That will give you 2 bytes per point, and a 300 byte (+overhead) message should be transferable within 5 seconds.

Here is some quick code to explain the encoding and decoding
unsigned int Encode(const float& value)
{
    unsigned int result = (value < 0) ? 0x80000000 : 0x00000000;// Work out and set the sign bit
    result |= (unsigned int)abs(value * 100.0);             // Get the absolute value (ignore sign) and multiply
    return result;
}

float Decode(const unsigned int& value)
{
    const bool isNegative = ((value & 0x80000000)  != 0);       // Get the sign bit
    float result = (float)(value & 0x7FFFFFFF);                 // To remove the sign bit
    result /= 100.0;                                            // Divide to return to the original number of dps.
    if (isNegative)
        result = 0 - result;
    return result;
}

sorry for the late reply, was having a hard time absorbing what you're saying since I'm a newbie. I did option 1 already but yun cannot send that much data using the client.get() function from HttpClient library.
After deep thinking on your code I understand it already, or somewhat at least. So first is the number should have a high bit (i guess it is also the msb?) to know if it's positive or negative, then I convert the decimal reading to an int, or remove the decimal place and then convert it to a string? I will definitely give this a try thank you so much for the answer!

hello, will i need a separator for this to change it back to decimal numbers? since other hex values are only one character and others are 2 characters.

also another one, how would i check if the hex value reflects the negative number? because when i tested it the same number having opposite signs printed the same hex value, thank you so much for the help

If the most significant bit is set then the number is negative.  That's what the 0x80:0x00 is for.  You then have 15 bits to hold the value, which is ... oh bugger it isn't enough.  You need 2 byte numbers, which give you 4 characters.  Sorry.

because this data is going to a web server developed in php, so i should check in php if each hex values has most significant bit then it is negative? I'm a little confused with your statement that i need 2 byte numbers which gives me 4 characters, I'm sorry I can't comprehend that well :(

now I understood what you meant by 2 byte numbers, that means i should use uint16_t right? because the values are greater than 255 (8 bit decimal), but now I don't know how to change this back to decimal when it is a negative number for it has an additional of 128 decimal value

Ralph, I've edited my answer with rough encode and decode functions.

hey I just found out that there are some values that doesn't get the right value in encoding, like when the value is -0.53 it returns the result as 52 instead of 53, but it works fine with others, why is this happening? even when I hard code -0.53 it still returns 52 but when I put -0.54 etc it works fine.

That's not my fault :) Its to do with the way floating point values are stored in memory.  A floating point number should have an infinite range of values between 0 and 1. Obviously you can't us binary to store this infinite range so you have to have make a compromise and this is where the resolution comes into play.  Write a little program in visual studio and add const float a = 0.53f;  printf("a = %2.5f\n", a);  printf("b = %d\n", (int)(a * 100));  You will get the output 0.53\n52\n!!!  If you put a break point in there you will see a == 0.5299999714F.

If you need accuracy then you could either user more digits or make a look up table of values that don't work so you can correct them.

Personally for this kind of frequency of data I wouldn't even consider sending it via HTTP. The extra bulk of the HTTP protocol makes the transfer way too slow.
Instead I would set up a UDP-based gateway server which accepts UDP messages from your sensor system and stores the data directly into the database (or wherever you are storing the data) for the website to display it at its leisure.
Yes, it is more complex to create since you need to write the UDP server gateway software. However you then completely remove the massive overheads of a text-based bulky protocol like HTTP.

You can use 2d Array for this and send all data at once in 5 Sec. It Read all 3 Axis data each 100Ms and make a matrix of 50 X 3 = 150 Values and then Print it in Serial Port. You can use this in your code to send data to server in desirable format.
int Xaxis=A0;
int Yaxis=A1;
int Zaxis=A2;
int axisMatrix[50][3];
void setup(){
    Serial.begin(9600);
    pinMode(Xaxis,INPUT);
    pinMode(Yaxis,INPUT);
    pinMode(Zaxis,INPUT);}

void loop(){
        for (int i = 0; i <= 50; i++) {
            axisMatrix[i][1]=analogRead(Xaxis);
            axisMatrix[i][2]=analogRead(Yaxis);
            axisMatrix[i][3]=analogRead(Zaxis);
            delay(100);}
        for (int i = 0; i <= 50; i++) {
            Serial.print(axisMatrix[i][1]);
            Serial.print(",");
            Serial.print(axisMatrix[i][2]);
            Serial.print(",");
            Serial.print(axisMatrix[i][3]);
            Serial.print(",");
            Serial.print("\n");
        }}

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


text:
SIM900A showing Starting modem test...ERROR, no modem answer. Checking IMEI...Modem's IMEI: 0

Edit:
Solution can be found HERE

I am trying to interface Simcom SIM900A GSM (SIM900a Mini DEV Board v3.9.2) and I tryed interfacing it with Arduino UNO. I have connected as:
Pins:
SIM900A - Arduino
=================
VCC     - VDC (+5V)
GND     - GND
5VR     - Connect to Arduino TX (Pin 1)
5VT     - Connect to Arduino RX (Pin 0)

Power Supply (External):
5V 2A

Problem
When I upload sketch of:
Example > GSM > TestModem:

to Arduino, I got this output from Serial Monitor:

Starting modem test...ERROR, no modem answer.
Checking IMEI...Modem's IMEI: 0
Reseting Modem... Modem is functioning properly: IMEI: 0

Other info:

By supplying 5V, 2A the SIM900A Power LED ON continuesly and Signal LED blink with certain period of time which mean I am okay with signal.

I connected SIM900A and Arduino with Male to Male + Female to Female as I don't have Male to Female wires. I tested the wires with Multimeter and it's prefectly working.

I tested uploading other sketches of sending sms but not successful. Note that, I have load + free sms on SIM.

Power supply is actually Adapter (no transformer but circuit) with output of 5.1 Volts

My previous post can be checked HERE
PS:
Yesterday just for a minute I noted: Both LEDs (Power + Signal)  of SIM900A were blinking at same time. But then by restarting it gets Okay again.
Please help. I am likely to die becuase of tension.

Some points: 1. You can't use pins 0/1 for both the GSM and your debugging at the same time. You will have to use SoftwareSerial (ugh) on another pair of pins. 2. The GSM library is for the Arduino GSM Shield, not the SIM900A.

Hello @Majenko, Thank You very much for your comments. With due respect if you allow to let me clarify before flaging my post as duplicate, despite the title being same we have different content, also by following the instructions in mentioned post I applied that but nothing happened * (actually they say you have to use different, mine is already in place) * I know rules of SO and I will never spam it with questions by bombording it with same content. I never ask, but I research before very thoroughly. Thank You.

@Majenko Thank You. 1: As you said: I can't use 0/1 I am using SoftwareSerial mySerial(9, 10); Still nothing happening (I mean not sending msg). 2: If I can't use GSM Library what should I use to make this SIM900A Mini work? What I want to accomplish is Send Text Message. Please post Answer, so that help universe solve this problem. (As many people are facing same problem and I found no solution)

You already asked this question at SIM900a Mini Modem, IMEI 0, Help with TX RX pins  and have now indicated that the answer is found there.   You should not have re-posted your already asked question.

@ChrisStratton I agree, and I apologize for my ignorance. Actually I wait for answer and every second I used to refresh my page but go no answer. For the sake of attention and more clarity I asked again with little different context. BTW the "answer there" is also mine. I give link just for ease if in case someone like me needed. Anyways Thank You very much. If anyone want to delete this post I am okay with it. I am okay with every SO rules. Once again accept apologize.

Re-posting to get extra attention is pretty much exactly what is prohibited.

Note:
Detailed Solution can be found Here

Excerpt:
My Pins connections were wrong, it should not be: 0 and 1 it should be 2 & 3
Also SoftwareSerial.h is not working with SIM900A
Pins:
All connections should be like this:
SIM900A - Arduino
=================
VCC     - VDC (+5V)
GND     - GND
5VR     - Connect to Arduino TX (Pin 3)
5VT     - Connect to Arduino RX (Pin 2)

Details Here


text:
What wrong with that code?
Hi i have made this code
its so simple its should receive data from the computer and send it back via the serial but the problem is he do not what it is suppose to do
when its run its keep sending -1 to the computer
and if i send something to the arduini  like  55   i receive and answer 53
i have no idea were is the problem in this code
long number = 0;

void setup() {
  Serial.begin(9600);
}
   void loop() {
   number = Serial.read();
   delay(1000);
   Serial.println(number);
}

Serial.read() returns -1 when there was nothing to read. Just discard the -1.

here i made so change to the code the value for  number is no longer 5   now its 0 and i changed int for long and therer no longer int before  number = Serial.read();          when i send 3  its answer me 51 10

When you send a 3 what answer do you expect?

@EricCooper True, if you send "3" you'll get ASCII 51, ASCII 10. (http://www.asciitable.com/index/asciifull.gif)
The NUMBER 51 is CHARACTER "3" also, a newline character (10) is added to the end of your serial message when you send it.

You need to include DEC as the second argument to the Serial.println() call to get the correct numbers out.  Read up on this here: Arduino Serial Print.
In other words, make change below:
Serial.println(number, DEC); // DEC is needed to get the correct values

I didn't even know this, but it's worth noting that he's printing the ASCII representive of the sent character.

Serial.read() returns one character from the input. Serial.println will try to convert a variable into ASCII characters, and print that. Your variable, number gets the ASCII code of the first typed character in its first byte. The Serial.println call will interpret that and the next 3 bytes (whatever they happen to be...?) as a value to be printed.
Your problem is in not understanding the conversion of digit strings into values and vice-versa, and of how the Serial.xxx functions work.
You'll need to collect the terminal input character-by-character into an array, then convert it to a numeric value (assuming you're eventually going to do more with it than print it back out). Then you could Serial.println() that (or another) value out to the terminal.


text:
less expensive alternative arduino board to CMUcam4
Is there any similar (less expensive alternative) arduino board to CMUcam4?
CMUcam4:The CMUcam4 is a fully programmable embedded computer vision sensor. The main processor is the Parallax P8X32A (Propeller Chip) connected to an OmniVision 9665 CMOS camera sensor module.

What's a CMUcam4?

@Majenko www.cmucam.org.

@IgorStoppa I can't click that, and copying and pasting is as onerous as using google to look it up for myself.  My dig was to try and get Rwy5 to provide a link (and even a little information) in the question...

I'm waiting for a bitbake build to complete, so trying to kill time :-)

OpenCV on Raspberry or Beaglebone.

I have used OpenCV on Intel Galileo for doing recognition of sub images from a larger image (given the cover of a magazine, identify it in a pile of magazines partially covering it). The frame rate is far from stellar.
I haven't tried with Edison but it should be much faster, as it's an Atom core vs the pentium-like Quark. OpenCV is optimized for x86.
I used a normal webcam to capture the image, so this solution gives more flexibility in the choice of the sensor.
You could have a look at ROS on Edison.


text:
Arduino Keyboard starts lower case (but it shouldn't)
So I flashed the KeyboardMessage example to my Arduino SS Micro ATmega32U4.
When I open an editor and push the button, I would assume the output to be

Zou pressed the button XX times.

(The "Z" is because I use a German keyboard)
In some editors (Arduino IDE, LibreOffice) this assumption is fulfilled.
However, in several other editors (Linux Shell, gedit), most of the times the output is

zou pressed the button 1 times.

starting with a lower case "z".
I use a Debian Testing computer. The only thing I changed in the sketch was the buttonPin as my button is soldered to pin 11.
I noticed, that this problem doesn't occur when the button is pressed a second time shortly after the first message. To investigate this, I coded a little sketch to find the threshold.
This is what I got (in gedit)

As line 8 shows, even after 70 millis, the upper case start is not reliable, however, somewhere after 250 millis, the error occurs every time.
My questions are:

What could be the cause for this issue?
How can it be fixed (if necessary, I also welcome a workaround)?

Please tell me if you need any additional information.
[edit]
After slightly altering the script, I noticed, that the problem doesn't only occur on the start of a line, but also (although less often) later in the output. See lines 24, 31 and 52 for example

Probable a long shot, but do you have any gedit plugins (e.g. ChangeCase plugin) enabled? Also, I hate to be pedantic, but are you sure the "little sketch" matches the output? The "little sketch" has a space between the number and millis (i.e. should produce "90 millis", not "90millis" as shown above). Also, the "little sketch" outputs a capital M in Message - which are all lower case in the above example.

Thanks for your comment! I indeed do have some gedit plugins enabled, however, they shouldn't change the case. I tried in the Linux shell as well and had the same result. About the changes in the sketch: you are right - I changed these two things after running the sketch. However, I didn't want to run it again as this takes quite some time.

yes, i just reread and saw the comment about linux shell. Oh, well it was a long shot :-)

Without any knowledge in this area, i assume that "slow editors" work better than "fast editors" and that somehow the shift key is swallowed somewhere between the arduino and the computer.

What happens if you unplug your normal keyboard while it's running?

@Majenko just tried: it's exactly the same.

As a debugging aid, you may try to use xev to see the keyboards events. When I press Shift-Y on my keyboard, xev shows four distinct events: KeyPress(Shift_L), KeyPress(Y), KeyRelease(Y), KeyRelease(Shift_L). Do you see the same events in the same order? See also Keyboard input in the Arch Linux Wiki (instructive even if you are not using Arch).

use keyboard.press() and keyboard.release() to send the shift key states at the correct time

Sorry for the late response. @EdgarBonet thanks for the xev tip. I coded a small sketch that should print "ON" when I push a button on the Arduino. This is the output in xev: https://nopaste.xyz/?b4efb9869c386975#22qZaCvBxQ2HfuTxEGszxdxnLbf18qTNuuCToR9JfwpA . In an editor like gedit this reads like "oN"

@jsotola this would be a possible workaround. However, like this I would need to distinguish between those characters that need a shift button and those that don't. Something I hoped the keyboard library would do for me.

I am not sure I have the answer to your problem, just a collection of
observations that hopefully steer you in the right direction.
According to your nopaste link, when you send "ON", the first four
keyboard events received by xev are: press(Shift_L), press(O),
release(Shift_L), release(o). One may notice that there is no point in
releasing the Shift key if it's going to be pressed again right away,
but let's assume that simply holding Shift is not such a useful
optimization. The detail that strikes me is that the last two events
look backwards: you usually release the letter before releasing Shift.
As a result of releasing Shift first, the release event for the O key
reports lowercase "o" as a keysym. I tried this backward way of
releasing the keys on a real keyboard, but both gnome-terminal and gedit
correctly registered the uppercase letters.
Another detail apparent in the xev dump is that the two key presses
(Shit and O) happen at the exact same time. Ditto for the corresponding
key releases. Looking at the source of the Keyboard library, it appears
that both key presses are sent to the PC as a single "key report". Same
for the key releases. This is contrary to what a real keyboard does:
actuations on the Shift keys are reported immediately, irrespective of
whether other keys are actuated.
You may try to modify the Keyboard library so that the actuations on
Shift are sent in their own reports. Maybe something like this
(warning: completely untested):
diff --git a/src/Keyboard.cpp b/src/Keyboard.cpp
index 4a948f6..9fbf7b6 100644
--- a/src/Keyboard.cpp
+++ b/src/Keyboard.cpp
@@ -239,6 +239,7 @@ size_t Keyboard_::press(uint8_t k)
        }
        if (k & 0x80) {                     // it's a capital letter or other character reached with shift
            _keyReport.modifiers |= 0x02;   // the left shift modifier
+           sendReport(&_keyReport);        // send the shift key by itself
            k &= 0x7F;
        }
    }
@@ -270,6 +271,7 @@ size_t Keyboard_::press(uint8_t k)
 size_t Keyboard_::release(uint8_t k)
 {
    uint8_t i;
+   bool has_shift = false;
    if (k >= 136) {         // it's a non-printing key (not a modifier)
        k = k - 136;
    } else if (k >= 128) {  // it's a modifier key
@@ -281,7 +283,7 @@ size_t Keyboard_::release(uint8_t k)
            return 0;
        }
        if (k & 0x80) {                         // it's a capital letter or other character reached with shift
-           _keyReport.modifiers &= ~(0x02);    // the left shift modifier
+           has_shift = true;
            k &= 0x7F;
        }
    }
@@ -295,6 +297,10 @@ size_t Keyboard_::release(uint8_t k)
    }

    sendReport(&_keyReport);
+   if (has_shift) {
+       _keyReport.modifiers &= ~(0x02);    // the left shift modifier
+       sendReport(&_keyReport);            // release shift after releasing the letter
+   }
    return 1;
 }

Alternatively, as suggested by @jstola in a comment, you may try to
press the Shift key by itself. Maybe you don't need to care about the
key release, or about any character but the first one (as it is the only
one that seems to cause problems). A minimal workaround to try would be:
Keyboard.press(KEY_LEFT_SHIFT);
Keyboard.println("ON");

Thanks, @EdgarBonet! I can confirm, that your solution works on my computer. However, this raises the question if the "original" Arduino implementation is faulty. I would encourage you to file a pull request on their implementation.

by the way, the problem doesn't only occur in the first character but also sometimes on later ones.

@speendo: I am reluctant to submit a pull request, as I do not have a 32U4-based Arduino to test it. I would do it, though, if you are willing to help with the testing: provide a minimal test sketch, run it, and report the results on the pull request page.

Of course I am willing to help. Using this library (https://github.com/NicoHood/HID) you could also use test your code with another Arduino board (this is the library where I first experienced the error) But I would also fund you a cheap Pro Micro board as a little recognition for your work. Just tell me what solution(s) you like best :)

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


text:
Arduino to ESP8266 SoftwareSerial communication
I have an Arduino Uno and an ESP8266, connected over serial through
ESP8266 pin GPIO_2 (which is set as RX over espsoftwareserial) and 11 on Uno (which is set as TX over SoftwareSerial). I am trying to send data (for now just random numbers from 0 to 1000) from Arduino Uno to ESP8266.
But ESP8266 shows messy chars.
I am using:

espsoftwareserial library
Original SoftwareSerial library

Arduino UNO code:
#include <SoftwareSerial.h>

SoftwareSerial mySerial(10, 11); // RX, TX
int randnum;

void setup() {
  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  Serial.begin(115200);
}

void loop() { // run over and over
  randnum = random(0,1000);
  mySerial.write(randnum);
  Serial.println(randnum);
  delay(2000);
}

ESP8266 code: (it's programmed with Arduino IDE)
#include <ESP8266WiFi.h>
#include <SoftwareSerial.h>

SoftwareSerial ARD_ESP(2, SW_SERIAL_UNUSED_PIN); // RX, TX  |||| RX = ESP8266 = GPIO_2

const char* ssid     = "myssid";
const char* password = "mypassword";

const char* host = "www.myweb.com";
const char* value2 = "986.458";
const char* value1 = "150.0589";
long previousMillis = 0;
char indata;
String incomingData_from_ARD = "";
int i=0;

void setup() {
  Serial.begin(115200);
  ARD_ESP.begin(9600);
  delay(10);
  // We start by connecting to a WiFi network
  Serial.println();
  Serial.println();
  Serial.print("connecting to wifi: ");
  Serial.print(ssid);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}
//int value = 0;

void loop() {
  //delay(1000);
  //++value;
  if (ARD_ESP.available() > 0) {
    Serial.write(ARD_ESP.read());
    indata = ARD_ESP.read();
    incomingData_from_ARD += String(indata);
  }
  if ((millis() - previousMillis) > 10000) {
    Serial.println("---------------------------------------------------------------------------------------");
    Serial.print("Requesting URL: ");
    Serial.println(host);
    Serial.println("-------------------------------");
    // Use WiFiClient class to create TCP connections
    WiFiClient client;
    const int httpPort = 80;
    if (!client.connect(host, httpPort)) {
      Serial.println("Request failed");
      return;
    }
    // We now create a URI for the request
    String url = "/testesp.php";
    url += "?sensor_1_total_volume=";
    url += incomingData_from_ARD;
    url += "&sensor_2_total_volume=";
    url += value2;
    Serial.println("Sending data to URL: ");
    Serial.println(url);
    Serial.println("-------------------------------");
    client.print(String("GET ") + url + " HTTP/1.1\r\n" +
      "Host: " + host + "\r\n" +
      "Connection: close\r\n\r\n");
      unsigned long timeout = millis();
    while (client.available() == 0) {
      if (millis() - timeout > 5000) {
        Serial.println(">>> Server Timeout!");
        client.stop();
        return;
      }
    }
    while(client.available()) {
      String line = client.readStringUntil('\r');
      Serial.print(line);
    }
    Serial.println();
    Serial.println("Closing connection with web");
    Serial.println("-----------------------------------------------------------------------------------");
    previousMillis = millis();
    incomingData_from_ARD = "";
  }
}

And this is the text that I am getting on Serial (on PC):
    -----------------------------------------------------------------------------------
        ›¸Ąě*Ű
 ---------------------------------------------------------------------------------------
Requesting URL: www.myweb.com
-------------------------------
Sending data to URL:
/testesp.php?sensor_1_total_volume=Ĺ˙˙˙˙˙&sensor_2_total_volume=986.458
-------------------------------
HTTP/1.1 200 OK
Server: nginx
Date: Tue, 13 Dec 2016 23:28:58 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: close
X-Powered-By: PHP/7.0.10

354

â€žÄŚas si vymysleli lidĂ©, aby vÄ›dÄ›li, od kdy do kdy a co za to.â€ś Jan Werich

<!DOCTYPE html>

   <meta charset="UTF-8">
   <meta name="description" content="TEST_ESP">
   <meta name="author" content="Vasekdvor">
   <meta name="robots" content="noindex">
   <title>TEST ESP 8266 POST A GET</title>

0

Closing connection with web
-----------------------------------------------------------------------------------

These messy chars at the beginning are the random numbers that Arduino Uno sends:
›¸Ąě*Ű
But Arduino sends real numbers, only the ESP8266 is interpreting them as this.
Can you please help me fix that? How can I receive numbers?
Thank you.
EDIT:
So i have made some changes based on chupo_cro recommendations
Now its Arduino:
void loop() { // run over and over

randnum = random(0,1000);

mySerial.write((byte*)&randnum, sizeof(randnum));
Serial.println(randnum);

delay(2000);
}

And ESP8266:
long previousMillis = millis();
char indata;
String incomingData_from_ARD = "";
int i=0;

void setup() {

.................................
void loop() {
  //delay(1000);
  //++value;

  if (ARD_ESP.available() > 0) {
    //Serial.write(ARD_ESP.read());
    indata = ARD_ESP.read();
    incomingData_from_ARD += indata;
  }

  Serial.println(incomingData_from_ARD);

  if ((millis() - previousMillis) > 10000) {

Its still doesnt work.

There are a few issues in your code.
First, you have if (ARD_ESP.available() > 0) to check if the data arrived but what is going to happen if the data still haven't arrived? Instead of waiting for the data to arrive the program will continue through the loop and it will send a request every 10 seconds even if there is no data.
Second, you initialized previousMillis to zero. You should initialize it to millis() so you can count from the present moment in time.
Third, in the loop where you are reading the input:
if (ARD_ESP.available() > 0) {
    Serial.write(ARD_ESP.read());       // <-- 1st read
    indata = ARD_ESP.read();            // <-- 2nd read
    incomingData_from_ARD += String(indata);
}

when something arrives, you are reading it twice so the second read indata = ARD_ESP.read(); gets -1 (no data available) when there is less than two chars in the buffer. Even if you sent more than one character there is no time for new data to arrive in the buffer and even if there is more than one character you miss every second one because of the 1st read.
Fourth, you cannot send the number greater than 255 (one byte) with mySerial.write(randnum); because write() sends only one byte. And even if you could in a such way send more than one byte, you cannot display these bytes as a string representing the number. You could send all bytes using:
mySerial.write((byte*)&randnum, sizeof(randnum));

but, as I said, these bytes are not a string representing the number contained in a variable. For example, if randnum = 1000, that is 0xe8, 0x03 and "1000" is 0x31, 0x30, 0x30, 0x30. 0x31 is ASCII for 1 and 0x30 is ASCII for 0.
So, you have a lot of things to improve.
EDIT:
Try this, I don't have a time to check the code but it should work:
int length = 4;
char to_send[length];
itoa(randnum, to_send, 10);
mySerial.write((byte*)&to_send, sizeof(to_send));
Serial.println(to_send);

EDIT:
Unfortunately I don't have Arduino (I've even never had one :-)) so you'll have to try the code and report back if it works. I have a few ESP8266s but they are all logging some data at the moment.
Now for the ESP8266 code:
You have at least two choices when deciding how to read the data. The first choice would be 'your way', something like:
void loop() {

    char input;
    if(ARD_ESP.available()) {
        input = (char)ARD_ESP.read();       // you can try even without (char)
        Serial.print(input);                // send char to terminal
        incomingData_from_ARD += input;     // concatenate the new char
    }

    if ((millis() - previousMillis) > 10000) {
        // if there was something received until now
        if(incomingData_from_ARD.length()) {
            // ...
            incomingData_from_ARD = "";
        }
        previousMillis = millis();
    }
    // ...
}

The second way could be:
void loop() {
    char input;
    // wait for the data
    while(!ARD_ESP.available())
        yield();                          // to prevent WDT reset
    // read everything that has been sent
    while(ARD_ESP.available()) {
        input = (char)ARD_ESP.read();
        Serial.print(input);
        incomingData_from_ARD += input;
        delay(120);                       // 100 or a bit more for 9600 Bd
    }

    // remove 'if' to send immediately
    if ((millis() - previousMillis) > 10000) {
        // ...
        previousMillis = millis();
    }
    // ...
}

There is a significant difference between these two ways of reading the incoming data. When reading the data as in the first example then in every pass through the loop you either read or don't read exactly one byte. Since there is a possibility 10 seconds will pass before we received some data, there has to be a check if the data in the meantime arrived or not. If there was some data then every 10 seconds everything received until that moment would be sent - even if that was in the middle of the string. You probably don't want to send just one part of the string to the server.
In the second example there is a while loop waiting for the data from serial port. When the data arrives there is another while loop to read all bytes one by one. Without delay the loop would end before receiving the second and all subsequent bytes so the received string would be cut in 1-character chunks. Now, when the whole string is received, we don't have to check if something arrived because we already know it did.
I've left 10 seconds delay between sending the GET requests but you have to decide if that is what you really want. You have to be aware that if the next data arrive in between sending the GET requests, the next string (number) will be concatenated with the previous one - and you do not want that to happen because such data wouldn't be meaningful. To avoid concatenation of the new with the old data, you have to remove if which is checking millis() to send the received data immediately.
Note:
As I said, I can't test the code so I cannot guarantee it is 100% error free but you can check if it works so I can correct the mistakes if there are any.

Thanks for your reply, but first issue doesn´t solve the problem with serial data.
I have edited the code, but still it doesn´t work.

Of course it does not resolve the issue, as I explained you cannot send raw numbers and have string representation. When you send number 1000, that is 0xe8, 0x03 (232, 3) because 1000 = 3*256 + 232. 232 and 3 is not 0x31, 0x30, 0x30, 0x30 which is String("1000"). To have string "1000" you have to send 0x31, 0x30, 0x30, 0x30. I will give you the code in an hour or two as I don't have time at the moment.

Here you are the code to send the number as a string. I'll take a look at other things later when I have time.


text:
Arduino to ESP8266 (SoftwareSerial) communication, does not receive full data
I have an Arduino Uno and an ESP8266, connected over serial through ESP8266 pin GPIO_2 (which is set as RX over espsoftwareserial) and 11 on Uno (which is set as TX over SoftwareSerial). I am trying to send data in this format:
<0.000000:0.000000:0.000000:0.000000:0.000000:0.000000:24.50:24.50:1.49>
It is < char then number with six floats, separator :, and again... 9 times
I am using:

espsoftwareserial library
Original SoftwareSerial library

Arduino UNO code:
SoftwareSerial ARD_ESP(10, 11); // RX, TX

totalVolume[0] = 0.000000;
totalVolume[1] = 0.000000;
totalVolume[2] = 0.000000;
flowRate[0] = 0.000000;
flowRate[1] = 0.000000;
flowRate[2] = 0.000000;
float temperature_cold_value = 24.50;
float temperature_hot_value = 24.50;
float propane_gas_value = 1.49;

void setup()
{
   ARD_ESP.begin(57600);
   Serial.begin(9600);
}
void loop()
{
if (millis() - previousMillis_esp_post > 5000 && run_state_metering == 1)
     {
          ARD_ESP.print("<");
          ARD_ESP.print(totalVolume[0],6);
          ARD_ESP.print(":");
          ARD_ESP.print(totalVolume[1],6);
          ARD_ESP.print(":");
          ARD_ESP.print(totalVolume[2],6);
          ARD_ESP.print(":");
          ARD_ESP.print(flowRate[0],6);
          ARD_ESP.print(":");
          ARD_ESP.print(flowRate[1],6);
          ARD_ESP.print(":");
          ARD_ESP.print(flowRate[2],6);
          ARD_ESP.print(":");
          ARD_ESP.print(temperature_cold_value,2);
          ARD_ESP.print(":");
          ARD_ESP.print(temperature_hot_value,2);
          ARD_ESP.print(":");
          ARD_ESP.print(propane_gas_value,2);
          ARD_ESP.print(">");

          Serial.print("<");
          Serial.print(totalVolume[0],6);
          Serial.print(":");
          Serial.print(totalVolume[1],6);
          Serial.print(":");
          Serial.print(totalVolume[2],6);
          Serial.print(":");
          Serial.print(flowRate[0],6);
          Serial.print(":");
          Serial.print(flowRate[1],6);
          Serial.print(":");
          Serial.print(flowRate[2],6);
          Serial.print(":");
          Serial.print(temperature_cold_value,2);
          Serial.print(":");
          Serial.print(temperature_hot_value,2);
          Serial.print(":");
          Serial.print(propane_gas_value,2);
          Serial.print(">");
          Serial.print("");

          previousMillis_esp_post = millis();
     }

ESP8266 code: (it's programmed with Arduino IDE)
#include <ESP8266WiFi.h>
#include <SoftwareSerial.h>
#include <string.h>

SoftwareSerial ARD_ESP(2, SW_SERIAL_UNUSED_PIN);

const byte numChars = 32;
char receivedChars[numChars];
boolean newData = false;

String sensor_1_total_volume;
String sensor_2_total_volume;
String sensor_1_flow_rate;
String sensor_2_flow_rate;
String temperature_cold_value;
String temperature_hot_value;
String propane_butane_gas_value;
String mereni_token = "xxxxx";

void setup() {

  Serial.begin(115200);
  ARD_ESP.begin(57600);
  delay(10);
}

void loop() {

  recvWithStartEndMarkers();
  showNewData();

  sensor_1_total_volume = getValue(receivedChars, ':', 0);
  sensor_2_total_volume = getValue(receivedChars, ':', 1);
  sensor_1_flow_rate = getValue(receivedChars, ':', 2);
  sensor_2_flow_rate = getValue(receivedChars, ':', 3);
  temperature_cold_value = getValue(receivedChars, ':', 4);
  temperature_hot_value = getValue(receivedChars, ':', 5);
  propane_butane_gas_value = getValue(receivedChars, ':', 6);

}

void recvWithStartEndMarkers() {
    static boolean recvInProgress = false;
    static byte ndx = 0;
    char startMarker = '<';
    char endMarker = '>';
    char rc;

    while (ARD_ESP.available() > 0 && newData == false) {
        rc = ARD_ESP.read();

        if (recvInProgress == true) {
            if (rc != endMarker) {
                receivedChars[ndx] = rc;
                ndx++;
                if (ndx >= numChars) {
                    ndx = numChars - 1;
                }
            }
            else {
                receivedChars[ndx] = '\0'; // terminate the string
                recvInProgress = false;
                ndx = 0;
                newData = true;
            }
        }

        else if (rc == startMarker) {
            recvInProgress = true;
        }
    }
}

void showNewData() {
    if (newData == true) {
        Serial.print("This arrived: (unparsed)");
        Serial.println(receivedChars);
        Serial.println("DATA sensors: (parsed)");
        Serial.println(sensor_1_total_volume);
        Serial.println(sensor_2_total_volume);
        Serial.println(sensor_1_flow_rate);
        Serial.println(sensor_2_flow_rate);
        Serial.println(temperature_cold_value);
        Serial.println(temperature_hot_value);
        Serial.println(propane_butane_gas_value);
        Serial.println(mereni_token);
        newData = false;
    }
}

String getValue(String data, char separator, int index)
{
    int found = 0;
    int strIndex[] = { 0, -1 };
    int maxIndex = data.length() - 1;

    for (int i = 0; i <= maxIndex && found <= index; i++) {
        if (data.charAt(i) == separator || i == maxIndex) {
            found++;
            strIndex[0] = strIndex[1] + 1;
            strIndex[1] = (i == maxIndex) ? i+1 : i;
        }
    }
    return found > index ? data.substring(strIndex[0], strIndex[1]) : "";
}

It works fine, but ESP receive only three values, another 6 does not.
I have tried to change bitrate to 57600, but thats not help.
I think that there is a problem with speed or waiting for full data.
Can you help me ? Many Thanks.
Here is the output from ESP:
This arrived: (unparsed)0.000000:0.000000:0.000000:0.00
DATA sensors: (parsed)
0.000000
0.000000
0.000000
0.004

xxxx

Could you reduce these pages of code to a minimal, complete, verifiable example [http://stackoverflow.com/help/mcve] please, and edit your question to include it. You might even find that doing so fixes your problem.

Its Done. Maybe now someone could help.

I meant get rid of all the many Serial.println()s and replace with a single test string. Send only that string.  Write a minimal example for the receiving device to receive and print only that line. Show how the expected and actual received data differ.

You should be able to write a little 10-line program for sender and another for receiver, and demonstrate the problem very concisely. It'll help us, and it'll help you :-)

You are sending number+'.'+6 float +separator = 9 char at least.
You are sending 9x this, 81 char at least. Plus '<>' and maybe some more chars...
And you store it in 32 char long buffer. Somehow it does not fit all inside, who knows why?  :(
As you can see, you got like 32 chars only of the full transmission. Try to set numChars to something like 100 and try again. See, if it is better.
(Also I would use pattern
      ARD_ESP.print("<");
      Serial.print("<");
      ARD_ESP.print(totalVolume[0],6);
      Serial.print(totalVolume[0],6);
      ARD_ESP.print(":");
      Serial.print(":");

to leave the ESP more time to process stored data, but it is probabelly not problem now)

Thank you so much. I am such an idiot. I wrote a program and forget on setting numChars to corresponding value.

I am trying to use this for my purposes with just two strings.  I was hoping to use it with an ESP8266-01 with only eight pins.  Do you think it would work  what pins should I plug into  on the ESP if I use TX (2) and RX(3) on the Arduino UNO.  Thanks

Sorry, I do not have ESP or much knowledge about it. I just counted characters and read the size of buffer and see, there is at least one big problem (regardless platform) which I can simply see. Happened this was all, what was needed to fix it.

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


text:
I have 4 motors connected to their own ESC (that is connected to a power distribution board), how do I connect this to Arduino uno? (Drone)
I am currently working with a bigger drone that I want to connect with an arduino uno.
The motor and ESC that are already soldered together and connected are these: https://hobbyking.com/en_us/mt1806-brushless-combo-include-esc-5030cw-ccw.html
I have also connected it to a power distribution board where I succesfully can connect my 3s lipo battery.
What is currently missing is where I should put the 3 pins on each ESC onto the arduino board. So there are 12 pins in total.
The color on the 3 wires on each ESC are: yellow, red and brown.
Yellow is the signal if i am not mistaken and those should be connected on the PWM pins where I control each motor in the code.
When it comes to the red it is + power and should I ignore to connect these pins? I would like for my battery to power both the motors and the arduino so of course I would prefer to connect it to the arduino uno if it is possible.

Here are just some clarifications for you:

Signal pins don't have to be connected to PWM pins. AFAIK, any digital pins should work.
All grounds togheter! Glad you got that right!
Connect VCC of ESCs directly to the power supply.
Connect power supply to VIn of Arduino (not 5V because you are going to grill it!)

Uptdate

Yes, you can probably solder all the VCC wire of the ESCs togheter.
By power supply, I meant connecting it directly to the battery.

To power the Uno, connect the battery+ to the VIn pin of the UNO.

Thanks a lot for the answer! So far so good :)

Ok!
Ok!
3/4. Do i do the following: Solder all of the VCC of the ESC (the red wire) the same way like I do with the ground and then I connect it to a power supply module? Is this a power supply module I can use? https://www.aliexpress.com/item/Smart-Electronics-MB102-MB-102-Solderless-Breadboard-Power-Supply-Module-3-3V-5V-for-Arduino-Board/32569124727.html?spm=2114.40010208.4.1.Pm4T84 It is for a breadboard i think but can it work with an arduino uno? When it comes to powering teh arduino I am a bit unsure how to do it.

This is one of my first projects so therefor I am very rookie in some areas!

I've updated the answer.

Hi! I was just wondering. I have a 4s battery now that I plan to hookup to a arduino pro mini 5v board instead of a Uno-board. So instead of putting the battery wire to the Vln of the arduino uno I will put it on the "RAW" on the arduino pro mini. Will a 4s or 3s lipo make any difference?

Pro Mini's regulators are quiet bad. I'll suggest to put it to a down converter before passing it to the Arduino.

this is where i will attach the battery: https://hobbyking.com/en_us/hobby-king-quadcopter-power-distribution-board.html to my power distribution board and from that board i will connect the voltage to the RAW and the other pin to the gnd. Does the PDB work as a converter?


text:
How can I send/write two doubles via Bluetooth (nRF8001 Bluefruit LE) in Arduino?
I recently purchased an nRF8001 Bluefruit LE and I am now trying to read/send data with an app. But I am not sure how I can write/send a double value. I want to send two double values at once and to successfully send this, do I have to convert these doubles to a byte array? If so I would very much appreciate how that would look!
This is documentation on how my module works:
https://learn.adafruit.com/getting-started-with-the-nrf8001-bluefruit-le-breakout/nrf-uart-in-detail
Under the headline Writing data they give examples on how to send data but as far as I can see (I am a bit new to Arduino code) in their example they only send an int and a string.
I know how to read and set up the module, so it is only the writing/sending doubles that I am struggling with.
These are the two doubles that I wish to send and I control it with:
double valueOne;
double valueTwo;

The Bluetooth control:
Adafruit_BLE_UART BTLEserial = Adafruit_BLE_UART(ADAFRUITBLE_REQ, ADAFRUITBLE_RDY, ADAFRUITBLE_RST);

So if I for example do this:
BTLEserial.write(valueOne, valueTwo);

I get this message: no matching function for call to 'Adafruit_BLE_UART::write(double&, double&)'
So do I need to convert these two double values to a byte array and if so how would that look?
Appreciate every help, tips, code! :)

After the first successful message received, did you see the location refreshed on the serial monitor by the Serial.println(gps.location.lat(),6); ?

I see that once yes and also the Serial.println(gps.location.lng(),6); once

Also the Serial.println(F("* Connected!")); once

Seeing once Serial.println(F("* Connected!")); is normal, because the message is sent only when the status change. But are you sure that your gps.location.isUpdated() is true ?

I removed gps.location.isUpdated() in the if-statement but it still stops right when I connect my app to the bluetooth. I also added a Serial.println("test"); right at the top of the while loop and that stops once i connect the app with the bluetooth as well so there must be something else.

And what is strange is: If i remove the write/print function. It works and Serial.println(gps.location.lng(),6); keeps getting written out in the log. So it is that last line when I write the data the while loop decides to stop

When reading the "nRF UART In Detail", only 20 bytes could be sent at a time... So, try send a small string in place of sBuffer... Then reduce the size of sBuffer by sending less decimal for your location.

I kinda need the lat/long decimals to be as exact as possible when i send them. I tried with this code: String slat = (String)latvalue;     BTLEserial.print (slat); but that gave me the same result unfortantly

I recieve this amount of decimals right now from my lat value 15.728758 which is 8 numbers and the same amount of numbers from my lng value. Should this be a problem?

Try to send for instance just "lat,lon" that very small message... Is it sent periodically ?

So just BTLEserial.print("lat,lon");?

Same thing :(
When I connect i get this in the monitor:

Connected!
0.000000
0.000000

0.000000  is the lat, lng that is currently empty and I dont send that, i just write them out in the while loop each time it runs to see if it keeps running after i sent "lat,lon"

Ok I figured out the codeline that makes it work but I am not sure how to solve it without it because I do not want to read current data, i want to send new data. I need this line in order to make it work String vOut = Serial.readString();

Check it out here: https://learn.adafruit.com/getting-started-with-the-nrf8001-bluefruit-le-breakout/nrf-uart-in-detail on the first code example you can find it and how the code works when they write it. If i copy that it works. But if i create my own string and replace that one line i mentioned above String vOut = Serial.readString(); it does not work.

I made a new post covering that exact issue

As the link "Adafruit - nRF UART In Detail" describes, the function write(sendbuffer, sendbuffersize); is waiting for a buffer of uint8_t followed by the size of the message.
Here are the step--by-step solution to send the 2 doubles by using that function.
Step1 - convert the floating-point values into a char string.

In the Arduino environment, the standard format-specifier %f or %lf
  is not well-managed and the function dtostrf() is recommended.

The format is char *   dtostrf (double __val, signed char __width, unsigned char __prec, char *__s) where:

__val is the floating-point value to be converted,
__s is the array of char to store the result,
__width is the number of characters to store the result,
__prec is the number of digit

The conversion is:
char sValueOne[16], sValueTwo[16];
char sBuffer[33];

strcpy(sBuffer,dtostrf(valueOne, 15, 8, sValueOne));
strcat(sBuffer,",");
strcat(sBuffer,dtostrf(valueTwo, 15, 8, sValueTwo));

Step2 - write the buffer over the BTLEserial object.
BTLEserial.write((uint8_t *)sBuffer, strlen(sBuffer));

Alternate output solution using BTLEserial.print() function.

BTLEserial.print(sBuffer);

so should I use a strcpyon the sValueOne and a strcaton sValueTwo? What does these strcpy and strcpy mean? What type of function is it? Btw, thanks a lot for the answer!! I learned a lot with your example

Both functions strcpy() and strcat() are used to copy char strings. The first is used to initialize the buffer char sBuffer[33] and the second is used to concatenate the extra string to the existing. If valueOne= 8.89 and valueTwo=9.88, the first string is sValueOne =  "8.89000000" and the second string is sValueTwo =  "9.98000000" and the output buffer is sBuffer = "8.89000000,9.98000000".

How often can I write code? Is it possible to do it each 0.5 second?

Ok. Thanks a lot for explaining that! my both doubles cointains 6 numbers after. I send coordinates looking like this:  `double latvalue;
double lngvalue;
latvalue = (gps.location.lat(),6);
lngvalue = (gps.location.lng(),6);`

The period is highly depending of the real baudrate of your BTLEserial device. The conversion is enough fast for two samples per second.

Alright! Thanks a lot for your help! Appreciate it a lot

After I write/print with the bluetooth, the void loop()stops and it does not keep working/running. Any idea why this is?

I add a delay (500); after the write/print but still the while loop stops after the first "run"

Could you edit your question and add your source code ?

Sure one second

Updated now with source code

When i connect my phone to the bluetooth device it works once, atleast I think) so becuase I recieve the latvalue + lngvalue when I print out in my serial monitor and also i get  "Connected". But I only recieve this once.

I didn't try this, but since Adafruit_BLE_UART inherits from Stream,
which in turn inherits from Print, you should be able to
BTLEserial.print(valueOne);
BTLEserial.print(",");
BTLEserial.println(valueTwo);

Codes uploads without any trouble! However the while-loop stops with my current code when I use your code as well. It works once (when I connect to the bluetooth with my phone) I edited the post with my source code if you want to check it out.

If i completely remove write or print and connect to the bluetooth with my app the while loop keeps going but if i add your code or j.piquards code the while loop stops right away when i connect the app with the bluetooth


text:
LED Control through bluetooth
I have an Android app that sends data to the arduino HC-06. It is however giving me colors i did not send to it. Eg. Red in place of green, white in place of red etc.
Here is a snippet of my android code that sends the data via bluetooth
 public void onColorChanged(int color) {
    BluetoothV2 bluetooth = new BluetoothV2();
    int r,g,b;
    r = Color.red(color);
    g = Color.green(color);
    b = Color.blue(color);
    bluetooth.Message(r+","+g+","+b);
 }

Here is a snippet of my arduino code
void loop() {

if(Serial.available()>0){

while(Serial.available()>0){
   char inChar = (char)Serial.read();
   inputString += inChar;
}
   int red = Serial.parseInt();
   int green = Serial.parseInt();
   int blue = Serial.parseInt();
   color(red,green,blue);
   inputString = "";
   Serial.println("R:"&& red &&"G:"&& green &&"B:"&& blue);
  }
}

void color (unsigned char red, unsigned char green, unsigned char blue){
   analogWrite(redPin, 255-red);
   analogWrite(greenPin, 255-green);
   analogWrite(bluePin, 255-blue);
}

Terminal data
               2,,,,,,,,,,,,,2,,5,,,,,,,,,,,,,,,,,,,,,,,,,02725,1,502725,,,,,,,,,02514,5,602515     ,5,3,,,,,025

Is the problem how i get the data though Serial.read()? Or what am i missing

When you say "terminal data" where is it coming from? What do you see in the serial monitor of the arduino IDE?

Why read characters to inputString and then parseInt()? And the Serial.println("R:"&&...) is strange that it even compiled. Try printing each value separately.

@Madivad i meant data from my serial monitor.

@MikaelPatel i was doing parseInt() to separate the commas in between the data eg data received=255,255,255. inputString is equated to that data and parseInt() the first time gets me the first value before the comma and the second time the second value after the first comma to the next comma(next character thats not of int data type). However i solved this issue. Let me post my answer.

int firstcomma = inputString.indexOf(',');
int secondcomma = inputString.indexOf(',',firstcomma+1);
String r = inputString.substring(0,firstcomma);
String g = inputString.substring(firstcomma+1,secondcomma);
String b =  inputString.substring(secondcomma+1);
red = r.toInt();
green = g.toInt();
blue = b.toInt();
Serial.print("R");
Serial.print(red);
Serial.print("G");
Serial.print(green);
Serial.print("B");
Serial.println(blue);

This solved my problems.

Maybe you can try again with something like this to check if the android part is not correct. From your terminal output it seems that you receive values higher than 255.
void onColorChanged(int red, int green, int blue) //values from 0 - 255
int r,g,b;
r= red;
g= green;
b= blue;
bluetooth.Message(r+","+g+","+b);

The receive part in your arduino code is like my code for a similar project.
Try setting your color in the arduino code like this to check if the example code from above works:
void color (int red, int green, int blue)
{
analogWrite(redPin, red);  //the higher your send value the brighter the color
analogWrite(greenPin, green);
analogWrite(bluePin, blue);
}


text:
Multi-drop RS485 device control v1.0 - why is limit for "TIME_BETWEEN_MESSAGES "?
I am going to use Nick's rolling-master system library (http://www.gammon.com.au/forum/?id=11428) in my home project.
For first experiments and testing, I have:
- BAUD_RATE = 9600
- max adress = 2 (it means max 3 drops)
- 2 active drops with adress=0 and adress=1, 1 intentionally missing drop (simulation    of malfunction one of drops :-))
- TIME_BETWEEN_MESSAGES = 200000
- Packet length = 200 bytes
- Packet time = 208333 microseconds
- Timeout for no messages = 1633332 microseconds
- gap between messages = 200 ms (measured value by oscilloscope).
It work perfect.
I would like to increase the gap between the messages, but after I increased the constant "TIME_BETWEEN_MESSAGES"  from 200000 to 300000, then start bad communication  between the drops:
- TIME_BETWEEN_MESSAGES = 300000
- Packet length = 200 bytes
- Packet time = 208333 microseconds
- Timeout for no messages = 2033332 microseconds
- gap between messages = 2170 ms
Adress first started after reset (for example 1)  broadcasts, but nothing receives from other adress (for example 0), which started later.
Adress 0 receives all messages from adress 1 OK, but nothing transmits (subroutine "sendMessage ()" is never called).
After reseting of broacasting drop with adress  1, it works in reverse (addr 1 only receives, no broadcast, and addr 0 broadcasts).
Why is there limit for "TIME_BETWEEN_MESSAGES" value ? How to increase gap between messages ? For my purpose be enough gap 1 - 2 sec and so drops should have enough time for their own job.
Thanks for advice,
Vava
(Sorry for my English... :-)


text:
Writing analog voltages on analog pins of Arduino
Can we write a analog voltage to analog pins A0-A7 of the Arduino Nano (for example)?
As in:
pinMode(A3, OUTPUT);
analogWrite(A3, 200);

read the doc https://www.arduino.cc/reference/en/language/functions/analog-io/analogwrite/

No. The analogWrite(pin, val) function is reserved to PWM pins (D3, D5, D6, D9, D10, and D11 in Arduino Nano). Pins marked as "ANALOG IN" on the board can work either as analog input (to the Analog to Digital Converter), digital input, or digital output.
It is worth to note that the Arduino Nano (and any other Arduino board I'm aware of) actually doesn't have any 'true' analog output port. When you use analogWrite(pin, val) you are actually telling the Arduino to output a PWM signal with the duty cicle specified by val (100% for val = 255 and 0% for val = 0). If you actually do need a true analog output, you should consider using any form of analog lowpass filter at the specified PWM output port. Depending on how clean you want your signal to be, you could use a single capacitor or any other (a little more complex) filter.
If you don't know anything about filters, this could be a good starting point: ElectronicsTutorials - Passive Low Pass Filter
More insight about PWM in Arduino, here: EAS 199 - Basic Pulse Width Modulation

Note that the Due does have two true analog output pins (called DAC0 and DAC1), in addition to a dozen PWM pins.

analogWrite are PWM digital pins. Analog pins on Nano are ADC read/input only (or digital I/O except A6 and A7).

All microcontrollers including Arduino are digital, and rely on specific circuit hardware in order to interface with the analog world.  Two of these relate to your question:

Analog-to-digital converters (ADCs) sample an analog voltage and output a number representing the voltage relative to the measurement range - such as 0 to 1023 on a 10-bit ADC.
Digital-to-analog converters (DACs) do the reverse, where a digital number from the microcontroller is used to output an analog voltage, e.g. between ground and the supply voltage.

While ADCs and DACs convert analog-to-digital and vice versa, they need different circuits.  In the case of Arduino boards and other microcontrollers, analog input (read) and output (write) must use different pins.  Analog input pins cannot be used as outputs, and vice-versa.
The exception is where you want to produce an analog output via PWM (and a smoothing capacitor).  In that case the answer is yes, you can use pins A0-A7.  However, you will need to bit-bang and won't be able to use the timer hardware.  It's much easier to use the pins dedicated to DAC or analogwrite if that's an option for you.

You can create your own PWM on non-PWM pins using Blink Without Delay techniques.  Use the micros() timer and check it every pass thru loop() to if it is time to change the state of the output.
This will create 50% duty cycle, with frequency = 1/(2 x halfPeriod)
void loop(){
  currentMicros = micros(); // capture the current 'time'
  elapsedMicros = currentMicros - previousMicros;
  if (elapsedMicros >= halfPeriod){
    previousMicros = previousMicros + halfPeriod; // set the 'time' of the next transition
  }
}

all time related elements are of type unsigned long
Then filter with a RC Lowpass filter (Resistor and a capacitor) to smooth it out so it's more like an analog level.


text:
How do I connect through a HC-05 to PS4 Controller?
Searching for Arduino and PS4 on google, I find always the same construction using a USB host shield and a Bluetooth dongle.
But I'd like to connect a PS4 Controller to a HC-05 device. Is it possible? If not, why not?

The HC-05 uses the Bluetooth Serial Port profile (SPP). The PS4 controller doesn't.
Hence you need something that is capable of using the same profile that the PS4 controller uses (HID?). And to that end you need something a little more configurable than a simple HC-05. One option is, as most people use, a USB Host shield with a Bluetooth dongle that can then be configured to communicate using the right profile.

@NikX see https://en.m.wikipedia.org/wiki/List_of_Bluetooth_profiles

So, how do I get to know which profile a bluetooth device uses? assuming the ps4 controller uses HID, I think this could be a way to connect a hc-05 to ps4 controller.

I upgraded my HC-05 to RN42. With some experimenting it seems like it's possible to connect to the PS4 Controller. At least I could detect the controller.


text:
What is actually an IC (Integrated Circuit)?
They say that you must know what IC your board has before loading a new program from the Arduino IDE and that the information is available on the top of the IC, but where is it exactly and what is an IC?

https://en.wikipedia.org/wiki/Integrated_circuit

IC stands for integrated circuit, which is a generic term encompassing any class of devices that has multiple electronic components (transistors, and possibly capacitors, resistors, diodes, and more) encased and interconnected within. The opposite of an integrated circuit is a discrete component, which is a single electronic component in its own package that relies on wiring (or a circuit board) to connect to other components.
Taking a look at the Arduino Uno R3 below (click for larger image), the long rectangular black thing is the primary IC. You can see the ATMEL logo on it, followed by a short series of numbers (a date code if I'm not mistaken). Below is the chip model itself; in this case, "ATMEGA328P-PU". With respect to the Arduino IDE, it's sufficient to know that the chip is an ATmega328P, which is sometimes incorrectly called ATmega328 in the Arduino world.

If you look closely, there are also several other ICs on the board. To the right of the ATmega328P is a small 5-pin package; if I'm not mistaken it's an LP2985-33DBVR, which is a low-dropout voltage regulator. On smaller packages like this they often have more cryptic legends printed on them, in this case if you squint at the full-size picture you can make out "LPFL". Fortunately for most Arduino development purposes, knowing the model of these auxiliary ICs is generally not necessary. Just below that, above the crystal (the metal oblong can marked SPK16.000G) is an 8-pin package marked 09TI R5R, which I believe is a LMV358IDGKR dual op-amp.
Another IC of note on this board is the small square 32-pin package below the crystal; this is an ATmega16U2. In the case of the Arduino Uno R3, rather than being the primary microcontroller, this serves as the USB-to-serial converter.
Note that to the right of the crystal is a small three-pin package marked "340"; this is a FDN340P MOSFET. While this model of MOSFET (as with many others) contains an integrated diode across its drain and source and could thus technically be classified as an integrated circuit, most would still consider it a discrete component.

@per1234 thanks for the corrections :)

It's funny that you have a picture of one in your profile pic. :)

The arrow points to the most obvious integrated circuit or chip in you pic, there is another square one to the left of the TX and RX markings.  There are lots of different types of ICs -- most are black and come in different shapes and sizes, different number of legs, but most have some form of writing on the back that Google can use to locate the data sheet, or general help.  Have a quick look on Wikipedia for a more authoritative description.


text:
Maximum Delay time
I am designing a driver for a Bipolar stepper motor using Arduino Mega 2560 and DRV8825 Stepper driver.
In my application, a stepper motor (Nema 24) will run for 5 minutes and stop for 2 minutes. I have doubts about is what is the maximum time an Arduino Mega can delay the process, or how much a maximum time delay() function will last, or work in programming?

Note: there's an existing question here this should be closed as a duplicate of, but that is proving hard to find.  So until someone does find it...
The arduino delay() function creates a blocking delay of the provided number of milliseconds.   The argument is an unsigned long which on a 16-bit Arduino is a 32-bit unsigned integer type, having a maximum value of 4,294,967,295.  Since these are milliseconds, the maximum delay() would be 4,294,967.295 seconds, or about 49 days.
However, you can easily achieve longer delays by using counting variables to count up instances of shorter delays.  At an extreme, by using up available memory for keeping track of such counting, you can readily achieve theoretical delays exceeding the age of the universe.
Note that the Arduino delay() function is blocking, which is to say that nothing else (except interrupts and on-chip hardware peripherals) runs during it.  This is often undesirable.  A more useful solution might be to make a loop taking say 20 milliseconds to run, as the result of a delay() and a few housekeeping operations, and then run this over and over again while counting.  Or you could make a 1 second loop, or whatever you choose.


text:
Convert from 3 V to 5 V
I'm new to Arduino, electronics, and this forum.
I have made up a little project that connects an HC-SR04 ultrasonic range detector, and displays the distance on a 4 digit, 7 segment LED display.
When I have it plugged into my laptop for power, it runs beautifully on an Uno board.
But I want to mount all this in a Nerf gun (Nerf N-Strike Elite Firestrike) using a Nano board.
The Nerf gun has a built in "laser" (red light) that is powered by 2 x AAA batteries, which makes 3 V, I think. I want to rig this up so that pulling the laser/light trigger also triggers the range detector and display.
I want to run the range sensor and the display off the Nerf guns batteries, but they both use 5 V. Is there a way to do this? Or do I need a separate 5 V power supply?

I cannot answer the question as asked.  I don't know of a way to convert 3V to 5V.  Arduinos run better at 9V anyway.  You are probably going to want 9V battery for an Arduino Nano to mount in the Nerf gun.  Have you considered this?

Yes, I have considered a seperate power supply. Maybe a 9v battery powering the nano is the way to go.

You may want to use a boost converter which is a device that can step up voltage.
You can get them from eBay for around $US 2.

As Chris Stratton pointed out in a comment, the boost converter may run your batteries down quite quickly. Let's say you need 200 mA for your Uno, sensor and LEDs. At 5V power that is 1W of power (0.200 * 5).
However to get 1W from 3V you would consume 333 mA (0.333 * 3). Then take into account that the converters are not completely efficient. Let's say the converter has 90% efficiency. Then you need to multiply the current by the inverse of the efficiency, that is: 0.333 mA / 0.9 = 0.37 mA.
Another factor is the battery type. If you use NiCad batteries their nominal voltage is closer to 1.2V than 1.5V, especially after you have been using them for a bit. Ditto for NiMh batteries.
Reworking the above for 2 * 1.2V (2.4V) we see that the current will be:
1W / 2.4V = 0.4167A
0.4167A / 0.9 = 0.463A (allowing for 90% efficiency)

Now it potentially draws close to half an amp when active. Your batteries might not be able to handle that for long.

This is possibly, a solution, but may place a lot of load on the little AAA batteries, as the current drawn at the input voltage is the current needed at the output voltage multiplied by the ratio and the reciprocal of the conversion inefficiency.

Indeed. Still, to meet the requirements of the question it could work (for a while). I've edited the question to do some maths for the current draw.

All this math makes my poor head hurt.

Just to suggest an alternative, and more energy efficient, solution...
There appear to be newer versions of the HC-SR04 on the market that support 3.3V, such as the HC-SR04 v2 - Low Cost Ultrasonic Sensor (3V to 5V Supply).
So you could use an Arduino Pro Mini designed to run at 3V in conjunction with the 3.3 V HC-SR04, and run it straight off your nerf gun's power supply.

However, it might be worth taking these new versions with a pinch of salt, as modules seem to vary from one to another, see Re: Do HC-SR04 5V rangefinder sensors work in 3V battery mode?

I have a MKRFOX1200 working with HC-SR04 and it works fine. It is stated to work only at 5v but its fine with 3V. But I have another one (SF-SR02) with a higher range (6meters) and this one doesnt get any further than 1  or 2 meters under 3V. If I use the 5V for VCC while running on USB, it reaches full range. Digital inputs seem to be more tolerant than they state for 5V signals.. (although I'm not advising to do so!!)

An extremely useful comparison of these modules (the first generation) running at both 3.3 and 5 V can be seen here, Re: Ultra cheap ultrasonics, and a bit of a challenge:
3V3

5V

Notwithstanding, the newer versions of the HC-SR04 may have an improved response.

Arduino nano also have 5v-3.3v voltage regulator so you can power all this with only one power supply (power your arduino nano with 6x AAA batteries) and then just connect your nerf gun power with arduino nano 3.3v pin, it will work just fine............
                                      :)

I like this option. Rather that running the Arduino off the guns power, run the gun off the Arduino's power. Still means I need to put in more batteries. I was hoping to fit everything inside the Nerf gun, but that might not be possible. Or I just buy a bigger Nerf gun.

This is a very good solution.  And yes, they make bigger Nerf guns.  But also keep in mind that the Nerf gun is going to shoot much further than the ultrasonic sensor can measure.  While this is an interesting project, it may not turn out to be useful.


text:
Combining ADC IRQ with SPI peripherals results in SPI not working
I'm working on a pet project that requires ADC, SD card (SPI interface, SdFat library) and a display in the future (also SPI).
I have put together a piece of code that initializes ADC at the highest clock frequency and uses ADC_IER_DRDY interrupt and double buffering.
I have also put together a piece of code based on one of SdFat examples that inits SD card and benchmarks its speed.
On its own, each piece works just fine. But combined together, it breaks if I enable the ADC interrupt. It causes SdFat to stall, not sure where (I don't have a debugger). Simply disabling the interrupt is enough to let SdFat work just fine, but I need both. I have also set ADC IRQ priority to 0 and most other IRQs to 1, but removing NVIC_SetPriority calls does not solve the problem.
Any advice on how to make both ADC and SPI work, with ADC IRQ priority so that I don't miss samples?
I also tried lowering SPI speed from full to 1/16th (SdFat lib has a convenient parameter for this), didn't help.
The code is not long, but a bit too much for inlining into the question, here are Github links.

main.cpp and ADC stuff - just commenting the highlighted line fixes SPI.
SD card stuff. Of note: sometimes it prints "chipselect: 10", sometimes not even that.

Update: making ADC handler empty does not resolve the problem, neither SPI nor printing to Serial works.

First thought was to poll the ADC and not use interrupts.  But if you need it that fast, well.  My second thought is to rewrite the interrupt routine to handle both the ADC and the SPI.  Guessing, only the last feature you instantiate is working.  Are you setting up the ADC after you setup the SdFat?

@st2000: no, I'm setting up ADC first, then running SdFat code. If ADC interrupt is enabled by now, SD doesn't work. I don't have any sort of explicit SPI interrupt handling routine, it's either part of the SdFat lib or the Arduino framework itself, not sure yet.

My ADC interrupt can't be taking more than 30 cycles, I don't understand why it affects SPI in the first place.

@st2000: I made ADC handler body empty, but still neither SPI nor printing to Serial works. Is that supposed to happen? Any ideas why this might be?

These types of problems can take a lot of digging to solve.  Ideally, you would find someone who has solved this exact same problem.  The rest of us, with out a considerable investment in time, can only make suggestions.  If interrupts are involved for both the ADC and SPI features, and if the embedded processor you are using only has 1 interrupt vector for both, then I sill think the vector is being over-written pointing to just the interrupt routine of the last feature to modify the vector. If true, then rewriting that interrupt routine to handle both features may be a solution.

Some other suggestions: 1. Arduino platforms are cheap.  Use one for the ADC and another for the SPI.  2. Try a larger embedded processor.  Different processor have different hardware features.  Maybe you will get lucky and the libraries will be compatible on a different embedded processor.  3. Try a different library.  People write the libraries and it is highly unlikely any 2 approach the problem identically.

@st2000: I understand, appreciate the suggestions. I'm sure this is doable in principle, I'll keep digging and will post an answer if I find a solution.


text:
What are patterns of bits sent to or read from GPIO pins called?
I want to call them “words”, but I’m uncertain if this is how they are referred to in documentation for the use of a header board that might plug into an ardino board.
So if you have a sequence of ONs and OFFs being read or sent from a microcontroller board are those called words?  What are they called?

What? I don't understand, what you are talking about

https://en.wikipedia.org/wiki/Word_(computer_architecture)

Bit streams or bit patterns, perhaps? Words have a different definition already, but it may fit what you are asking for, can't tell.

Also it might be called packets, messages (=> communication protocol). Depends on interface

@KIIV Frames too?  What do you mean by “depends on the interface?”

Different interfaces names similar concepts differently...

The "GP" in GPIO stands for "general-purpose", meaning that the interpretation of the signals will vary. Even changing from a 0 to a 1 might not be "a bit" depending on the specific protocol being used (e.g., edge-clocked).

Consider backing away from Arduino hardware for just a moment

I want to call them “words”, but I’m uncertain ...

For most computers and processors a word is comprised of bytes and bytes are comprised of bits.  A bit is an individual 0 or 1.  That's always true.  A byte is almost always made up of 8 bits.  Why? Because it is always convenient to do things on a computer or processor in powers of 2.  That is, 2 or 4 or 8 or 16 or 32 or ... (keeps going).  And 8 is a convenient sized number of bits!  A word is usually 2 bytes or 16 bits.  But that's not always true.  For some computers it is more.
Keep in mind, so far, we are just talking about data.  Not physical GPIO pins.  When we do interface through the GPIO pins this data can be sent out in parallel or in serial form.  It really depends on how we want to interface with the world!  For instance, many Arduino projects uses a serial interface called an I2C bus to talk with peripherals such as a temperature sensor.

So if you have a sequence of ONs and OFFs being read or sent from a
microcontroller board are those called words?

This sounds like you are talking about serial data (as apposed to parallel data).

Talking about the hardware: The GPIO lines on most embedded processors are designed to interface with the world using parallel data.  You can use software and "emulate" a serial stream of data on one of the GPIO lines.  But you might not be able to send out data fast.  Instead, most embedded processors have special serial port pins which are connected to fast hardware usually called UARTs. When sending or receiving serial data, it is almost always better to use a pin connected to a UART.

Talking about the data: Again, word can mean different amounts of data on different processors. And to further complicate things, some serial protocols mix things up and end up sending out or reading data using an odd number of bits.  Which makes talking about the combined bits as a word confusing.  At this point I would just stop using the word "word" to describe the data and just call it "data".

Besides, most Arduino boards (like the Arduino Uno) use embedded processors which interface directly to peripherals such as temperature sensors over serial ports.  As such, the data format is usually spelled out by the peripheral and is (very) specific for the purpose of the peripheral (temperature sensing in this case). It is recommended to read the specifications for the peripheral and use the terminology presented there when communicating with others regarding that particular peripheral.

Here is a simplistic diagram.
Larger than 8 bits is usually referred to as WORD.

Is one nybble input and the other nybble output in the diagram?

no,  it is not ... how did you arrive at that supposition? ... the diagram only shows that a byte consists of two nybbles ... there is no input or output implied


text:
Problems using an arduino with vex motors and motor controller 29
I am using a VEX 2-wire motor with the Motor Controller 29 to use it like a three-wire motor.
I was told that I am able to program it like a servo using the Arduino Servo class. When I use the write() function to set the power, it works from values around 50-85 in one direction, slowing down the power as I increase the value, but when the value exceeds around 90 then the motor stops working and makes strange clicking sounds. It is not a hardware problem, because the motor works fine in either direction when I plug it straight into a power source.
Does anyone know what my problem is?

What power supply are you using to power the motor? Those VEX motors have a stall current of at least 3A, so you'll want to be providing a fair bit of power to the motor controller.

I'm using the 5V pin that is built-in to the arduino.

and what is that powered by? USB will not be enough power, and the voltage regulator on board cannot cope with that much current. You should be powering the motor from at least a 2A 5V power supply, and you can power the arduino from it via the 5V pin if you wish.

I'm using a 9V battery to power the Arduino.

VEX motors with Servo library have the following functionality:
0 one direction (full speed)
90 stop
180 opposite direction (full speed)
So at 90, it is trying to remain motionless and hence creating that sound.
btw. You should provide power to motors separately from the Arduino. You might fry your Arduino if you run VEX motors from it. Best solution is to power using 7.2V 3000mAh Flat NiMH High Power Battery Packs.