text:
SD card in Arduino
Im connecting an SD card module to arduino pro with 3.3v , the card is getting initialized , but im getting an error message that FAT 32 partition is not available , but it is already in FAT 32 format , is this an voltage issue ? should i connect it to a 5v line? Ive tried it two libraries SD and sdfat libraries , im getting same results, im using 8gb memory card

A SD card is 3.3V.
Have you read this: Arduino.cc forum about SD Formatter ?
Perhaps it is a cheap module with bad contacts.
Perhaps your 8GB card is not compatible. Do you have another memory card ? Preferably older and less memory.
Perhaps you use long wires, or a breadboard with bad contacts.
In most cases it should work without problem. When the initialization is okay then the wiring is probably okay. Therefor I suspect that the card itself or the partition on it, is not compatible.

and Ive tried formatting with SD formatter , no change .Im not using long wires since this is a closed circuit .and upto my knowledge arduino supports upto 8gb fine and good . and ive triple checked the connections , its good .Is there something with the memory ? Please do let me know If there is something

Could you try with another SD memory card ?
Is something else connected to the MISO ?
When the module has a voltage regulator, and a 3.3V and 5V pin, then you could try to power it with 5V to the 5V pin and leave the 3.3V pin of the module open.
The SD card module could be broken.

@ Jot Yeah ive tried it with 16gb memory card its working ,I dont know why its not working with 8 gb memory card

I'm glad it is working. Some memory cards are not compatible with the Arduino SD library, it happens.


text:
Arduino Sdcard database Library
Im using Arduino connected to an SD card and PIR sensor , and based on the inputs from the PIR sensor the data needs to be written on the sd card , It is done , but for retrieving the data from the SD card is there any library for arduino ? Ive seen Extended Database library ,since im retieving huge amount of data from the SD card and i should be able to do Lots of sorting operations based on the CSV values in the file , So can i do Sorting operations in  Extended Database library from an Sd card ive seen the Examples but it doesnt have any sorting operations ,Is Querying data from the SD card using this library is Possible ?ie)Selecting data Based on some Conditions even if it can be done is there any tutorial ? Or is there any other alternative Library? for this purpose . Thank You

When you are reading the data are you reading it on a PC or Arduino?  If its a PC, you are asking the wrong forum.  If its on an Arduino how are you going to load 32GB of data into 32kB of memory?

@Matt  No im loading the data from SD card into arduino that too after sorting and selecting a particular record and loading it into arduino

source: Stack Exchange

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

sort: votes


text:
WiFi connections being lost on connection reset
Look at the trick in the last few lines of this code:
#include <ESP8266WiFi.h>

const char* ssid = "xxxxx";
const char* password = "yyyyyyy";

// Create an instance of the server
// specify the port to listen on as an argument
WiFiServer server(80);

void setup() {
  Serial.begin(115200);
  delay(10);

  // Connect to WiFi network
  Serial.println();
  Serial.println();
  Serial.print("Connecting to ");
  Serial.println(ssid);

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
     delay(500);
     Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");

  // Start the server
  server.begin();
  Serial.println("Server started");

  // Print the IP address
  Serial.println(WiFi.localIP());
}

void loop() {
  // Check if a client has connected
  WiFiClient client = server.available();
  if (!client) {
    return;
  }

 int delays = 0;

 // Wait until the client sends some data
 Serial.println("new client");
 while(!client.available()){
    delay(1);
    delays++;  // First line of trick.
    if (delays > 10) {
       return;
    } // Trick ends.
  }
  ...// Handle some events.
}

Code works ok without the trick (only delay(1); inside the loop), but the problem is it gets stucked there, if some responses are asked from browser so that tab is closed in between the requests.
One response is for favicon:
 if (req.indexOf("favicon.ico") != -1) {
    String s = "HTTP/1.1 404 WTF Favicon !!\r\n";
    client.print(s);
    client.flush();
    return;
 }

I had also one similar response starting with 200 OK for certain URLs and then a response of plain json text.
I would like to know why my server gets stucked on this delay(1);? Also, when the trick is needed, what is correct delays value?
Also I did add a client.flush(); after every client.print();. May that affect anything?

WifiServer class has a bug that is now resolved. It causes a phenomenom described like follows:

When I send message to client via WifiServer.avalible, the user is disconnected from server - I can connect to it again, so server is not stopping.

And latest comment on topic is that it is corrected in latest commits.

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


text:
ESP8266 library / function for IR remote control
I am using IRremoteESP8266 for reverse engineering Hitachi AX-M76E mini stereos IR controller. I want to read the signal that the remote sends and send the same hexas to the stereos with IR led.
Please let me know if this is wrong site but I am trying to find out one thing on that IRremote library that is missing on it: code and protocol for Hitachi. There are even example code for Sony and other well known marks but Hitachi is missing.
Receiving IR is universal:
void loop() {
  if (irrecv.decode(&results)) {
    // print() & println() can't handle printing long longs. (uint64_t)
    // So we have to print the top and bottom halves separately.
    if (results.value >> 32)
      Serial.print((uint32_t) (results.value >> 32), HEX);
    Serial.println((uint32_t) (results.value & 0xFFFFFFFF), HEX);
    irrecv.resume();  // Receive the next value
  }
  delay(100);
}

With this loop I am able to fetch IR hex codes from remote control but with the next code I still cannot wake any action on stereos:
void loop() {
  Serial.println("NEC");
  irsend.sendNEC(0x00FFE01FUL, 32);// put the received hexa here
  delay(2000);
  Serial.println("Sony");
  irsend.sendSony(0xa90, 12, 2);
  delay(2000);
}

What you see every manufacturer uses their own protocol. I tested NEC because its protocol seemed to match what I received, still I did not succeed.
What may be the correct code, if I rewrite the sendNEC function so that I get the Hitachi one?

Now when I look this again, it seems that the problem is that the result code is 64 bit and NECsender parametr is 32. I have to verify that. Code that I received was longer than that I used in example.

HI, did you get solution of this problem. I'm using the same library to get the Panasonic AC remote IR code. It returns the different-different code for Same On/Off button with encoding protocal as UNKNOWN. I also get the Time line data, which is raw data.
Can I get the raw data from IR code?


text:
16x2 LCD showing blocks under text
I have a LCD connected to a Arduino Mega 2560 using the instructions in LiquidCrystal library. It is not the first time I am using a 16x2 LCD but I never have encountered a problem like this. When I first connect the Arduino Mega to PC I see a row of blocks in first row of LCD which looks like normal to me. Then after that there is a block of white under each character.
Now I have searched a little and saw whole blocks which was due to bad soldering or bad wiring or etc. I have checked soldering and wiring twice. used 3 different LCD's and 2 different Mega's and it is still the same.
Any suggestions?
These are the images from when I turn it on:

[SOLVED] Update :
Looks like the POT was broken and did not respond the way it used to. So i replaced V0 with a 2.5k resistor and connected them to GND.
Here is the updated image :

can you please post an update later with adjusted contrast which looks fine?

@user1306322 updated with image

My LCD display shows gibberish character. How do I troubleshoot?

The row of white blocks is what you get before the screen's initialized. It's normal.
The shadow behind the characters is because you have the contrast turned up too high. Adjust it down a little.

If your contrast is not adjustable by a pot, there's a resistor that goes on the contrast pin that controls the level of contrast, which is what is causing the dark blocks.

Some LCD modules also have software contrast adjustment. Read the datasheet

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


text:
How do I send HTTP request using ESP8266 to other port than 80?
I currently have a working connection to my ESP8266 module.
However, I can only connect to a server using the port 80, is it possible to choose a different port?
I can connect using AT+CIPSTART="TCP","192.168.122.46",80,
but I get an ERROR CLOSED when using AT+CIPSTART="TCP","192.168.122.46",8090 for example
Also, how do I send an HTTP request using the AT+CIPSENDcommand?
UPDATE: Stupid me, it was just Firewall blocking it...

Are you certain there is a port open and listening on 8090 at the target machine, and it's bound to the right outward-facing interface?

It was just firewall blocking in

authors: זאב ליבוביץ zevlib


text:
How can I implement a parking counter with multiple entrances and exit?
I'm relatively new to arduino projects and am trying to solve a real world problem on a parking lot space counter.
My Idea is to have a sensor placed on the entrances and exit to count the total number of cars in the parking lot.
Now there are several codes online but they only implement for 1 entrance.
Scaling for 4 entrances:

Would it be ideal to implement 1 main unit with multiple cables running to each sensors placed on the entrances and exits of the parking lot.

Given that the parking lot is huge:

Is there a wireless way to transmit data from each sensor to the central unit ?

I'm welcoming any recommendations regarding this project.
EDIT:
This is for an actual prototype. I've scoped around the garage to find that I only need  multiple entry exit (2) system for the ground floor. Rest of the two floors have their own 1 entry and exit points.
The entrance and exit are the same point so I was thinking of a bidirectional sensor.

Does 10 feet of width pose a problem for the sensor ?
  Could I instead use two bi-directional sensors placed on either sides of the entry and exit, and then hook them up to the same input in the Arduino ? So incase 1 misses the other one registers.

Edit 2: The parking deck is big enough to hold about 20-25 cars on each of the 3 floors. I don't know the exact measurement though

Besides Sensors could I use a wire on the floor to register when a car crosses over ? Would that be easier?

Theoretically, the sum stays the same. If you count how many cars go in, and how many go out, it won't matter where they go in or go out.

Mind that if it misses one car (or the message gets lost), the counter will become offset. And the system can't really recalibrate itself. You'll probably want to have persistant/failsafe storage, to avoid the system being desynchronised after a power failure.

You could go with wireless, as long as there is bidirectional communication, you can make the counter "acknowledge" incoming or outgoing cars. If the connection is lost, you'll want to retransmit the message until it is accepted. (This may also lead to desynchronisation).

Is it for a prototype or an actual product?

personally, i would just use ESP8266s and have one host an AP that the other sensors connect to

Define "huge"..


text:
ATmega AVR frequency measurement with timer/counter
I've been rehashing some existing libraries I found on some obscure forums to measure a frequency on digital pin 5, using the ATmega328P/ATmega2560 Timer/Counter modules and an interrupt based approach in order to be able to measure frequencies up to 4MHz(-ish). However, using the code described below, the results are off by a factor of exactly 100. I used a frequency generator to accomplish these readouts. Here is an example of what I've been getting back when generating a 5000Hz square wave (50% duty cycle):

Can someone please point out what might be wrong. I've read the ATmega328P datasheet multiple times by now and it should just work! This is very strange.

Edit:
  As it turns out the AWG I use has a blantant software bug which causes it to generate a wave with a period that's 100 times too long (see picture below). Nevertheless as Edgar pointed out I made some pretty big mistakes by not taking into account race conditions. Therefore the code below has been updated. Also, the test program has been updated to generate a 50% duty cycle square wave @5000Hz for testing purposes as suggested by Edgar.

This is the header file:
#ifndef FreqCounter_h
#define FreqCounter_h

#include <avr/interrupt.h>
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
namespace FreqCounter
{
    extern volatile unsigned long f_freq;
    extern volatile unsigned char f_ready;
    extern volatile unsigned char f_mlt;
    extern volatile unsigned int f_tics;
    extern volatile unsigned int f_period;

    void start(int ms);
}
#endif

This is the source file:
#include <FreqCounter.h>

volatile unsigned long FreqCounter::f_freq;
volatile unsigned char FreqCounter::f_ready;
volatile unsigned char FreqCounter::f_mlt;
volatile unsigned int FreqCounter::f_tics;
volatile unsigned int FreqCounter::f_period;

void FreqCounter::start(int ms) {
    f_period = ms;
    GTCCR = (1<<TSM) | (1<<PSRASY) | (1<<PSRSYNC); //halt all timers

    //set TC1 to normal mode => TOV1 flag set at TOP = 0xFFFF
    TCCR1A &= 0x00; //reset TC1 control register A
    TCCR1B &= 0x00; //reset TC1 control register B

    //set TC1 to use external clock source, clocked on rising edge
    TCCR1B |= (1<<CS10);
    TCCR1B |= (1<<CS11);
    TCCR1B |= (1<<CS12);

    //reset TC2
    TCCR2A &= 0x00; //reset TC2 control register A
    TCCR2B &= 0x00; //reset TC2 control register B

    //set TC2 to CTC Mode with TOP = OCR2A => counter cleared on reaching TOP
    TCCR2A |= (1<<WGM21);

    //TC2 is in CTC mode => set value of OCR2A = TOP
    OCR2A = 124; //TOP is reached every 125 counts (starting from 0)

    //set TC2 to use a prescaler of 1 => 16MHz / 128 = 125kHz
    TCCR2B |= (1<<CS20);
    TCCR2B |= (1<<CS22);

    f_ready = 0; //reset ready flag
    f_tics = 0; //reset TC2 interrupt counter

    //synchronize the value of both timers
    TCNT2 = 0;
    TCNT1 = 0;

    //clear interrupt flags
    TIFR2 |= (1<<OCF2A);
    TIFR1 |= (1<<TOV1);

    TIMSK2 |= (1<<OCIE2A); //enable TC2 Output Compare A interrupt => triggered on reaching TOP = OCR2A
    TIMSK1 |= (1<<TOIE1); //enable TC1 overflow interrupt => triggered on reaching TOP = MAX = 0xFFFF

    GTCCR &= 0x00; //restart all timers => start counting
}

/*
 * This ISR is triggered by TC2 every 1ms because
 * TC2 increments with a frequency of 16MHz / 128 = 125KHz
 * and reaches TOP every 125 counts
 * => trigger frequency = 1kHz
 * => trigger period = 1ms
 *
 * This ISR handles the Gate Time generation
 */
ISR(TIMER2_COMPA_vect)
{
    //increment number of TC2 interrupts (triggers when reaching TOP = OCR2A)
    FreqCounter::f_tics++;

    /*
     * If branch evaluates as true if given gate time (f_period) equals
     * amount of milliseconds TC2 has counted (= f_tics)
     */
    if (FreqCounter::f_tics >= FreqCounter::f_period)
    {
        //end of gate time => measurement ready
        TCCR1B &= ~0x07; //set TC1 to no clk source => TC1 stops counting
        TIMSK2 &= ~(1<<OCIE2A); //disable TC2 Output Compare A interrupt
        TIMSK1 &= ~(1<<TOIE1); //disable TC1 overflow interrupt
        FreqCounter::f_ready = 1; //set software flag for end of gating period

        //increment on overflow of TCNT1
        if (bit_is_set(TIFR1, TOV1))
            FreqCounter::f_mlt++;

        //calculate frequency
        FreqCounter::f_freq = 65536 * FreqCounter::f_mlt;
        FreqCounter::f_freq += TCNT1; //add value of TC1
        FreqCounter::f_freq = (long)(FreqCounter::f_freq * 1000.0 / (double)FreqCounter::f_tics);
        FreqCounter::f_mlt = 0;
    }
}

ISR(TIMER1_OVF_vect)
{
    FreqCounter::f_mlt++;
}

This is the test program:
#include <FreqCounter.h>

long frq;

void setup()
{
    //generate a 5 kHz square wave on OC0B = digital pin 5 = T1
    DDRD |= _BV(PD5); //PD5 = OC0B as output
    TCCR0B = 0; //stop timer
    TIMSK0 = 0; //disable overflow interrupt
    OCR0A = 50 - 1; //period = 50 * 64 cycles
    OCR0B = 50 / 2 - 1; //50% duty cycle
    TCCR0A = _BV(COM0B1) //non-inverting PWM on OC0B
        | _BV(WGM00) //fast PWM, TOP = OCR0A
        | _BV(WGM01); //...ditto
    TCCR0B = _BV(WGM02) //...ditto
        | _BV(CS00) //clock at F_CPU / 64
        | _BV(CS01); //...ditto
    Serial.begin(57600);
    Serial.println("Frequency Counter");
}

void loop()
{
    FreqCounter::start(1000);
    while (FreqCounter::f_ready == 0);
    frq = FreqCounter::f_freq;
    Serial.println(frq);
}

PS: This is my first ever post on this forum. Feel free to comment on the contents of my question. Tips as to how I might improve future questions are always welcome. Have a great day!

Try swapping the order of operations to FreqCounter::f_freq * 1000 / FreqCounter::f_tics

@Gerben unfortunately changing that didn't make a difference and if it did that would've been completely irrational. Thanks anyway!

Not completely irrational. The variables are integers, but you want the calculation to be performed as floating point. Swapping some parts around will negate the need for floats all together, as demonstrated. Too bad that didn't help here. Have you tried measuring different frequencies? Are the all of by a factor of 100?

@Gerben you're right indeed. And to answer your question: yes I have. All other frequency measurements are also off by a factor 100. That's what's strange to me actually. This leads me to believe there might be some default prescaler weirdness I'm not aware off. I'm used to working with STM's and have worked with XMEGA devices in the past but since an Arduino has some pretty annoying default settings I've been bumping into these sorts off things all the time lately. I'm commited to using the Arduino platform for this project unfortunately.

The code looks okay to me. Very weird indeed. What happens if you change the period (e.g. FreqCounter::start(100);)

@Gerben the same problem with a different period. Of coarse the precision also changes but that is to be expected. A period of 100ms gives a precision of 1000Hz but it should be 10Hz.

Not only does your code look fine, it works perfectly well here, on my Arduino Uno compatible board (ATmega328P). You are sending the square wave into pin 5, right?

Do you live in a place of the world with 50 Hz mains? What are the low and high voltages of your square wave? Does your frequency generator share a common ground with your Arduino? Is it sitting close to the event horizon of a black hole?

@EdgarBonet Positive on the 50 Hz mains and I'm not sure but I might be living on the edge of a black hole because I'm constantly wondering how time can go by so slowly, especially when I'm trying to fix sh*t that's just supposed to work ;). They do have common grounds and I'm definitely using pin 5. I will check the frequency of the generated pulse with my oscilloscope (as I already should've done). Also I'm generating a wave on TTL levels.

I am posting this as an answer, just because it doesn't fit as a
comment. But more than an answer it is intended to be a debugging help.
First, I would like to point out that you can use the same Arduino to
both generate the test signal and read it. This can be done by
configuring Timer 0 (the last one you have left...) to output the 5 kHz
square wave on OC0B (digital pin 5), and wire this signal to pin T1
which is... also digital 5. No wiring needed then! You can do this by
adding the following to your test program's setup():
// Generate a 5 kHz square wave on OC0B = digital pin 5.
DDRD  |= _BV(PD5);    // PD5 = OC0B as output
TCCR0B = 0;           // stop timer
TIMSK0 = 0;           // disable overflow interrupt
OCR0A  = 50 - 1;      // period = 50 * 64 cycles
OCR0B  = 50/2 - 1;    // 50% duty cycle
TCCR0A = _BV(COM0B1)  // non-inverting PWM on OC0B
       | _BV(WGM00)   // fast PWM, TOP = OCR0A
       | _BV(WGM01);  // ...ditto
TCCR0B = _BV(WGM02)   // ...ditto
       | _BV(CS00)    // clock at F_CPU / 64
       | _BV(CS01);   // ...ditto

Then I would like to point out a couple of bugs in the library you are
using. First, there is an off-by-one error: the program is counting one
millisecond too much. This can be fixed by moving the lines
//increment number of TC2 interrupts (triggers when reaching TOP = OCR2A)
FreqCounter::f_tics++;

from the bottom to the top if ISR(TIMER2_COMPA_vect).
Next, there is a race condition between the ISRs. Race conditions are
nasty bugs because they are hard to reproduce and most of the time you
don't see them. And then the program just fails at a random time after
many tests showed it works fine.
Here it works as follows: let's say that after the required time has
elapsed, TIMER2_COMPA fires and right after that TIMER1_OVF fires
also. This second interrupt is put on hold (it's a pending interrupt)
while TIMER2_COMPA_vect runs through its prologue. Then you compute
the frequency based on FreqCounter::f_mlt (which has not been updated
to account for the overflow) and TCNT1 (which has already overflown to
zero). Thus you get an incorrect result. Not only that, the overflow
flag remains set, so the ISR will run right away as soon as the
interrupt is enabled again by your next call to FreqCounter::start().
And again you get an incorrect result.
The fix is two fold: first you have to detect the pending interrupt
condition in ISR(TIMER2_COMPA_vect): after stopping the timers and
before computing FreqCounter::f_freq, you need this:
// Did we miss an overflow?
if (bit_is_set(TIFR1, TOV1))
    FreqCounter::f_mlt++;

Next, you have to clear the interrupt flag. This is customarily done
right before enabling the interrupt, and just to be safe you do it for
every interrupt you enable. Thus, in FreqCounter::start(), right
before touching TIMSK2 and TIMSK1, you would:
// Clear interrupt flags.
TIFR2 = _BV(OCF2A);
TIFR1 = _BV(TOV1);

There are a couple of other minor issues, like the statement
TCCR2A &= ~(1<<WGM22); which makes no sense (the bit belongs to
another register). But given that this, like a few other statements, has
no effect whatsoever, it should not affect the working of the program.
It does reveal sloppy programming though.

Wow I can't believe the level of noobishness I displayed by neglecting to even think about race conditions. If my former professor in computer sciences knew about this he would strangle me with his bare hands. Also, I should really check my code before running off to forum threads. I will make the suggested corrections at once and report back to you. If it's fixed I will edit my post. Thanks in advance.

authors: Алексей Репич


text:
How to prevent modify library of arduino?
For some reasons of security, I created library for everybody to use, but I don't want people change my library, cause it make device not work. I search around but still not working. Do I need to set password for library or make it unreadable or make it can not modify or another way that you can give the direction ?
P/s: Think like a hacker, I can change library and make an attack to the server from library.

why is it a problem for you if someone changes the library and the device fails as a result?

it make device not work

@Quang, that does not answer my question ... you already said that the device may not work .... why is it your problem? ... why is it not the problem of the person that changed the library?

it make device not work - what device? A few more details, please.

Maybe if you provide a precompiled library for the users. Though I'm not really qualified in that field.

See my amended answer for my thoughts about your "hacker" comment.

No, you can't do that. How could a library work if it is unreadable?
If you don't want people changing it, don't publish it.
If you publish it you could put a disclaimer on it:

If you change my library, it may stop working.

(Added to question two days later)

P/s: Think like a hacker, I can change library and make an attack to the server from library.

Yes, but, if you distribute the original library, then someone would have to download it, change it, and then attack themselves with it!
And if your library does something to do with servers (you haven't said what your library does) then someone could make a similar library, and build the attack code into that. Hacking your particular one wouldn't be required.
My other issue is: If your library is a secret, that is, I can't read its source code, then I might presume that your library is where the hack is. At least if people get the source code they can read it and check it.

Later versions of the IDE have the ability to use pre-compiled libraries.  This means that the end user only gets the compiled version of your library (a .a file) rather than the source code.
Modify your library.properties file to include dot_a_linkage=true. If you don't have a library.properties file you need to make sure you create your library in 1.5.x format.
Then compile your library in the normal way. This will result in a .a file somewhere in the build  tree which gets linked with your sketch.  You need to grab that .a file.
Next make a new copy of your library that has just the header file (needed for compilation) and the .a file (needed for linking). No .cpp files.
Now you in the new library.properties file you add precompiled=true.
As long as you lay out the files right it should now compile using the precompiled .a file.
You can read more about the library.properties contents here.

Hmm, I didn't know that.

@NickGammon it's not something that is well documented, and not used much. I haven't used it myself, just inferred it fun the spec.

This answer should probably mention that this is only a mild deterrent, as it's relatively easy to disassemble and edit a .a file.

@JosephSible It's simple to extract the .o files from a .a file, yes. Less easy to disassemble those .o files back into source code, modify them, and recreate them. I'd hardly call it a "mild" deterrent.  True, anything can be reverse engineered if you're determined enough - but we're talking about an Arduino library here - with the associated level of competence that a typical Arduino user has...  I.e., a .a file is a complete mystery to them...

Distribute your library in compiled format. The when code is compiled it's "translated" from "human readable code" to "machine code". Machine code is almost impossible to read and understand without years of experience.
There always is a possibility of decompilation. There are programs called decompilers that change any "machine code" into "human readable code". The resulting code is different then your original code, and there is nothing you can do to prevent decompilation because in the end Arduino has to have that "machine code" to know what operations to execute, and it's impossible to have it encrypterd in any way.
You can make always decompilation more troublesome. There is a procedure called "code obfuscation". You can manually, (or using a specialized code obfuscation software) make the "human readable" code no longer readable by humans. They can add extra variables, extra methods change constants to variables that are generated by completely unrelated parts of code. This will also change machine code, and make the code after decompilation much harder to understand. Unfortunately it will also complicate the machine code and make library run much slower.
Fun Fact!
There exists a competition in code obfustation https://www.ioccc.org/
And this is a valid C code that you can compile and run. https://www.ioccc.org/2014/sinon/prog.c

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


text:
Sending a string to arduino and is not reacting to it
I am trying to move servos with a VR headset, I am using the Unreak 4 Arduino Plugin, but that is not the problem. I send the rotation Y and Z from the headset, convert them to int and then send them together as an int separated by commas. Here's what it does: It gets the rotation Z, it converts it to int, then it converts it to String, I add a comma at the end of the String, then I add the rotation Y after the comma, and it returns me: "rotationZ","rotationY" (the values between " are the numbers sent by Unreal to arduino), these results may come in negative or positive value.
Then inside arduino I have this code:
#include <Servo.h>
#include <SoftwareSerial.h>

Servo servo1;
Servo servo2;  // Crea un Objeto servo

int angle = 10;
int posicion = 10;    // Variable de la posicion del servo

String user_input1;

int r;
int g;

void setup()
{
  Serial.begin(9600);
  servo1.attach(2);  // Selecionamos el pin 2 como el pin de control para el servo
  servo2.attach(3);  // Selecionamos el pin 2 como el pin de control para el servo

  servo1.write(0);
  servo2.write(0);

  Serial.setTimeout(5);
}

void loop()
{
  if (Serial.available() > 0)
    {
  String firstValue  = Serial.readStringUntil(',');
 // String first = Serial.readString(); //next character is comma, so skip it using this
  String secondValue = Serial.readStringUntil(',');
//  String second =  Serial.readString();

   r = firstValue.toInt();
   g = secondValue.toInt();
    }
  if (r < 0)
  {
    r = r * -1;
  }

  if (g < 0)
  {
    g = g * -1;
  }

  Serial.println(r);
  Serial.println(g);

  servo1.write(r);
  servo2.write(g);

}

As you can see, it gets the numbers between the commas and then it converts them to int, and then it applies to the servos which are in pins number 2 and 3 (yes, everything is plugged in correctly), which it should then move them acordingly the position of the VR headset, I've also tried to make them always receive positive results but still doesn't work. I have searched over the internet on how to separate a string divided by commas and I still don't know if it's correctly done.
EDIT: I also tried to input the numbers in the console manually, and it gets them right and moves the servos but it still doesn't work with the VR. I also added Serial.setTimeout(5) to try if it works that way.
Thanks in advance for reading this bunch'o text about my problem.

I also tried to input the numbers in the console manually, and it gets them right and moves the servos but it still doesn't work with the VR.

This implies that the problem is in the code sending the data.  Get a terminal emulator program and hook that up to the code generating the data from the VR headset (you will need 'local echo' turned on).  I suspect you will see the headset is not writing the data in the format you expect.  Also it will let you capture a real sample of data that you can feed into you program to generate a repeatable test.
If this isn't the fault, then please can you post the a few lines of data so we can see whats wrong.

I have to apologize but, what do you mean by "terminal emulator program"? I am kinda new to this kind of programming with arduino.

I should apologise 20+ years of embedded development and I forget things like speaking English :)  What you need is a program that you run on your "PC" and it lets you talk to the serial port.  The serial monitor is a sort of basic terminal emulator, but I don't think it would work in this case.  So for Windows try "Terraterm" [https://ttssh2.osdn.jp/index.html.en] or "Putty" [http://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html].  (Linux and Mac will need advice from someone else, sorry)

authors: Сергей Скориков


text:
What are the problems with using an Arduino in a production environment?
I am thinking about making a real project using arduino to earn money.
What could be the objective reasons (from both a technical and a business perspective) to not use an Arduino in a real profitable project?

There's pro products using OEM arduinos; 3d printers, custom home automation installs, cosplay accessories, and quadcopter controls come to mind. If your product's markup can eat the higher labor and parts cost compared to a lower-level setup, or you need fewer than 100 of something, It can be a viable option no doubt.

We've had a complaint that this question should not have been put on hold because it is a useful question. I'm inclined to agree with that, however questions about "is it a good idea" are indeed likely to be opinion-based. If enough people vote to re-open the question then it will be re-opened by the system. You may want to re-word along the lines of "what are the problems with using an Arduino in a production environment?" and omit things like "is it a good idea?". One issue I can see is that the pushing in of connectors into the Arduino "pins" could be problematic if there is vibration.

Even better would be to describe the particular project you're thinking of and the particular Arduino board you're thinking of using in it and ask "what would be the problems with this project if used with this board."

My 2 cents... I did VTC but also upvoted the answers by Majenko and dannyf. The OP doesn't specify whether he's planning to use an Arduino in a mass produced product or using it in a one-off project. Both cases are commercial projects but the implications are quite different. Also, what might be worth knowing (and objective too) could be the actual problems encountered by someone who actually used Arduino in a commercial project or, alternatively, the reasons why someone who considered Arduino for a commercial project ended up ruling it out.

I want to know if there is anyone that has used Arduino boards in a real project?

I have seen it being done, quite a few times.

What are the problems that you have faced?

Pros:

quick to market;
low cost accessories;
large code base to drop from;
...

Cons:

only workable for certain applications -> high cost per mcu (vs. bare chips), no possibility of passing certification of any rigor, no respect from others / clients, ...
quite inflexible an eco-system: porting code to / from others can be problematic.
poor project management capabilities.
...

Each of those pros / cons can be addressed and may not be relevant for your particular application.

Add big or bulky boards and high power requirements to list of cons.  Also assembly time can be a problem (lots of through-hole pins to solder, to connect eg a Nano or Micro to a project's PCB)

As a rule, no it's not a great idea.
Arduino boards are a prototyping platform. They are designed to make trying ideas out easy, not for permanent installation in a device. That's not to say you can't permanently install it in something of your own making, but when it comes to making a professional product it's not good, for a number of reasons:

An Arduino board is expensive compared to a plain MCU.
It's not a professional image.
It's not (typically) rugged and reliable enough.
Manufacturing something around a board like an Arduino is expensive.

The most professional way of using an Arduino would be to use something like an Arduino Mini and directly mount it on a custom PCB. But since you are making a custom PCB anyway, why would you incur the extra expense of an Arduino board when it is far cheaper to just build the required components directly into your board design? Also, when bulk manufacturing, you need to have as much of the build automated (i.e., surface mount to be populated by a pick-and-place machine) in order to keep costs down, and having to manually mount an Arduino onto a board adds extra expense (you have to pay a person to do the job themselves).

No, you don't want to manufacture a commercial device with the ATMega328P. If it had to be a '328 then it wants to be the ATMega328-MU or at a pinch the ATMega328-AU. Through hole is very expensive to manufacture.

That is pretty much what the entirety of my post is saying. Don't use a dev board, design the required components into your own circuit.

i just think mentioning a specific google-able term like the uno-acting atmega328 allows more follow-up

I am not about to recommend a specific chip to use, and certainly I wouldn't recommend an ATMega.

The ATmega328P is available as a surface-mount chip.

@EdgarBonet No it isn't. The ATMega328-PU is a SPDIP. The -MU is a QFN, and the -AU is a TQFP. The letters are important.

Yes, it is. C.f. the datasheet. Every ATMega328P-XX, where “XX” is anything but “PU”, is surface-mount.

@EdgarBonet Oh, it seems I am looking at the wrong page. Yes, you are right, there is the 328-* and the 328P-* (idiotic Atmel and their crappy naming scheme). They even have the 328PB-* now.


text:
move forward and turn right
i have a project about making an obstacle avoiding robot. But this one is a bit special. I want the robot to move forward and when an object is close to it, to turn right. https://i.sstatic.net/Vfnzi.png
#define echoPin 7 // Echo Pin

#define LEDPin 13 // Onboard LED

#define m1a 4

#define m1b 3

#define ena 9

#define m2a 2

#define m2b 5

#define enb 8

int maximumRange = 200; // Maximum range needed

int minimumRange = 0; // Minimum range needed

long duration, distance=0; // Duration used to calculate distance

void setup() {

Serial.begin (9600);

pinMode(trigPin, OUTPUT);

pinMode(echoPin, INPUT);

pinMode(LEDPin, OUTPUT); // Use LED indicator (if required)

pinMode(m1a, OUTPUT);

pinMode(m1b, OUTPUT);

pinMode(m2a, OUTPUT);

pinMode(m2b, OUTPUT);

pinMode(ena, OUTPUT);

pinMode(enb, OUTPUT);

}
  void moveForward()
 {

 digitalWrite(LEDPin, LOW);

 digitalWrite(m1a, LOW);

 digitalWrite(m1b, HIGH);

 analogWrite(ena, 180);

 digitalWrite(m2a,HIGH);

 digitalWrite(m2b,LOW);

 analogWrite(enb,180);

 }
 void turnRight()

{

 digitalWrite(LEDPin, HIGH);

 digitalWrite(m1a, LOW);

 digitalWrite(m1b, LOW);

 analogWrite(ena, 100);

 digitalWrite(m2a,HIGH);

 digitalWrite(m2b,LOW);

 analogWrite(enb,100);

 }

void loop() {

 digitalWrite(trigPin, LOW);

 delayMicroseconds(2);

 digitalWrite(trigPin, HIGH);

 delayMicroseconds(10);

 digitalWrite(trigPin, LOW);

 duration = pulseIn(echoPin, HIGH);

 //Calculate the distance (in cm) based on the speed of sound.

 distance = duration/58.2;

if (distance <= maximumRange && distance >= minimumRange){
    turnRight();
}
else {
/* Send the distance to the computer using Serial protocol, and
turn LED OFF to indicate successful reading. */
 moveForward();
}

//Delay 50ms before next reading.
 delay(50);
}

m1a,m1b,m2a,m2b are the motor pins. ena, enb are the pwm pins from the driver(l298n). I am currently using an arduino uno, and hc-sr04 ultrasonic sensor and a l298n motor shield

Please edit your question (click "edit") and include the information from your comment in the body of the question.  Also, please edit your question and mark the code as code.  When including code in a stackexchange question or answer, first paste the code into the question or answer editing box; then in that editing box, highlight the code and press ctrl-k. Or highlight the code and click the {} icon in the toolbar at the top of the editing box. To highlight text click-drag across it or use the arrow keys while holding the shift key.

I want the robot to move forward and when an object is close to it, to turn right.

How close do you want the robot to be to the obstacle? You should at least declare some form of threshold to determine what values are considered "close". (Maybe a closeThreshold variable)

while(distance>=maximumDistance) { moveForward(); if(distance<=maximumDistance) break; } turnRight();

As for the code you have posted, why not use a simple if else function with a closeThreshold variable instead of a while loop?
...
void loop() {
delayMicroseconds(2);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
duration = pulseIn(echoPin, HIGH);

 //Calculate the distance (in cm) based on the speed of sound.

 distance = duration/58.2;
 if(distance<=closeThreshold) {
 turnRight();
 } else {
 moveForward();
 }
}

oh well..the robot now is stuck right now.

Stuck as in not moving at all or stammering at a particular spot?

Not moving at all

I created a variable called maximumDistance, and if the current distance is smaller than that, the obstacle is considered close enough. It's the same with the closeThreshold variable

nope. it's not working at all

I made an edit in the source code and nothing happens. I made a function which calculates the currentDistance, but no results so far

Is there any values coming from the ultrasonic sensor?

Actually no. I mean i used the serial.print() function and it just displays text from the if statement in the serial monitor

OK...i tried with a sample code and now i get values from the sensor

Integrate your main code with the sample code, the robot should be able to move

So...i just did what you said. No results. With the sample code works as charm(The values come continuously and in the implemented version, they come one by one and the motors are just stuck)

http://arduinobasics.blogspot.nl/2012/11/hc-sr04-ultrasonic-sensor.html this is the sample code

i removed the functions and tested the code just like that

I think the problem lies in your moveForward() and turnRight() function: you are delaying 1s everytime you call the function. So the whole loop delay would be ~1 second per cycle. Maybe reduce the delay in it?

Plus can you update the implemented version of code into the body of the question as an update? Easier to see what you have changed.

ok so...any ideas? removing the delay didn't work


text:
radio.write () always returns 0
I'm trying to send a char [] through an NRF2401 but the radio.write () method always return 0. Check that msg contains the message read from str.
#define TAM 50

RF24 radio(9,10);

const uint64_t pipe = 0xE8E8F0F0E1AA;

char  msg[TAM];

void setup() {

  Serial.begin(9600);

  radio.begin();

  radio.openWritingPipe(pipe);
}

void loop() {
    if(Serial.available() > 0){
      String str = Serial.readString();
      str.toCharArray(msg,TAM);
      if(!radio.write(msg, TAM)){
        Serial.println("Message not send");
      }
      else
        Serial.println(msg);
    }
}

What am I doing wrong?
Edit1:
What I have noticed, is that the first time I was allowed to send it but the others no longer.
Edit2:
Remove the keyboard input by a char [] and sent it to without problems. Why can this be? Anything else happen when I make a keyboard entry?

Check the max payload size. The NRF24L01 does not allow more than max 32 bytes in total.

If you want to send a longer message you will have to split it into several messages and then merge them at the receiver.

Is there another Arduino receiving the message? The nrf24 will check if it receives an ACK message back. If it doesn't the write method will return 0

@Gerben Yes, there is another arduino that acts as receiver. Also check and radio.write returns 0.

@MikaelPatel Yes, I have sent a single char to verify this and I continue the same thing.

I hope you resolved your issue by now, but I had the same problem with an Arduino UNO/nRF24l01+ combination and this question was one of the search results.
In my case, the write() call returned false, but the receiver received the message.
As soon as I added one of the ubiquitous Adapter Boards into the mix the write() call started returning true.
My uneducated guess is that the sending and then the switch from transmit to receive and then waiting to receive the ACK used a bit too much power or something like that.
In any case, even though everyone recommends adding a capacitor and I had the adapter boards on hand, I had thought to tough it out without one and see how far I could get.
I kicked myself for the wasted time, but I learned a lot in the process and I'm having a lot of fun with the transceiver boards now. I'm glad that I didn't just shrug and say "well the message got through so who cares?"


text:
GPS module not working with sensor
I am connecting my Soil Moisture Temperature Sensor SHT10 with GSM Module SIM900A and GPS GY-GPS6MV2. Individually, all components work properly and give proper values. But when I interface all three components with Arduino, only Temperature sensor seems to work and GPS does not give any values.
Even If I connect only SHT10 and GPS with Arduino Uno (without GSM), only SHT10 gives values but GPS doesn't.
My code is:
#include <AltSoftSerial.h>
#include <TinyGPS++.h>
#include <SHT1x.h>

AltSoftSerial gpsSerial (11,12);

TinyGPSPlus gps;

#define dataPin 6
#define clockPin 7
SHT1x sht1x(dataPin, clockPin);
float TEMP, HUMID;

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

void loop()
{
TEMP = sht1x.readTemperatureC();
HUMID = sht1x.readHumidity();
Serial.println(TEMP);
Serial.println(HUMID);
gps_value();
}

void gps_value()
{
while(gpsSerial.available())
{
gps.encode(gpsSerial.read());
}

if(gps.location.isUpdated())
{
Serial.println("Latitude: ");
Serial.println(gps.location.lat());
Serial.println("Longitude: ");
Serial.println(gps.location.lng());
Serial.println("Altitude Feet: ");
Serial.println(gps.altitude.feet());
Serial.println("Horizontal Dilution of Precision: ");  //lower the better
Serial.println(gps.hdop.value());
Serial.println("");
}
}

What is happening here ?
Datasheet of SHT10

DId you try to connect the GSM and GPS modules without connecting the temperature sensor?

@Majid_L Yes, I have done that. And it works.

You should share the temperature sensor circuit and the power supply you are using. From the info you have given till now I think it is a problem related to hardware not software. It could be over loading the power supply or maybe the arduino is getting reset.

@Majid_L I am powering Arduino with my PC itself.

As already mentioned this seems to be a current related problem. You are powering your Arduino over Usb. The sensors themselves do work fine. Yet connecting all of them seems to draw too much current so they won’t work properly. (See this post for more information on current.

You could have used SoftwareSerial instead of AltSoftSerial.Since you are using AltSoftSerial please go through its library file to check how you need to deal with it.
For Software Serial you need to use predefined Rx , Tx pins of Arduino rather than defining any other pins of it for Rx,Tx
for connecting those to Rx Tx of tempterature sensor.
For GPS try to define any 2 pins of Arduino as Rx Tx so that you can connect them to Rx Tx of GPS.Hope this helps you.

NEVER use a software serial library on the HardwareSerial pins (RX pin 0 and TX pin 1).  And SoftwareSerial is the worst alternative.  See this answer for more info.


text:
GSM SIM900A SMS content not displaying
I am trying to read messages sent from my mobile to a GSM SIM900A module on my Arduino Serial monitor. Neither does the AT+CMGR command nor does the AT+CMGL command display SMS content. I also tried increasing the receiver buffer size in the SoftwareSerial Library but to no avail. I am simply trying to read 'check123'. I want to further store the SMS received as a string for further processing. But I am stuck with no display of SMS content on the serial monitor.
My code is:
#include <SoftwareSerial.h>
SoftwareSerial mySerial(9, 10);
String content = "";
char character;
int i;

void setup() {
  mySerial.begin(9600);
  Serial.begin(9600);
  delay(100);
}

void loop() {
  ReceiveSMS();
  delay(2000);
}

void ReceiveSMS() {
  mySerial.println("AT+CMGF=1");
  delay(2000);
  toSerial();
  mySerial.println("AT+CPMS=\"SM\",\"SM\",\"SM\"");
  delay(2000);
  toSerial();
  mySerial.println("AT+CMGL=\"ALL\"\r");
  delay(5000);
  toSerial();
  mySerial.println("AT+CMGD=1,4");
  delay(2000);
  toSerial();
}

void toSerial() {
  while (mySerial.available() != 0) {
    Serial.write(mySerial.read());
  }
}

Output is:

Edit:
SoftwareSerial.cpp file. I have marked the area where I have changed the value from 64 to 256 according to some previous help post.

It is typically a buffer overflow issue. what is your current rx buffer size now?

I have changed it to 256 from 64

you mean you have changed softwareserial rx buffer or hardware serial rx buffer?

I have added the image of SoftwareSerial.cpp file and the change I made in it.

Your code is absolutely correct. As I tested it with my Mega with Serial3 connected to GSM SIM900. I think there is something fishy about SoftwareSerial. Double-check the location of SoftwareSerial.

C:\Program Files (x86)\Arduino\hardware\arduino\avr\libraries\SoftwareSerial\src

Maybe you can see if RAM usage is exceeding the safe limit. Here is my output:


text:
How do you balance an Arduino quadcopter using calculated gyro values?
I was working on an Arduino quadcopter project. I setup all my hardware and was having balancing problems with my software end. I am using an MPU-6050 gyro and accelerometer. I have calculated the angle of the quad in relation to the ground and was trying to implement these values by adjusting the output values to each of the four motors.
Here is some of my code:
    x=(-computedGyroAngleX-3.5)*10;
    y=(-computedGyroAngleY-2)*10;
    esc1.writeMicroseconds(rc_values[RC_CH1]+x-y);
    esc2.writeMicroseconds(rc_values[RC_CH1]+x+y);
    esc3.writeMicroseconds(rc_values[RC_CH1]-x-y);
    esc4.writeMicroseconds(rc_values[RC_CH1]-x+y);

If the quad is leaning forward I increase the power at the front of the quad and reduce it at the back. I do the same for the y axis. But I run into problems when I test out the quad. It flips over to the side or forward. How would I fix this?

Hello and welcome. Could you please edit in another line break near your code section... to make code formatting work (I cannot do the edit due to the six-character rule).

Such task is usually done by PID regulator (library) and to save you a lots of time by trying to tune it correctly also by PID Autotune library

That was happening with me too. Check if the weight distribution of the drone is perfect. Lets say if the battery is placed a little more to one side of the frame than the other side, your drone will try to hover from the other side.
The center of gravity should be taken care of when the drone is not balancing properly.


text:
Can I power up my Arduino and MotorShield with four AA batteries?
can I power up my Arduino UNO with four AA batteries? It's about 6V, will my arduino burn? And, if I power my Arduino, I have to power my Motor Shield too or not?
I want to make line follower. I have to know what I have to power up. I dont know, how many battery holders I need. I have: Arduino UNO, motor shield, two 6V DC motors

connect 4 AA batteries through the power jack. nothing will get burned. Please share which motor shield you are using

this one: https://goo.gl/XbYSx0 ; and I have two DC motors (6V), btw, I have battery without ON/OFF switch, if I plug it in power jack, and after minute suddenly I disconnect this jack, will it damage my Arduino? is there other option? btw how many volts can I connect to this power jack?

L293d can support upto 36V. (http://www.ti.com/lit/ds/symlink/l293.pdf)
arduino Uno: Input Voltage (recommended) 7-12V
Input Voltage (limit) 6-20V

@Sanu-OpenMaker I have to give power to Arduino Uno, Motor shield and two motors? so I need 3 battery holders?

Generally No need. You can give 6V to arduino through power jack. Arduino has a voltage regulator to convert to 5v.
Motors driver will get powerder through Vin pin in arduino(in some other cases you can connect 6V to the shield and it will power the arduino as well)
Motors are gerring power from motor driver in most cases

You won't damage the Arduino if you remove the power to the motors as even though you're using the same power supply to power the motots and Arduino (4 x 1.5 - 6V batteries) you're not powering it from the Arduino pins itself.
What exactly are you trying to accomplish here?  Post some more info.

I updated question

can I power up my Arduino UNO with four AA batteries?

6v is about the max if it is directly applied to the chip;
6v is just shy of the minimum if it is applied to a regulator and then to the chip.

This is multiply mistaken.  6v is too low for the usual regulator to deliver rated output.  But 6v is also not the sum of four new alkaline AA's, which will be higher.

It won't cause damage to connect 4xAA to the input of the Arduino's regulator, however it also won't result in specified operation, as even with fairly new cells the voltage will below that which the typically used 5v regulators require to deliver 5v at the output.
Additionally, the common L293D and L298 based bipolar motor shields are horribly lossy.  Feed them about 6v input, and you'll get just over 4v to your motor, which is likely to be disappointing.
To build an Arduino-based battery-powered motor project, you typically need to do one of two things

Use 6, 7, 8 or more cells, and higher-voltage, lower current motors
Use a 3.3v Arduino and a more efficient FET-based H-bridge motor driver/shield, for example the TB6612FNG.   This supports 4 cell operation quite well, and may to a more limited degree work on 3 alkaline cells.


text:
arduino on battery for long time use
I have a small project with arduino UNO R3 + RTC clock DS3231, that control through a relay a electrovalve (12V).
I would like to use the entire circuit on battery.
The electrovalve (a small motor) has a consumption of 500mA and will be active 4 times a day for 15 second.
I have a 7Ah battery, and I had calculated that my system will work only around 34 hours with it... is there any way to optimize circuit consumption ?
Thanks for any suggestion !

You don't write what kind of Arduino, I think there you also can gain something (using a stripped IC plus the minimum needed), or use sleep mode if you want to keep the (complete) Arduino.

Can you paste you calculations here? The time seems pretty short to me. I come up with 500mA * 15s = 0,5A * 1/240h = 0,002 Ah. So your Battery will last for 3500 cycles = 875 days = about two years. What are the characteristics of your arduino setup? In sleep mode an Arduino can go as low as 0.2µA.

@MichelKeijzers  I edit my post it's an arduino uno.

@Kwasmich what do you mean by sleep mode ? you mean 200mA ?

No, I really mean 200 nano Amperes. 200nA = 0.2µA.

You can turn off the entire Arduino and let it wake by your RTC. That way you can conserve a lot of power. (link)
Also you will have losses from the power regulator when powering the Arduino from 12V. You might consider using a Arduino Pro mini with 3.3V powered by two AA batteries. That should last for years.

That's very interesting, but it's not clear how my RTC can awake arduino, because in my program arduino just read permanently the time send by the RTC...

Some (not all) RTCs have an interrupt timer. Depending on the module it is either INT or SQW. You can set a time and go to sleep then RTC will wake the arduino that is configured to wake up on that interrupt. Then you can read the data, set a new timer and go sleeping again. See here and here

Thanks, it's seems to be what I'm looking for, do you know any library that allow easily to make this configuration ? I read a lot about but didn't understand how to set the RTC DS3231, to send message four time a day.


text:
7 Segments display with arduino mega2560
I doing a small project with 6 display 7 segment (I will call A1, A2, A3, A4, A5, A6) and 3 cd4543B (I will call Da, Db, Dc) with an arduino mega 2560. I also use 6 transistor to control power supply of display.
Da is use for A1, A2
Db is use for A3, A4
Dc is use for A5, A6
The circuit is done, and work if I use only 4 display I have tried different combination (A1, A2, A3, A4, or A1, A2, A5, A6 or A2, A3, A4, A5, or A3, A4, A5, A6) and all work well.
but If I want to use five or six display, nothing work....

there is resistance for each segment of each display which not appear on the diagram.
my code for 5 display :
//Da
const int bit_A=8;
const int bit_B=9;
const int bit_C=10;
const int bit_D=11;
//Db
const int bit_E=22;
const int bit_F=24;
const int bit_G=26;
const int bit_H=28;
//Dc
const int bit_I=40;
const int bit_J=42;
const int bit_K=44;
const int bit_L=46;

// transistors
const int alim_dizainemillier= 3;
const int alim_millier=4;
const int alim_centaine=5;
const int alim_dizaine=6;
const int alim_unite=7;

void setup()
{

pinMode(bit_A,OUTPUT);
pinMode(bit_B,OUTPUT);
pinMode(bit_C,OUTPUT);
pinMode(bit_D,OUTPUT);
pinMode(bit_E,OUTPUT);
pinMode(bit_F,OUTPUT);
pinMode(bit_G,OUTPUT);
pinMode(bit_H,OUTPUT);
pinMode(bit_I,OUTPUT);
pinMode(bit_J,OUTPUT);
pinMode(bit_K,OUTPUT);
pinMode(bit_L,OUTPUT);
pinMode(alim_dizainemillier,OUTPUT);
pinMode(alim_millier,OUTPUT);
pinMode(alim_centaine,OUTPUT);
pinMode(alim_dizaine,OUTPUT);
pinMode(alim_unite,OUTPUT);

digitalWrite(bit_A,LOW);
digitalWrite(bit_B,LOW);
digitalWrite(bit_C,LOW);
digitalWrite(bit_D,LOW);
digitalWrite(bit_E,LOW);
digitalWrite(bit_F,LOW);
digitalWrite(bit_G,LOW);
digitalWrite(bit_H,LOW);
digitalWrite(bit_I,LOW);
digitalWrite(bit_J,LOW);
digitalWrite(bit_K,LOW);
digitalWrite(bit_L,LOW);
digitalWrite(alim_dizainemillier,LOW);
digitalWrite(alim_millier,LOW);
digitalWrite(alim_centaine,LOW);
digitalWrite(alim_dizaine,LOW);
digitalWrite(alim_unite,LOW);
}

void loop()
{
 for(int i=0;i<100000;i++)
 {
   afficher_nombre(i);

 }
}

void afficher_nombre(int nombre)

{
 long temps;
 int unite=0,dizaine=0,centaine=0, millier=0, dizainemillier=0;
 dizainemillier=nombre/10000;
 millier=(nombre-(10000*dizainemillier))/1000;
 centaine=(nombre-1000*millier)-(10000+dizainemillier)/100;
 dizaine=(nombre-(centaine*100)-(millier*1000)-(dizainemillier*10000))/10;
 unite=nombre-(dizainemillier*10000)-(millier*1000)-(centaine*100)-(dizaine*10);

 temps=millis();
 while((millis()-temps)<500){

    digitalWrite(alim_dizainemillier,HIGH);
    afficher_CD(dizainemillier);
    digitalWrite(alim_millier,LOW);
    digitalWrite(alim_centaine,LOW);
    digitalWrite(alim_dizaine,LOW);
    digitalWrite(alim_unite,LOW);
    delay(5);

    digitalWrite(alim_dizainemillier,LOW);
    digitalWrite(alim_millier,HIGH);
    afficher_CM(millier);
    digitalWrite(alim_centaine,LOW);
    digitalWrite(alim_dizaine,LOW);
    digitalWrite(alim_unite,LOW);
    delay(5);

   digitalWrite(alim_dizainemillier,LOW);
   digitalWrite(alim_millier,LOW);
   digitalWrite(alim_centaine,HIGH);
   afficher_CM(centaine);
   digitalWrite(alim_dizaine,LOW);
   digitalWrite(alim_unite,LOW);
   delay(5);

   digitalWrite(alim_dizainemillier,LOW);
   digitalWrite(alim_millier,LOW);
   digitalWrite(alim_centaine,LOW);
   digitalWrite(alim_dizaine,HIGH);
   afficher_UD(dizaine);
   digitalWrite(alim_unite,LOW);
   delay(5);

   digitalWrite(alim_dizainemillier,LOW);
   digitalWrite(alim_millier,LOW);
   digitalWrite(alim_centaine,LOW);
   digitalWrite(alim_dizaine,LOW);
   digitalWrite(alim_unite,HIGH);
   afficher_UD(unite);
   delay(5);
 }
}

void afficher_UD(int chiffre)
{
  digitalWrite(bit_A,LOW);
  digitalWrite(bit_B,LOW);
  digitalWrite(bit_C,LOW);
  digitalWrite(bit_D,LOW);

      if(chiffre>=8)
         {
           digitalWrite(bit_D,HIGH);
           chiffre=chiffre-8;
         }
     if(chiffre>=4)
         {
           digitalWrite(bit_C,HIGH);
           chiffre=chiffre-4;
         }
    if(chiffre>=2)
         {
           digitalWrite(bit_B,HIGH);
           chiffre=chiffre-2;
         }
    if(chiffre>=1)
         {
           digitalWrite(bit_A,HIGH);
           chiffre=chiffre-1;
         }
}

void afficher_CM(int chiffre)
{
  digitalWrite(bit_E,LOW);
  digitalWrite(bit_F,LOW);
  digitalWrite(bit_G,LOW);
  digitalWrite(bit_H,LOW);

      if(chiffre>=8)
         {
           digitalWrite(bit_H,HIGH);
           chiffre=chiffre-8;
         }
     if(chiffre>=4)
         {
           digitalWrite(bit_G,HIGH);
           chiffre=chiffre-4;
         }
    if(chiffre>=2)
         {
           digitalWrite(bit_F,HIGH);
           chiffre=chiffre-2;
         }
    if(chiffre>=1)
         {
           digitalWrite(bit_E,HIGH);
           chiffre=chiffre-1;
         }
}

void afficher_CD(int chiffre)
{
  digitalWrite(bit_I,LOW);
  digitalWrite(bit_J,LOW);
  digitalWrite(bit_K,LOW);
  digitalWrite(bit_L,LOW);

      if(chiffre>=8)
         {
           digitalWrite(bit_L,HIGH);
           chiffre=chiffre-8;
         }
     if(chiffre>=4)
         {
           digitalWrite(bit_K,HIGH);
           chiffre=chiffre-4;
         }
    if(chiffre>=2)
         {
           digitalWrite(bit_J,HIGH);
           chiffre=chiffre-2;
         }
    if(chiffre>=1)
         {
           digitalWrite(bit_I,HIGH);
           chiffre=chiffre-1;
         }
}

I don't understand why it's not working. Could it be a power supply problem ? even if there is never two display used at the same time (delay between them, see code)
Thanks a lot for any help.

Try this link Arduino and CD4543
To control a common cathode seven segment display using CD4543
PH ( Pin 6 ) should be set LOW.
LD ( Pin 1 ) should be set HIGH.
BL ( Pin 7 ) should be set LOW.

Try this code for each segment, could be faulty segment too :)
int Ph  = 6;      //arduino pin connected to the Ph pin of 4543
int BL  = 5;     //arduino pin connected to the BL pin of 4543
int LD  = 11;   //arduino pin connected to the LD pin of 4543

int A   = 7;
int B   = 9;
int C   = 10;
int D   = 8;

void setup()
{
    // Declare all the pins as OUTPUT pins

  pinMode(Ph,  OUTPUT);
  pinMode(BL,  OUTPUT);
  pinMode(LD, OUTPUT);

  pinMode(A , OUTPUT);
  pinMode(B  , OUTPUT);
  pinMode(C  , OUTPUT);
  pinMode(D, OUTPUT);

}

void loop()
{

    // Display 0

  digitalWrite(Ph,  LOW);
  digitalWrite(BL,  LOW);
  digitalWrite(LD,  HIGH);

  digitalWrite(A , LOW);
  digitalWrite(B , LOW);
  digitalWrite(C , LOW);
  digitalWrite(D , LOW);

  delay(1000);

    // Display 1

  digitalWrite(A , HIGH);
  digitalWrite(B , LOW);
  digitalWrite(C , LOW);
  digitalWrite(D , LOW);

  delay(1000);

    // Display 2

  digitalWrite(A , LOW);
  digitalWrite(B , HIGH);
  digitalWrite(C , LOW);
  digitalWrite(D , LOW);

  delay(1000);

    // Display 3

  digitalWrite(A , HIGH);
  digitalWrite(B , HIGH);
  digitalWrite(C , LOW);
  digitalWrite(D , LOW);

  delay(1000);

    // Display 4

  digitalWrite(A , LOW);
  digitalWrite(B , LOW);
  digitalWrite(C , HIGH);
  digitalWrite(D , LOW);

  delay(1000);
}

This 3 pin on the CD4543 are already well linked... I have done a better post with video of my problem : https://arduino.stackexchange.com/questions/38374/7-segment-displays-arduino-mega-2560

The circuit is done,

unnecessarily complex: you can share the data lines among the drivers.


text:
Run program from SRAM on SAMD21?
I am looking for an example of how to load a program from sd card to SRAM and execute it from there on the SAMD21.
I understand that the given MCU use the Von Neumann architecture and all code is privileged.

According to an important Wikipedia article, “Neuman's surname is often misspelled as "Newman"”.  I guess the same thing happens to  Von Neumann.

BTW, per Table 22.11 in Joseph Yiu's  “Guide to ARM Cortex-M0 and Cortex-M0+ Processors” book, the Cortex-M0 and -M0+ use Von Neumann architecture, while the Cortex-M1, M3, M4, M7 use Harvard.  The SAMD21 is a Cortex-M0+ processor, so Von Neumann as stated in question.

@JamesWaldby-jwpat7 By the way, the proper pronunciation of Neumann is actually Noiman. It's German.

@Majenko, of course that's true of Von Neumann's name, as he was born and raised in Germany; but perhaps less so of Neuman's name, which is from whole cloth.  Anyhow, artificer has corrected the spelling in the question.

@JamesWaldby-jwpat7 Yeah, the proper pronunciation of Neuman is "Chumly".

There's two aspects to what you want to do - one (relatively) easy, and one (comparatively) hard.
The first thing you will need is some way of getting your program into RAM. That would mean some software running on the chip that will accept the program and place it into RAM then execute it. You will have to write your own bootloader-like program that runs in Flash that will perform the task.
The second, harder, thing is to compile your program in such a way that it will execute from RAM. And that's no easy task.
Ideally you want to compile the code as position independent code (with the command line flag -fPIC), but that depends on the compiler being able to do that for this chip. If not, you will have to compile it so that the code expects to reside in RAM with all addresses used for jumps, etc, going to the right location. And that brings me to the second aspect of compiling, the linker script.
If you have your code in RAM you can't also have your variables in the same place in RAM. You will have to subdivide the RAM into two sections - the code execution section and the variable storage section. This is done through the construction of a custom linker script which is used during the linking phase of compilation. It tells the compiler where in memory to place everything - code, variables, etc. You will need to craft your own linker script to divide the RAM up in a suitable manner to give you enough room for your code while at the same time not starving it of variable storage space. This will also make sure all jumps, etc, in your code use the right addresses in case you can't (or don't want to) use -fPIC.
So, given all that, do you still really want to execute code from RAM?

Thanks a lot for the linker warning. I will have to consider the SRAM size constraints.

After a lot of reading I found an ATMEL document about the subject. They already created the linke script!  the document is named "AT07347: Executing Code from RAM"


text:
Triggering Sound - Arduino + Contact Mic
I previously created a sound installation using contact mics and computer (ableton+max msp) where sound would be triggered when people touched/tapped on the object/surface. Now I want to do something similar but want to get rid of the computer as it will be at a night club space where people will be walking around so I don't want to leave the computer there.
What I exactly want to do is to be able to load some sounds into arduino and again use contact mic on the object and when people touch it, the sound will be triggered. I know it won't be as creative as doing it with ableton where there is live-editing possibility but I'm happy with one type of sound in this one. I can probably find some codes here and there but I'm not sure what I exactly need to use to be able to do this.
I have few uno boards and lots of other bits that I've collected but haven't used before, so I would be very happy if you could help me as a novice.
Thank you

I'm using piezzos too, for making art installations, and I used max-msp too, but I don't like it too much.
It's a whole new world change from the computer to the Arduino. Because it's not only the code, you must deal with electronic components I'm quite a novice too and I don't know how much you know about music and electronic components so maybe I say things wrong or that you already know, but I will say:

AC Adapter

I will use an AC Adapter better than batteries, because the batteries will run out in a couple of hours and in a night club almost for sure you will have access to some power extension. Arduino usually works with 9v 1A, but it'll go for 2A.

Music Shield

And you need a music shield, you can buy a cheap one, but I recommend the Adafruit ones, because they come with a lot of more information, and more people are working with them, but they're usually more expensive. With the music shield you need a SD card. Arduino don't have enough memory so you need a music shield with a SD card to storage the sounds.

Speakers and amps

and finally the speakers, it depends in what kind of speakers are you using, if you're using a big ones like some Yamaha MSP you will need and amplifier,  but if you're using little ones like 8ohm 0.25W with the music shield will be enough

some kind of box

you will need to put the Arduino in some kind of box, and I will secure it in the wall and not in the ground

If you're asking what kind of sensor you'll need, look for capacitive sensors or there's even this instructable that could be implemented with a conductive material (see link below).
You can definitely do this project without a computer, you just need to figure out the following things:
1) Power consumption - How much current will your Arduino, speaker, sensors, etc use? Calculate your "mAh" from this and determine what kind of battery (my recommendation) will fit your needs.
2) Housing for the arduino+circuitry. If you're doing this in a nightclub you want this to be waterproof/somewhat durable.
3) SD card shield/adapter to store the sounds you want.
I have lots of experience as a hobbyist so please do not hesitate to ask for more questions. Good luck!!
Link to instructable: https://www.instructables.com/id/DIY-Touch-Sensor/

authors: Юрий Новиков


text:
Something's wrong with my code for a 4 digit 7 segment clock display
I'm trying to do a clock using 4x7 segment displays but once I run the code the Display doesn't turn on
here's my Code that I'm like 90% sure that there's nothing wrong with it
bool A = 2;
bool B = 3;
bool C = 4;
bool D = 5;
bool E = 6;
bool F = 7;
bool G = 8;
int PWR1 = 10;
int PWR2 = 11;
int PWR3 = 12;
int PWR4 = 13;
int TimeSec = 0;
int TimeMin1 = 0;
int TimeMin2 = 0;
int TimeHour1 = 8;
int TimeHour2 = 0;
int Display = 0;
int Loop = 0;
int Digit = 0;
int Memory1 = 0;
int Memory2 = 0;
int Memory3 = 0;
int Memory4 = 0;
int Rewrite1 = 0;
int Rewrite2 = 0;
int Rewrite3 = 0;
int Rewrite4 = 0;

void setup() {
  pinMode(A, OUTPUT);
  pinMode(B, OUTPUT);
  pinMode(C, OUTPUT);
  pinMode(D, OUTPUT);
  pinMode(E, OUTPUT);
  pinMode(F, OUTPUT);
  pinMode(G, OUTPUT);
  pinMode(PWR1, OUTPUT);
  pinMode(PWR2, OUTPUT);
  pinMode(PWR3, OUTPUT);
  pinMode(PWR4, OUTPUT);
}
void loop() {
  loop:
  delay(250);
  Digit = Digit + 1;
  if (Digit > 4) { Digit = 1; }
  if (Digit == 1) { goto digit1; }
  if (Digit == 2) { goto digit2; }
  if (Digit == 3) { goto digit3; }
  if (Digit == 4) { goto digit4; }

  // Supposedly turns on the 7-segment display that is next in line to have its digit edited but doesn't work?
  digit1:
  digitalWrite(PWR1, HIGH);
  digitalWrite(PWR2, LOW);
  digitalWrite(PWR3, LOW);
  digitalWrite(PWR4, LOW);
  Display = Memory1;
  goto skip;
  digit2:
  digitalWrite(PWR2, HIGH);
  digitalWrite(PWR1, LOW);
  digitalWrite(PWR3, LOW);
  digitalWrite(PWR4, LOW);
  Display = Memory2;
  goto skip;
  digit3:
  digitalWrite(PWR3, HIGH);
  digitalWrite(PWR1, LOW);
  digitalWrite(PWR2, LOW);
  digitalWrite(PWR4, LOW);
  Display = Memory3;
  goto skip;
  digit4:
  digitalWrite(PWR4, HIGH);
  digitalWrite(PWR1, LOW);
  digitalWrite(PWR2, LOW);
  digitalWrite(PWR3, LOW);
  Display = Memory4;
  skip:

   // Manual Turning on of LEDs is overcomplicated and can be made much shorter yes I know :(
   if (Display == 1) {
    digitalWrite(A, HIGH);
    digitalWrite(B, HIGH);
    digitalWrite(C, HIGH);
    digitalWrite(D, HIGH);
    digitalWrite(E, HIGH);
    digitalWrite(F, HIGH);
    digitalWrite(G, HIGH);
    digitalWrite(B, LOW);
    digitalWrite(C, LOW);
  }
  if (Display == 2) {
    digitalWrite(A, HIGH);
    digitalWrite(B, HIGH);
    digitalWrite(C, HIGH);
    digitalWrite(D, HIGH);
    digitalWrite(E, HIGH);
    digitalWrite(F, HIGH);
    digitalWrite(G, HIGH);
    digitalWrite(A, LOW);
    digitalWrite(B, LOW);
    digitalWrite(G, LOW);
    digitalWrite(E, LOW);
    digitalWrite(D, LOW);
  }
  if (Display == 3) {
    digitalWrite(A, HIGH);
    digitalWrite(B, HIGH);
    digitalWrite(C, HIGH);
    digitalWrite(D, HIGH);
    digitalWrite(E, HIGH);
    digitalWrite(F, HIGH);
    digitalWrite(G, HIGH);
    digitalWrite(A, LOW);
    digitalWrite(B, LOW);
    digitalWrite(C, LOW);
    digitalWrite(G, LOW);
    digitalWrite(D, LOW);
  }
  if (Display == 4) {
    digitalWrite(A, HIGH);
    digitalWrite(B, HIGH);
    digitalWrite(C, HIGH);
    digitalWrite(D, HIGH);
    digitalWrite(E, HIGH);
    digitalWrite(F, HIGH);
    digitalWrite(G, HIGH);
    digitalWrite(B, LOW);
    digitalWrite(G, LOW);
    digitalWrite(F, LOW);
    digitalWrite(C, LOW);
  }
  if (Display == 5) {
    digitalWrite(A, HIGH);
    digitalWrite(B, HIGH);
    digitalWrite(C, HIGH);
    digitalWrite(D, HIGH);
    digitalWrite(E, HIGH);
    digitalWrite(F, HIGH);
    digitalWrite(G, HIGH);
    digitalWrite(A, LOW);
    digitalWrite(F, LOW);
    digitalWrite(G, LOW);
    digitalWrite(C, LOW);
    digitalWrite(D, LOW);
  }
  if (Display == 6) {
    digitalWrite(A, HIGH);
    digitalWrite(B, HIGH);
    digitalWrite(C, HIGH);
    digitalWrite(D, HIGH);
    digitalWrite(E, HIGH);
    digitalWrite(F, HIGH);
    digitalWrite(G, HIGH);
    digitalWrite(A, LOW);
    digitalWrite(F, LOW);
    digitalWrite(G, LOW);
    digitalWrite(C, LOW);
    digitalWrite(D, LOW);
    digitalWrite(E, LOW);
  }
  if (Display == 7) {
    digitalWrite(A, HIGH);
    digitalWrite(B, HIGH);
    digitalWrite(C, HIGH);
    digitalWrite(D, HIGH);
    digitalWrite(E, HIGH);
    digitalWrite(F, HIGH);
    digitalWrite(G, HIGH);
    digitalWrite(A, LOW);
    digitalWrite(B, LOW);
    digitalWrite(C, LOW);
  }
  if (Display == 8) {
    digitalWrite(A, HIGH);
    digitalWrite(B, HIGH);
    digitalWrite(C, HIGH);
    digitalWrite(D, HIGH);
    digitalWrite(E, HIGH);
    digitalWrite(F, HIGH);
    digitalWrite(G, HIGH);
    digitalWrite(A, LOW);
    digitalWrite(B, LOW);
    digitalWrite(C, LOW);
    digitalWrite(D, LOW);
    digitalWrite(F, LOW);
    digitalWrite(G, LOW);
    digitalWrite(E, LOW);
  }
  if (Display == 9) {
    digitalWrite(A, HIGH);
    digitalWrite(B, HIGH);
    digitalWrite(C, HIGH);
    digitalWrite(D, HIGH);
    digitalWrite(E, HIGH);
    digitalWrite(F, HIGH);
    digitalWrite(G, HIGH);
    digitalWrite(A, LOW);
    digitalWrite(B, LOW);
    digitalWrite(C, LOW);
    digitalWrite(D, LOW);
    digitalWrite(F, LOW);
    digitalWrite(G, LOW);
  }
  if (Display == 0) {
    digitalWrite(A, HIGH);
    digitalWrite(B, HIGH);
    digitalWrite(C, HIGH);
    digitalWrite(D, HIGH);
    digitalWrite(E, HIGH);
    digitalWrite(F, HIGH);
    digitalWrite(G, HIGH);
    digitalWrite(A, LOW);
    digitalWrite(B, LOW);
    digitalWrite(C, LOW);
    digitalWrite(D, LOW);
    digitalWrite(E, LOW);
    digitalWrite(F, LOW);
  }

  // Checks how many times it has looped over
  Loop = Loop + 1;
  if (Loop < 4) {goto loop;}
  else
  {
    // Resets Loop count and counts 1 second (normally it has a delay(1000) but the delay(250) on the loop to account for LED's turning on is counting for me )
    Loop = 0;
    TimeSec = (TimeSec + 1);
    if (TimeSec == 60) {
      TimeMin1 = (TimeMin1 + 1);
      Memory1 = TimeMin1;
      TimeSec = 0;
      if (TimeMin1 == 10) {
        TimeMin2 = (TimeMin2 + 1);
        Memory2 = TimeMin2;
        TimeMin1 = 0;
        Memory1 = TimeMin1;
        if (TimeMin2 == 7) {
          TimeHour1 = (TimeHour1 + 1);
          Memory3 = TimeHour1;
          TimeMin2 = 0;
          Memory2 = TimeMin2;
          if (TimeHour1 == 10) {
            TimeHour2 = 1;
            Memory4 = TimeHour2;
            TimeHour1 = 0;
            Memory3 = TimeHour1;
            if (TimeHour1 == 3 && TimeHour2 == 1) {
              TimeHour2 = 0;
              Memory4 = TimeHour2;
              TimeHour1 = 1;
              Memory3 = TimeHour1;
            }
          }
        }
      }
    }
  }
}

And here's how it's Wired up
Also I think that I have to make a clock of my own for the Timer or else it will become a problem later on but I don't know how to make 2 loops so if someone can tell me how to do it (preferably in a way that I can understand xD) I'd be very grateful
Notes:

The Displays are Common Anode so to turn on a LED I used digitalWrite(ledpin, LOW) for a negative output
I'm not using a 4 digit 7-segment display -- I'm using 4 individual 7-segment displays
Resistors are 220 Ohm
The Picture was made using https://circuits.io
I'm still new at this so my code may have some newb mistakes or just stuff that was made overcomplicatedly simple if you know what I mean :P

UPDATE 1:
I fixed it now the problem was I was setting the variables to bool instead of integer but I still can't figure out how to do a self-sufficient clock because the current code now runs but doesn't turn on as fast as I need to

Regarding “here's my Code that I'm like 90% sure that there's nothing wrong with it”:  Because it doesn't work, you should instead be 100% sure there's something wrong with it.

There are several bugs that I spot right off the bat.  First off, you should never need goto in C++.  You should be able to use if, for, and while to completely eliminate those. goto makes code hard to follow and read, so it makes it nearly impossible for someone else to try to debug.  Be nice to yourself and forget that goto ever existed.  I would suggest hitting a C++ tutorial and learning about functions, because most of the places you've used goto, what you really needed was a function call.
Second is this:
bool A = 2;
bool B = 3;
bool C = 4;
bool D = 5;
bool E = 6;
bool F = 7;
bool G = 8;

A bool is meant to hold a true or false value, not a pin number.  You should use int here, or better yet save a few bytes and use byte.  But not bool.  The second issue here are the single capital letter variable names.  Those are always a bad idea.  Many of them (B and F for sure) are already defined as macros in the core.  They're not available for you to use.  Single letter variable names are bad form, but single capital letters are right out.
Third is the way you have the digits connected.  There should be a resistor for each segment, or you will have brightness differences depending on how many segments are in use at any one time.  But that can wait until you get the code worked out.
Finally, here is some code for working with 7-segment displays.  It's a lot easier to work with than the whole thing you've got written out.  See if you can follow it and ask questions if you don't understand.  This code would count 0 to 9 over and over on a single 7 segment display.
byte digits[] = {0b1111110 , 0b0110000, 0b1101101, 0b1111001,
0b0110011, 0b1011011, 0b1011111, 0b1110000, 0b1111111, 0b1111011};

// pins to segments g,f,e,d,c,b,a
byte pins[] = {3,4,5,6,7,8,9};

void displayNumber(int aNumber) {
  for (int i = 0; i < 7; i++) {
    digitalWrite(pins[i], digits[aNumber] & (1 << i));
  }
}

void setup(){
  for (int i = 0; i < 7; i++){
    pinMode(pins[i], OUTPUT);
  }
}

void loop(){
  for (int i = 0; i < 10; i++) {
    displayNumber(i);
    delay(1000);
  }
}

I thought goto was easier to follow as it's a custom label that would be easier to spot but if you say so :P --- I think I'm going to stick to my Overcomplicatedly simple code as it's easier for me to understand but I'll make a separate build to use your code so I can play around with it --- I'm still stuck at how to make a separate clock since I don't know how to make a 2nd loop that works simultaneously with another if it's even possible

The same argument you make for goto applies doubly to a function.  It gives you a definite place in the code to go to with a name that is easy to spot, but doesn't require all the convoluted logic to then skip sections.  When functions return they go right back to the same spot in the code where from they were called.  And they can bring back information with them. Learn about functions and you'll see what I mean.


text:
Writing your own Arduino flashing tool
I want to make Arduino flashing tool only for a nano, a simple flashing application which could run on windows taking input as a .hex file.
I know how to do this in Linux environment using Makefiles and writing script to automate it but have no idea what all are the things which I need to know and consider before I proceed with any windows application for such cases (implementing light GUI).
Any initial guide or read through would be a great help!

....... Why on earth....?!?!

I wish to give a support for a firmware upgrade for a product wherein I would be giving a .hex file and enable flashing on customer side. IDE can be used but I wish to provide a minimal complexity for the unskilled user.

So you don't want an IDE then, and it has nothing to do with Makefiles. You just want to run avrdude, maybe from a little wrapper GUI.

May be yes. @Majenko please suggest the steps that would be involved in wrapping the avrdude with the GUI. Thanks!

Write a windows application that asks for a file. 2. Add that file name to a predefined string for executing the command. 3. Execute the command. Maybe add options to select the com port. If you're clever and your chosen windows programming language allows it you may be able to feed the output of avrdude back to the user.

Or just use this https://blog.adafruit.com/2013/02/19/avrdudess-a-gui-for-avrdude/

This application already exists. It's called AVRDUDE:
http://www.nongnu.org/avrdude/
You can download it compiled for Windows at the link above. This is the very flashing tool that the Arduino IDE uses for the AVR boards such as Nano. You can get the AVRDUDE command the Arduino IDE uses to upload to the Nano by following these steps:

Start the Arduino IDE
File > Preferences > Show verbose output during: > upload (check) > OK
Tools > Arduino Nano
Sketch > Upload
After the process completes scroll the black console window at the bottom of the Arduino IDE window up to the start of the upload output and you will see the command generated by the Arduino IDE, which you can adapt to your needs.

If you want to use Makefiles you can get make compiled for Windows from this package:
http://winavr.sourceforge.net/
Note that it's incorrect to call what you're trying to do an IDE. IDE stands for Integrated Development Environment, which this is certainly not.


text:
Adafruit nRF52 feather board [SOLVED]
I am working on a project (the scenario is depicted in the attachment) involving Bluetooth Low Energy (BLE). As a master (central device) I am using the Adafruit nRF52 feather board (https://learn.adafruit.com/bluefruit-nrf52-feather-learning-guide/introduction) and as slaves (peripheral devices) a pair of Adafruit nRF8001 modules (https://learn.adafruit.com/getting-started-with-the-nrf8001-bluefruit-le-breakout/pinouts?view=all#introduction). Moreover, I have to wire the nRF52 up with an Arduino Uno rev3.
I am trying to set up the very initial communication between central and peripheral devices, but if I even try to upload the blinky sketch into the nRF52 board the compiling phase returns to me the following error:

exec: "nrfutil": executable file not found in $PATH

Does anyone have an idea what it means? I googled a lot but I am not able to figure it out on this problem.
Thanks in advance to anyone would be able to help me!
Filippo

[EDIT] Solved: just need to install the nfrutil first, as written in https://learn.adafruit.com/bluefruit-nrf52-feather-learning-guide/arduino-bsp-setup#nrfutil-os-x-and-linux-only

mind sharing your code on github?

Would you mind sharing how you solved the problem in an answer (or edit monkSinha's answer)? That adafruit website may not exist at the same address in the future, so it would help to give a complete answer to future readers of your question.

Step 2 solves this problem:
https://learn.adafruit.com/bluefruit-nrf52-feather-learning-guide/arduino-bsp-setup
Also, read up about how to add something to Path Variable on Windows.


text:
Arduino UNO two SoftwareSerial ports communication
I am working on a project involving bluetooth and wifi communications. Both of them are wired up to the Arduino and communicate to it using two software serial port.
The scenario is the one in the picture attached.
What I am doing is:

retrieve the sensor value
send it from the BT slave module to the master one (wired up to Arduino)
take it and send it, using AT commands, through the WIFI channel (the WIFI module is a ESP8266-01) to a web server.

The problem is that if I start listening to the BT serial port (BTSerial.listen()) I am not able to properly send the sensor values through the WIFI connection. But if I comment out the lines related to the BT sotware serial, and try to send fixed value to the web server, the sending terminates succesfully.
In my opinion there are some problems with the BTSerial.listen() and WIFISerial.listen() calls, since they are not able to switch from one the the other correctly.
I saw the TwoSerialPort example provided into the Arduino IDE and I tried to apply it into my code but it still not works to me.
Does anyone have a idea which would be the problem? Does anyone already faced with this problem or a similar one?
Hoping to be as much clear as possible, thanks in advance to anyone would help me.
Filippo
[EDIT] Added two code snippets
// This method prepares the AT commands will be send to the ESP8266-01 module in order to upload the values on the web server
void send2server(String ip, int port, String file, int t, int h, int p) {

  String queryString = "temp=";
  queryString.concat(t);
  queryString.concat("&hum=");
  queryString.concat(h);
  queryString.concat("&press=");
  queryString.concat(p);
  Serial.println(queryString);

  // Prepare and exec the AT+CIPSTART command provideing the TCP connection init
  String CIPSTART_cmd = "AT+CIPSTART=\"TCP\",\"" + ip + "\"," + port + "";
  exec_cmd(CIPSTART_cmd, 1000);

  // Prepare the POST request
  String httpPOST_cmd = "POST /";
  httpPOST_cmd.concat(file);
  httpPOST_cmd.concat(" HTTP/1.1\r\n");
  httpPOST_cmd.concat("Host: ");
  httpPOST_cmd.concat(ip);
  httpPOST_cmd.concat("\r\n");
  //httpPOST_cmd.concat("Accept: */*\r\n");
  httpPOST_cmd.concat("Content-Length: ");
  httpPOST_cmd.concat(queryString.length());
  httpPOST_cmd.concat("\r\n\r\n");
  //httpPOST_cmd.concat("Content-Type: text/html\r\n\r\n");
  httpPOST_cmd.concat(queryString);

  // Calculate the POST request length
  unsigned int len = httpPOST_cmd.length();

  // Prepare and exec the AT+CIPSEND statement with the POST request length just calculated
  String CIPSEND_cmd = "AT+CIPSEND=";
  CIPSEND_cmd.concat(len);
  exec_cmd(CIPSEND_cmd, 1000);

  // Exec the HTTP POST request
  exec_cmd(httpPOST_cmd, 1000);

  // Close the connection
  exec_cmd("AT+CIPCLOSE", 1000);
}

// This method execute each AT command in the previuous method
void exec_cmd(String cmd, int delayTime) {
   byte i = 0;

   while(1) {
      Serial.println("invio comando");
      WIFISerial.println(cmd);
      while(WIFISerial.available()) {
         if(WIFISerial.find("OK")) {
            i = 8;
         }
      }
      delay(delayTime);

      if(i > 5)
         break;

      i++;
   }

   if(i == 8) {
      Serial.println("OK");
      //return true;
   } else {
      Serial.println("ERRORE");
      //return false;
   }
}

The problem is the code goes properly till the AT+CIPSEND command, then the POST request is sent but no good feedback arrives, ending with the "ERRORE" error message.

[EDIT 2] Attached serial monitor output
This is the serial monitor output when I execute the skecth. It seems to work properly but it does not upload any value.

SoftwareSerial is poor at best. With two it's poor squared.

You can't use two instances of the normal software serial.  Probably you best bet is to drop the Arduino and instead run your sketch on the ESP8266, with that talking to the BT.  Or use nRF24L01's to link the sensors instead of BT.

Arduinos now come in so many configurations and use so many different processors you now need to specify exactly what you are using.  If a processor has only 1 hardware serial port you will have to implement the 2nd serial port in software.  There are different libraries to use for this.  Needless to say, a software implemented serial port is not as good (fast) as a hardware serial port.  As you can see, there is more to programming serial ports on Arduinos then simply instantiating another instance of the standard serial port library. Goodby software. Welcome to firmware.

This answer provides full details on choosing "good" combinations of hardware and software serial ports.  To summarize:

Use the HardwareSerial port (i.e., Serial) for one of the devices.  You can still use it for debug prints, as long as the device has some kind of command "format".  For example, if commands start with "AT", just make sure that none of your debug prints start with "AT".  It is the absolute best choice.  You would have to disconnect RX pin 0 from the device in order to upload new sketches over USB.
Use AltSoftSerial for the other device.  It is the most efficient software serial port, and it can be used at the same time as Serial.  It only works on two specific pins.
NeoSWSerial is the next best choice, at limited baud rates.  It can be used with the above choices, but transmitting on NeoSWSerial prevents them from receiving.
SoftwareSerial is the worst choice.  Receiving or transmitting on SoftwareSerial prevents all of the above from receiving anything.  It disables interrupts for long periods of time.

UPDATE - Here is the most reliable configuration:

Your code will have something like this:
#include <AltSoftSerial.h>
AltSoftSerial BT; // 8 is RX, 9 is TX

#define WIFI Serial  // 0 is RX, 1 is TX (disconnect 0 to upload new sketch)

void setup()
{
  WIFI.begin( 115200 );
  BT.begin( 9600 );
}

void loop()
{
  if (BT.available) {
    char c = BT.read();
    // do something with the character
       ... save them until '\n' arrives?
         ... then parse some values?

    if (values all received) {
      Serial.print( F("Sending values") ); // this is the WIFI port, but
          //  the ESP8266 ignores this debug print because it doesn't
          //  start with "AT".

      WIFI.println( F("AT+ ...") ); // all the AT commands
          ...
      WIFI.print( btValue1 );    // and the BT values
          ...
    }
  }
}

Thanks for the replies @slash-dev. If I understand correctly, using NeoSWSerial I would be able to receive data on the BT serial and transmit it towards the WIFI module over the WIFI serial simultaneously. Am I right or not?

And if so, is there a guide or a tutorial on NeoSWSerial? Thanks again!!

@Filippo, so you're ignoring the two best choices?    You would have to create a NeoSWSerial instance with a RX pin for the BT TX, and a TX pin for the WIFI RX.  Right now, you can only transmit and receive simultaneously with the one NeoSWSerial that is "listening".  You could make another instance for the WIFI TX/BT RX.  Just like SoftwareSerial, NeoSWSerial can only listen to one pin at a time.  Srsly, use AltSoftSerial (pins 8 & 9) with Serial (pins 0 & 1) to avoid all these issues.

@Filippo, there is no "tutorial" for NeoSWSerial, because it is a drop-in replacement for Serial or SoftwareSerial.  Some extra info at the NeoSWSerial github page.  All these libraries are available from the Arduino IDE Library Manager, under the menu Sketch -> Include Library -> Manage Libraries....

Already found either github page or library into the Arduino IDE, thanks @slash-dev.
I am trying to understand the test sketch in to the NeoSWSerial library in order to apply it into my project. But, since I am nquite new to Arduino, could you explain ti tom  me a little bit, please?
I have an Arduino UNO, so I got no Serial1, Serial2, ecc. ports. How can I apply your library to the scenario in the picture below?

@Filippo, the test sketch is for verifying the library, not an example for you.  Look at any example for Serial, AltSoftSerial or SoftwareSerial and it will work with NeoSWSerial.  I will add an update in my answer to show the best connections/libraries.

Huge thanks @slash-dev!!! My picture was just to give you an idea about the communication scenario, but I have the exactly same wirings than the ones in your schema.
Now I have a better idea about I have to do! Thanks again so much!!

Just a curiosity regarding the example in the code you posted above: what if I would use a software serial (e.g. AltSoftSerial or NeoSWSerial) instead of hardware serial (Serial) for the WIFI connection? Should it be possible?

@Filippo, you can only have one AltSoftSerial port, and it must be on two specific pins (8 & 9 for an UNO).  And as I said, "[NeoSWSerial] can be used with the above choices [i.e. AltSoftSerial], but transmitting on NeoSWSerial prevents them from receiving."  If you never transmit to the BT and the BT can run at 9600, 19200 or 38400, you could use NeoSWSerial for the BT.  Then you could use AltSoftSerial for the WIFI.  It won't be as reliable as the above configuration, because AltSoftSerial can affect NeoSWSerial reception, especially if AltSoftSerial is running above 38400.

Thanks @slash-dev! I wired up all the stuff as in the circuit you posted and used AltSoftSerial for the BT and the hardware serial (pin 0 and pin 1) for the WiFi. Despite all this I am not able to send the sensor value to the web server. I edit my initial question and added two snippets.
Any yours feedback would be strongly appreciated!!

Sorry, I don't know how to help with the AT commands, but I would suggest that you eliminate the String variables.  There's no reason to build up a big  String and call WIFI.println once.  Just print the pieces to WIFI, individually.  This will save a huge amount of RAM, which could be the problem.  The one exception is the Content-length.  I believe there is a mode where you can send the content and terminate it with ^Z (char 26), instead of sending the length first.  Maybe.

Thank you so much again @slash-dev. Your help was very very appreciated!
Just one more question: using the hardware serial port as a serial one for WIFI (#define WIFISerial Serial;), would not be the possibility the that the command for the ESP8266-01 module would be interpreted as simple prints on the serial monitor instead of the instruction for the module, leading to not actually producing the WIFI command

Yes, the ESP8266 commands would be visible in the Serial Monitor window, but they are only interpreted by the ESP8266.  It is the debug prints that must be ignored (not interpreted) by the ESP8266.  As long as they don't start with "AT", the ESP8266 should ignore them.  Or comment out all the debug prints to see if it starts working.  (I doubt it changes the behavior).  So you will see both debug prints and AT commands in the Serial Monitor window, but it doesn't matter.

Still it does not works fine for me, since the WIFISerial.println("AT+...") statements are only printed out onto the serial monitor window and they DO NOT produce any effective results about uploading values to the web server.
In my previuos connections (in which I used two SoftwareSerial ports, but commenting out the BT.begin(9600) statement), I used the exactly same code for the AT commands and it worked properly since the upload works fine (althought with fixed values).
I edited the intial post to attach to you the serial monitor output for a better comprehension.
Thanks again!!

Well, that doesn't make any sense to me... it seems to be replying "OK", but it doesn't actually send to the server?  A poor level-shifting circuit could affect the ESP8266.  Using [tt]Serial[/tt] means that there is extra loading on the TX and RX pins (0 & 1) from the on-board FTDI chip (for the USB).  You could try the alternative I suggested in the comment above:  "you could use NeoSWSerial for the BT. Then you could use AltSoftSerial for the WIFI."  This assumes you never send to the BT.