Since you do not have enough RAM for your arrays, something has to
give. A few options:

Do you really need the 10-bit precision of the ADC? If you can live
with 8 bits, then use 8-bit arrays (type uint8_t) and store only
the 8 most significant bits of each reading
(pixelsArray[i]=analogRead(Aout)>>2). This will make the arrays
half as big.
If you really need 10-bit precision, maybe you do not need 128-pixel
resolution? Then you could store only every other pixel. This will
also halve the array sizes.
If you do need both the full precision and the full resolution, then
you will have to pack the bits tight. You can pack up to 4 readings
in 5 bytes. But this will increase the complexity of your program.

Addendum: To declare the arrays as being made of 8-bit integers,
just replace

int pixelsArray[128];
int pixelsArray1[128];

by

uint8_t pixelsArray[128];
uint8_t pixelsArray1[128];

Here “uint8_t” means “unsigned 8-bit integer”, whereas “int” is a
regular integer, i.e. signed and, on the AVRs, 16-bits long.


backup battery for FeatherWing DS3231, RTC

The problem was a bad connection for one of the serial lines.

I found the solution at this link.

The battery is not necessary to make this work.


Check out ESP-LINK You can find it here
ESP-LINK is a esp8266 wifi-serial bridge, outbound TCP, and arduino/AVR/LPC/NXP programmer. It has several configuration, one of them allowes uploading new firware ower wifi, or to act as a serial link just like if usb cable is pluged in and serialport viewer is active. The website has great documentation and has one of the slickest configuration interfaces seen on ESP.


Why can't I declare variables inside an if statement?

Declaring a variable inside a block means that they only exist within that block. Once the block is exited, they become inaccessible.


Most likely, your motherboard detected a over-current situation, and disabled power to that port. Since it has to way to know if the cause of the over-current has been fixed, it will continue to disable the port (since the only way to know would be to turn the power back on, and doing that to many times might cause permanent damage).

I wouldn't expect there to be a way to force your MoBo to reset the port, as this is an unlikely event. You should be glad the MoBo prevented any damage.

Using a different port sounds like an okay solution.


Modify SSID and Passwords in WiFi sktechs

Yes, this is possible. However, you need to have some programming skills (Java, C, C++, anything really that can cope with serial comms) to write the computer-side program.

Forget 'automatic' running of a program without installing a service on the target computer to constantly monitor incoming serial comms. That said, there's nothing to stop you doing that but to me it's an unnecessary extra step. If the End User can handle connecting the Arduino to the computer without having a breakdown, then they can probably cope with launching the input program themselves.

Hence, write a program for the target computer that analyses COM ports for active connections. For each connection, listen for some kind of identification sequence. Perform a basic 'handshake' to verify that it's found the Arduino. Once it has, allow the User to enter the WiFi details, which are then passed on to the Arduino via serial. If you're feeling slightly adventurous (the necessary code is provided with the Arduino IDE as an Example, so it's no real challenge) you could have the Arduino scan for networks and offer the User a list to choose from.

On the Arduino, include within the sketch a method of opening serial comms with the target computer. This can be either:

Within loop(), at regular intervals, which becomes redundant after you've performed the setup correctly; or
A one-time affair within setup(). Each time the Arduino is powered on it attempts to establish comms with the computer, but times out after 30 seconds of 'silence', thus the User has to launch the program on the computer within a reasonable time.

Whichever approach you choose, the code in the sketch follows a similar essence - send a unique message to whatever is listening (if anything at all!) and wait for a specific response. If the computer is connected and the program is running, it should answer. Provided the answer received by the Arduino is expected (thus 'handshake' mentioned earlier), it should then wait for the SSID/pass to be entered by the User and sent by the computer. From there, connecting the Arduino to the network is a trivial process.


How to choose SPI type used by RF24 library from application?

Using this RF24 library set, I am able to use or not softspi by doing #define SOFTSPI on my sketch, there's no need to define it on the RF24_config.h, you should be able to define it on your own sketch.

EDIT:

Arduino 1.6.5

#include <SPI.h>
#include "RF24.h"
#include "printf.h"
#define SOFTSPI //Define pins RF24_config.h

/****************** User Config ***************************/
/***      Set this radio as radio number 0 or 1         ***/
bool radioNumber = 0;

/* Hardware configuration: Set up nRF24L01 radio on SPI bus plus pins 7 & 8     */
RF24 radio(8,9);

....
....
void setup() { ... }
void loop() { ... }


Arduino struggling to power a large LED strip

WS2812 use around 1mA when they are off. So that's already 400mA with no LED lighted. USB can supply around 500mA. So you only have 100mA available.

Each led package has three colored leds inside; Red, Green and Blue. Every color will use around 20mA when fully turned on.

So you can only turn on 5 colors at full brightness at 500mA.

Using a 2.5A supply you could go up to 105 colors, or 35 leds full white.

This would be more than enough for a word-clock, as most leds will be off.


Not clear code procedure in Arduino wire library

rxBufferLength is the number of bytes that have been received. rxBufferIndex is the byte you would next be handed with a read() function call.

So if you have received 6 bytes from the slave (which you will, since that is how many you requested) but not read any the available would be 6. Ergo, 6 <= 6. I.e., you asked for 6, it collected 6, and you are checking that it got at least 6 (it can never be >6 since you only asked for 6, so why they look for at least 6 I don't know).

rxBufferIndex is never decremented. It is incremented when you read a byte, up until rxBufferLength == rxBufferIndex at which point there is 0 bytes available.

  But, my current question is why decrementing return rxBufferLength - rxBufferIndex; where  rxBufferIndex is initialized to 0 all the time, and there's no chance the returned value would be less than 6, because that would terminate the if statement?

The way that Wire.h works is that available() will always return the number of bytes you requested if the call to requestFrom() succeeded until you first read some of that data. If you request 6 and the call worked then you have 6. The if could just as well be written as:

if (Wire.available()) {...

since it will always be 6 immediately after a successful call. However, that makes assumptions about how the Wire API works and could be subject to change in the future or operate differently on different platforms.

So it checks that, right after the call to requestFrom() for 6 bytes it actually got at least 6 bytes. Without seeing what is inside the conditional if, all I can do is make assumptions, but I would assume that it is then reading those 6 bytes, and so it wouldn't care if there happened to be more for some reason. But it doesn't want there to be 5 or fewer bytes available when it is reading 6 of them.

An if statement doesn't "terminate" if its condition becomes false once it has been executed. It's not like a while that keeps running until it's false - it's a single decision made at a single point in time. If anything changes in the future that would have caused a difference decision to be made (e.g., you read() a byte, so available() would now return 5), the decision that has been made still stands.

An analogy for you:

You want to go out for a good healthy walk - but only if it's not raining.

if (!raining) {
    walk_to_shop();
    walk_to_cafe();
    drink_coffee();
    walk_to_shop();
    walk_home();
}

You go out for your walk to the shops, get a coffee, do some more shopping, and then walk home - but you only start doing that if it's not raining. If it starts raining while you're out you don't suddenly teleport back home.  You could make the decision, when you come out of the cafe and see it's raining, to cut your shopping trip short, but you have to actively make that decision. Just because raining becomes true doesn't affect the fact that you are outside and walking.


This function:

void arrayTest(int* n){
    n[0] = 15;
}

is lacking the class qualifier:

void MyLib::arrayTest(int* n){
    n[0] = 15;
}


Unable to use DHT11 with NodeMCU(esp8266)

The esp8266 boot configuration pins 0, 2, 15 require a pull-up/pull-down  to ensure the required state at boot. The board (NodeMCU in this case) has pull-up resistor on io0 and io2 and a pull-down resistor on pin 15. The MCU pins io0, io2 and io16 are the NodeMCU pin D3, D4 and D8. You can use this pins in the sketch, but only to attach devices which are not in conflict with the required boot state and are not disturbed by the pull-up/pull-down.

NodeMCU and "Wemos D1 R2 and Mini" esp8266 pins and io overview

Serial

RX io1 RX0

TX io3 TX0

boot config pins with pullup or pulldown on board

D3 io0 PULLUP (LOW for boot to flashing mode)

D4 io2 TX1 PULLUP (Serial1 TX. no RX for Serial1)

D8 io15 PULLDOWN (SS pin if esp8266 is SPI slave)

untroubled GPIOs with optional function for I2C or SPI bus:

D1 io5 default pin for I2C SCL

D2 io4 default pin for I2C SCA

D5 io14 SPI CLK

D6 io12 SPI MISO

D7 io13 SPI MOSI

RTC pin for timed deep sleep wake-up (if connected to reset pin)

D0 io16 - optional internal pulldown, internal pullup not available

not useable: Sx pins io 6 to io 11 connect QIO SPI flash memory (in DIO flash mode the 2 QIO pins can be used as gpio) (in a very special setup the SPI bus can be used with other SPI device)

note: most digital IO start as INPUT_PULLUP


Try this
int LEDState = 1;
int SwitchPin = 6;
int LEDPIN = 9;

void setup()
{
  pinMode(LEDPIN,OUTPUT);
  pinMode(SwitchPin,INPUT);
  digitalWrite(LEDPIN,LEDState);
}

void loop()
{

  int SwitchState = digitalRead(SwitchPin);

  if(LEDState==1 && SwitchState==HIGH){
   LEDState = 0;
  }

  digitalWrite(LEDPIN,LEDState);
    delay(10);
}


DC Motor Pinning the Ada Fruit Moto Shield with the Mega2560 R3

Well because an Arduino Mega2560 is pretty much and UNO with a longer rear end, try seeing the UNO in the MEGA if that makes any sense. Then just put the shield in like a normal shield that you would put on a UNO. Most UNO shields are compatible with MEGAs. Then you just use your shield like if it was on an UNO.


To answer your first question, regarding stacking a WiFi Arduino Shield on top of a LCD Shield:

  can I stack them simultaneously

The obvious answer is - it depends on the shields. Each shield might use a different set of Arduino I/O pins, making them unavailable to the next shield stacked on top of it.

for example, this formal Arduino WiFi shield makes I/O pins 10, 11, 12, 13 and 7 (on Arduino Uno) unavailable to the next top shield.

Unfortunately, this LCD KeyPad shield needs pins 7 and 10 available (among others) in order to function properly. This makes it incompatible for stacking on top of the WiFi shield mentioned above (or vice versa).

It doesn't mean that there is no way that any LCD shield could be stacked on top of a WiFi shield, but to be honest, I couldn't easily find any LCD shield that won't collide with a WiFI shield pins. You might want to change approach and send the WiFi data using the built-in Serial to a computer.

  Is that the best microcontroller to use

If there would have been a manifest to this website, I'm sure that "The best product is the one that meet your needs best" would be it's first sentence. In order for someone with experience to answer what is best, (s)he would need to know your exact needs. Since you are still not sure what they are, and just want to play around a bit, I imagine that the classic Arduino Uno R3 could help you find your way, especially if you are doing your first steps with Arduino.


replace each delay chain with a switch statement where each delay is replaced by saving the current millis counter, a increment of the state, a case label for the new state and a if(millis()-timestamp  < timeout) return;

switch(state){
case 0;
      // Indicator right with running light (like a "half-knight-rider" ;) )
      // Rise
      digitalWrite(11, HIGH);
  timestamp = millis();
  state++;
case 1:
   if(millis()-timestamp  < mtime) return;

      digitalWrite(10, HIGH);
  timestamp = millis();
  state++;
case 2:
      digitalWrite(9, HIGH);
//etc.

The for loop around the entire thing will need to be replaced. Make i global and incrementing it in the last state and resetting it as needed. When i has been incremented to beyond 5 you always return.

This means that the left and right functions only do a few things: set the led, check a timestamp against the current time, and increment a state before returning.

This means that they will take very little time to execute and that you can check the button in the main loop() body and if pressed initiate the statemachine or end it (and putting out the LED when needed).


invalid conversion from 'const char*' to 'char*' [-fpermissive]

strtok modifies the char buffer entered as first parameter. It replaces the delimiters with terminating zeros. To parse a constant string with strtok, you must first copy it into a working char buffer.

For your test you can initialize a char array as in following example.

char payload[] = "setBrightness: 15";

uint8_t brightness;

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

  if(strncmp(payload, "setBri", 6) == 0) { // Search message
   strtok(payload, " ");
   const char* tok = strtok(NULL," "); // Get value (15)
   brightness = (uint8_t) atoi(tok); // Convert to uint8_t
  }
}

void loop() {}

if you know the 'name' part of the name:value string, you can skip it for atoi this way:

brightness = (uint8_t) atoi(payload + strlen("setBrightness: "));

(strlen("setBrightness: " will be evaluated at compile time to a constant number)

const char payload[] = "setBrightness: 15";

uint8_t brightness;

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

  if(strncmp(payload, "setBri", 6) == 0) { // Search message
     brightness = (uint8_t) atoi(payload + strlen("setBrightness: ")); // Convert to uint8_t
  }
}

void loop() {}


I have the same configuration and it works (Arduino UNO rev3)
I used WiFlyHQ library. Just be carefull with the serial.

Serial.begin(9600);
...
if (!wifly.begin(&Serial, NULL)) {
   ...

Upload with serial select then put it on USB and then open the monitor.


Computer to multiple arduino bluetooth modules

yes, you can, this is what happens normally in a crowded area where multiple people use their phones with bluetooth headsets, for example.
if you believe the claims typical 10m max 100m but in practice there are a number of factors:

Quality of the HW design of the antennas
Signal to noise ratio due to other radios operating in the same area
Obstacles in the path
Responsiveness and throughput required by your application
etc.

you could consider other options, like this module, which is basically the same, from the perspective of transferring data. Also wifi could work, if you are allowed to setup your own access point.


somebyte itself is a pointer. so "&somebyte" doesn't make sense.

instead, use "&somebyte[0]" (or "&somebyte[5]" if you want an offset), or "somebyte" (or "somebyte + 5" if you want an offset).

arrays are actually pointers.


How to create a USB CDC device. (I'm using stm32f103c8 black pill board) and I want to read the data through USB in my raspberry pi as a serial port

You can use the one provided by generating it with STMCubeMx. This is going beyond arduino though. But it is highly feasible.


Unable to declare variable in a library that doesn't have a class: multiple definition of the variable

In Lib.h you should declare an

extern int myVariable;

In Lib.cpp you can define it once

#include "Lib.h"
int myVariable=123;
...


Here are several "getting started" articles that contain simple programs.

http://tmrh20.github.io/RF24

https://groups.google.com/forum/#!topic/nrf24-arduino/VaC2U5D1o_s

http://arduino-for-beginners.blogspot.com/2013/02/setup-nordic-nrf24l01-rf-modules-to.html


Is defining a function improves speed rather computing average for each analog input separately

Writing the code out four times, in line, is a little bit faster than calling a function because the function call and return take some time, and the loop instructions take some time, and neither of those contribute to the average calculation.
Writing a function that you use four times, however, is much more readable, is much easier to fix if you've made a mistake because you can fix it once instead of four times, and is much easier to change or replace for the same reason, if that ever becomes necessary. Besides, a good optimizing compiler can often decide when to rewrite your loop as inline several repetitions of the loop contents (called "unrolling the loop"), so hand optimizing is probably not worthwhile.
Where your function will win over 4 repetitions of the calculation code is in the code-space needed. The function is more compact, but slightly slower.


D1 mini does not resume operation as expected after deep sleep

The garbage is because the ESP8266 outputs boot information at 76800. This should include the boot reason and may help you understand why the code's not working as expected.

Try changing your Serial speed to 76800 in your code (just so that your messages don't end up being gibberish), use 76800 on platformio's monitor and you should be able to at least see what the D1 says it's doing.

You should see a line that ends in something like:

  rst cause: x, boot mode:(y, z)

x should be 1 ("Power reboot"), 2 ("External reset or wake-up from Deep-sleep" - obviously what you want), 3 ("Software WDT" - the software watchdog went off) or 4 ("Hardware WDT reset" - the hardware watchdog timer went off)

boot mode indicates where the runtime image came from - y should be 3 ("Flash"); anything else is really unlikely for your setup.

There's more info on this at ESP8266 Reset Causes
and Common Fatal
Exception Causes

If you try this please post how it goes! I'd like to hear more about what's going on here.


how to block Arduino code until a certain event?

It depends on how the "keypad" is implemented. If you've got it hooked up to a hardware interrupt, then you only need to add an interrupt handler for that event.

On the other hand, the more "straight-forward" implementation is that you have to poll the pins to see if a key was pressed.  Simply do that in a loop until you see a key press, call your event-handler method, and then continue to loop.


Pretty much anything is possible.

There is a method known as bit banging which toggles a generic IO pin to create a protocol, and read changes on another generic IO pin to read in the data of a protocol.

The trick is in creating a protocol.

Fortunately that has all been done for you - the SoftwareSerial library. It will create a bit banged version of the RS232 serial protocol using any combination of IO pins to transfer data between devices.


By connecting BOOT0 to 3.3V you are telling the chip When I reset for whatever reason you must go into the bootloader.

So you reset, and it goes into the bootloader. You then upload your sketch.

At that point the programming software tells the bootloader "Ok, you are done now. Run the program". And it does.

Until you reset. And because you are telling it to go into the bootloader with BOOT0 it dutifully does so, waiting for you to load a new program.

The old program is still there, but you just aren't letting run, since you are insisting that the chip go into the bootloader when you reset.

In order to get your program to run and not the bootloader you must disconnect BOOT0 so it doesn't enter the bootloader.

You only need to connect the BOOT0 when you want to put a new program on there.


NodeMCU (ESP8266) board controlled over shared hosting database

Use MQTT.

You need:

The PubSubClient.h library
An MQTT server

For MQTT there are some free ones around on the internet (ask Google). Or if you have a Linux server available for use (e.g., a cheap VPS server from one of many many providers online) then you can run your own with mosquitto.

MQTT works kind of how you describe, but it's not making constant GET requests - it opens a single connection to the MQTT server and realtime requests are sent down it to the client, and back from the client to the server.

Near realtime communication.


Arduino I2C external 32Kb fram data organization

It'll be easier if you use a struct, not a union. Store all the data you want to preserve in a struct, then cast a pointer to it to be a byte pointer and just treat it as an array of bytes and read and write those bytes to the FRAM.
The union you were using explicitly did the same thing, but it's not easy to scale to multiple items.
Some caveats about what you can safely keep in the struct:

do not store pointers in it. A char array is fine because the entire array will take up space in the struct. A char * is not because all you'll save is the value of the pointer, not what it points at.

do not store objects (like String) in it. You don't know (and shouldn't know) how the object is composed internally. If need to use objects, they should have serialize and deserialize methods which would store or restore the contents of an object into an array of bytes which you could then store or restore with the FRAM.

Also remember that the C/C++ sizeof function (used below) tells you the size of thing at compile-time. So if you use it on a struct it will tell you the number of bytes it takes to store the struct. If you use it on a char *, it will tell you the number of bytes in a pointer to a char, not the number of bytes in the C string that the char * points at. If you use it on an object - like String str; sizeof(str); - it will tell you how many bytes it takes to store the String object, which will include the length of the string it stores.
Psuedo-code follows. There are more compact ways to write this; I'm aiming for clarity here.
#include <Arduino.h>

struct program_data {
  float first_thing;
  unsigned long second_thing;
  char third_thing[55];
  char fourth_thing;
  uint16_t fifth_thing;
} data;

void save_data(struct program_data *data_ptr) {
  byte *ptr = (byte *)data_ptr;

  for(size_t i = 0; i < sizeof(struct program_data); i++)
    store_byte_in_fram(ptr[i], i);
}

void restore_data(struct program_data *data_ptr) {
  byte *ptr = (byte *)data_ptr;

  for(size_t i = 0; i < sizeof(struct program_data); i++)
    retrieve_byte_from_fram(ptr[i], i);
}

// call when you want to save your data
  save_data(&data);

// call when you want to restore your data
  restore_data(&data);


The most important document you have to read is called a datasheet. Here you can find the MC14051's.

I assume you already know how a mux/demux work, so... Well, you have eight LEDs, one on X0, another on X1, ... up to X7. The one connected to the pin X, which is your A0 (the pin used on irsend, I assume) is indexed by the three inputs A, B and C.

On page 5 you see the truth table. According to that table, you have to write a 0 on inhibit, and the value on ABC. So, to select led on X0, you have to write 0 on pins 7, 8, 9 and 10. If you want to select led X1, 8 should go high. For led X7, 8, 9 and 10 should be 1, while 7 is low. And this is for all the combinations...


How to get a list of IPs in a LAN using NodeMcu?

You should use mDNS.  Install (if it isn't already) avahi-daemon on your Raspberry.

Then check out the ESP8266mDNS library and the examples it has. Especially the mDNS-SD_Extended example, which performs a query for a service on the network.


Mega 2560 powered with 7V don't work correctly

The Voltage-Regulator has a dropout-voltage of 1,2V, but in line to the regulator is a diode, which adds another minimum 0,7V (dont know the exact part number, so i guessed the voltage of a Si-diode at ~1A). So you have to supply at least 5 + 1,2 + 0,7 = 6,9V. I presume the circuit doesnt draw a constant current all the time, so from time to time the regulator cant supply the 5V because you sink under the necessary dropout-voltage of the rehulator/diode-combination.

-> Use 8V  or bypass the Diode D1 (with a solder-bridge) and use 7V if its a must and you are sure the input-polarity is always correct.

Arduino-Mega-2560-schematic: http://arduino.cc/en/uploads/Main/arduino-mega2560_R3-sch.pdf


Why does my Wemos D1 Mini stops working while charging via solar?

The TP4056 Module will output a max of 4.2V which is less than the 5V the Wemos D1 Mini is expecting on its 5V connection (Assuming you have connected the circuit as shown in the Github guide). When the solar panel is charging it's likely that the TP4056 is causing a driving issue on the supply of the Wemos causing it to potentially Brownout .
I would not connect the solar panel to the Wemos like this, I would have it connected to the battery then the battery connected to a 5V Step Up Power Converter like shown below (This reduces efficiency but give the MCU a stable supply),

My recommendation for the wiring,


When using a normal stepper driver, you say the driver to do one step, by sending him one pulse. The length of these pulses does not have a meaning. they are constructed, so that the driver can sense them. The driver does not make smaller steps than 1 full step, if you don't tell him on extra pins (The library you use can utilize those pins too). So the stepMotor() function is correct. You can drive the motors with different speeds by doing a step for each motor in different intervals (different number of steps per time).

Your move() function blocks the execution of other code, until the motion is completed. You are doing this with the while( STEPS > 0 ) loop. You need to modify your code to be non-blocking. This is normally done in the way, that is shown by the BlinkWithoutDelay example of the Arduino IDE. You are using it too: You have to use the millis() or micros() function, to check if it is time to do a step.

Replace the while with an ´if´-statement:

if( STEPS > 0 )

and make the STEPS variable a member variable of the class instance. Then make sure you execute the function often enough, so that it will not miss the time to do a step. Do the same with the second motor. For example something that looks like this:

void setup(){
  ...
  stepper1.doSteps(100);
  stepper2.doSteps(200);
}

void loop(){
  stepper1.move();
  stepper2.move();
}

Here in the setup function the steppers are told to move 100 and 200 steps. (You would have to write the function doSteps(int number_of_steps) yourself). The motion is then done by the move() functions, when it is time to do so. Since these two functions are looped very fast, they shouldn't miss the time for a step.

This is also the way the AccelStepper library works, which is also a common stepper library.


I want to program multiple arduino at once

Arduino, the company, may sell on enough volume to make it worthwhile to get the microcontroller manufacturer to program the microcontrollers durin the production process
This wouldn't cost them extra if they already get the bootloader pre-programmed. I've read programming ICs is a service available to high volume customers.
I guess low volume makers use fixtures that use the ICSP headers, pogo sticks or IC clips and which trigger the programming on contact using a microswitch etc.
I suspect Adafruit do something of this sort, see GIFs and video discussing testing at
https://www.adafruit.com/product/2458


How can I make my Arduino Uno press Space on my laptop keyboard?

if you have some knowledge in Java or Python you can interface your Arduino board to PC, through Arduino's SerialPort.
When Arduino sends a byte, for example, 0xAB, your Java or Python script sends a fake key-press event.
I hope this can help. Good luck!


There might be another device has already connected to that port. It could even be a terminal emulator which is left connected from last debugging session.

Otherwise, make sure that your UNO is really presented on COM4 by checking with "Device Manager". if not, change the port where it is available.


The code in the library truncates to 47 characters for some reason:

void printQR(String message) {

...

  // create QR code
  message.toCharArray((char *)strinbuf,47);
  qrencode();

The buffer is actually 116 bytes, oddly.

unsigned char strinbuf[116];

It's a little unclear why the limit of 47, or 116, was chosen.

You could try changing that line in qrprint.cpp to increase the number from 47 to at least 115.

Edit

After reading some of the comments, I doubt that will help. The QR code looks like it is generated into an internal array, which would have to have some size limits due to the amount of RAM available. The current array size is:

unsigned char qrframe[600];

That is already 1/3 of the available memory on a Uno.


Follow this tutorial on how to connect your Sim800l with Arduino.


Those functions have nothing to do with the Ticker library. Those functions are defined in the ESP8266 core.

The example you cite has this at the top of it:

  Hardware Timer0 is used by WiFi Functions. We can use only Timer1. Use of timer instead of Ticker gives advantage of precision timing and You can get timer interrupt in micro seconds.

Note the use of "instead of Ticker" there. That says that the code below has nothing to do with Ticker.


Well, one easy, but effective improvement is to use 2 buffers for writing data - while you are writing the one full to file, your interrupt can safely push values to the other and then after the other is full, your ISR would go to first one, while the second will be written. So even long open/seek/write/close loop does not get hit by new data arrival.

Then the main problem - RF - I would bet, that the on_connect() is called from interrupt too, as it is not mentioned anywhere in the loop(). In that case you would like to have it as small and fast as possible. So if you are only providing data, I would collect all the data in the main loop() in some variable (structure, class, what you need), get it thread safe as much as possible (atomic operations, or have two instancies, one actually enabled for the callback, the other opened for filling new data, then pointers to point which is which and just reassigning those pointers in atomic way (means disable interrupts, swich two pointers, enable interrupts - interrupts can wait for time need to two pointers be changed - on other hand you have no chance do anything in main loop (as disabling interrupts), while interrupt is actually running)

So (I know, it is just example, but) you know, that fileSize() is changed only after file is written - so save its value to some (volatile, of course) variable each time you write to the file and use that variable in onConnect.

So more like this (did not tested it, just idea):

volatile buffs[2];
volatile actBuff;
// timer interrupt 20Hz
// reading sensors to buffer
ISR() {
    int a = analogRead(A0);
    buffs[actBuff].push(a);
}

volatile int freeSpace;
void loop(){
    if buffs[actBuff].isFull() {
        int fullBuff=actBuff;
        cli();             // disable global interrupts
        actBuff = 1 - actBuff; // switch actual Buffer between 0 and 1
        sei();// enable global interrupts
        // ISR have nice free buffer to fill, we will write and empty the old one
        myFile.open("data.csv", FILE_WRITE);
        myfile.print(buffs[fullBuff].getData());
        myFile.close();
        buffs[fullBuff].empty()
        int tempval = SD.vwd()->fileSize();
        cli();             // disable global interrupts
        freeSpace = tempval;
        sei();// enable global interrupts:
    }
}

// possibility of blocking data collection process
RFduinoBLE_onConnect() {
    // int freeSpace = SD.vwd()->fileSize();
    // do the same trick here // other operations for monitoring data collection process
    RFduinoBLE.sendInt(freeSpace); // use the value from loop
}


So, a quick google for "Itead SD card breakout" comes up with their website/wiki where there is a schematic.  Can't believe you did not try this.  It is just that - a breakout board.  It will allow you to connect Arduino to an SD card.  You can look up any generic example for SD + Arduino on the web.

They explicitly say

  It can work with 5V or 3.3V power supply, and both 5V/3.3V IO operation level. It can be controlled directly by a wide range of microcontrollers such as Arduino, AVR, PIC, ARM and MSP430.


The pin that slides between the spokes should be just a metal bar that accepts your "small" pins in the ends to hold it in place.  Try looking at it from a different perspective and I think you will find a lot more suitable products.

You could use a worm gear, but this would be susceptible to bruit force attacks (literally) and would be easier to break.

Have you considered what happens when the power fails?  Does the lock lock or unlock?  If it unlocks on a power fail then it will be quite easy to open.  If it remains locked on a power fail then its not very user friendly, you would have to carry spare batteries and changing tools with you.

Sorry, but it is easy to poke holes in other peoples designs.


Can I run ESP8266 via Arduino using the PWM pins?

First question, Since we can control the volts that we can throw via PWM pins on Arduino, can we use it to power the 3.3v ESP8266?

No. The ESP8266 draws far too much current (in excess of 200mA) to use anything other than a proper supply.

  Second question, Can we also use these PWM pins as Software serial pins i.e. they will be sending instructions at 3.3v?

We'll drop the "also", since we've decided that you're not doing that.

You can use SoftwareSerial on any GPIO pins you like, provided the RX pin supports pin change interrupts.


Arduino digital output pin controling relay problem

Your problem is that you are basically saying "while the pin is HIGH toggle the relay" rather than "When, and only when, the pin transitions from LOW to HIGH do I toggle the relay".

To do that you must remember what state the pin was in during the last iteration:

const uint8_t led1 = 6;
const uint8_t enable1 = 7;

void setup() {
    pinMode(enable1, INPUT);
    pinMode(led1, OUTPUT);
}

void loop() {
    static bool led1_OnOff = false;
    static bool lastValue = digitalRead(enable1);

    bool currentValue = digitalRead(enable1);

    if (currentValue != lastValue) {
        lastValue = currentValue;
        if (currentValue == HIGH) {
            led1_OnOff = !led1_OnOff;
            digitalWrite(led1, led1_OnOff);
        }
    }
}


Arduino Pro Mini ATmega 328P: garbage output on serial console

Garbage values on output is mostly due to the baudrate.

Try changing the baudrate on the output terminal to the baudrate in the code.
Try checking the output by changing different baudrates on the terminal.

This must work for you :)


A 9V battery has both low peak current and low total power (low mAh rating). It is not a good choice for any circuit that draws more than ≈100 mA. (I pulled that number out of thin air, but it's probably a decent guess)
Build a battery pack from 6 AA alkaline cells instead. That will provide enough peak current. Or for much longer run-time, use 6 D sized cells.


Why does void loop() stop after some samples?

float sine[5000]
...
sine[j]=s+190;

A float takes 4 bytes. You are allocating 5000 of them which is 20000 bytes. The Uno has 2048 bytes of RAM. Thus you are running out of RAM and overwriting something you shouldn't be.

As pointed out on the Arduino forum, your for loop which tests for:

i < sample2 || i >= sample2

will always be true. Of course i will be either less than or greater than or equal to sample2.


Can UNO log more PCB 353b33 accelerometer data points compared to TDS3014B oscilloscope?

No way. The UNO has only 2.5kb of RAM, so you can't cache the data points and you would need a very quick link to get the data out. And sampling at 1.25 GigaSamples/s is orders of magnitude beyond an UNO, as its maximum clock frequency is only 16 MHz. An Uno is about $20, while your TDS3014B is around $1500. Sometimes, there's a reason for a different price tag.


I can't scroll Arduino IDE's example & scketch lists down

Try using 1.5.+. It has scroll arrows to allow larger lists of menus, bigger than the screen.

I find that most, if not all, sketches work equally well, if not better.

Up to 1.5.6r2 uses the same version of compiler as 1.0.+'s. 1.5.7 and newer uses a new compiler, that is more sctrict. All stock libraries work. And well written 3rd parties work. I personally use 1.5 and test backwards to 1.0.

There is a fork of 1.0 called ERW that has the scrolling. But 8t is becoming obsolete.


How to measure the distance between 2 points accurately

want to measure the movement of 2 points on a material surface as it is stretched and released the points move apart and towards one another. The points are real and tangible. This of pins in cloth and we want to measure the distance between the pins.

If the two points can be made then you could use an Ultrasonic range finder. you could have one point be a wall (use balsa wood or something light) then the other could be the range finder. You might have to do a little bit of engineering for attaching the range finder to the pins on the cloth, but I believe it's doable.

heres an amazon link for a generic arduino range finder: http://www.amazon.com/RHX-Ultrasonic-Distance-Measuring-Transducer/dp/B00F6KLLGG/ref=sr_1_2?s=electronics&ie=UTF8&qid=1439459256&sr=1-2&keywords=range+finder+arduino


This question is not really about the Arduino. It is about GNU C/C++ compiler optimizations.

By adding the keyword const the compiler can do a lot of optimization. One is that the value does not need to be stored in SRAM. The value can end up as part of an instruction, become part of an expression that is evaluated at compile-time, etc.

In the Arduino-GPIO library static const member data is used to allow the compiler to optimize to a single instruction digitalRead() with almost X100 performance improvement (on Arduino Mega).

Check GCC and AVR optimizations for further details.

http://www.nongnu.org/avr-libc/user-manual/using_tools.html
https://gcc.gnu.org/wiki/avr-gcc
http://www.linuxjournal.com/article/7269

Cheers!


Creating public instance of class in another class's initialization

As it's now in the first example, it's local variable in Timer constructor.

In the second one you have to use member initializer list in constructor as there is no default constructor in your display class.

class Timer {
public:
    Timer(uint8_t CLK, uint8_t DIO)
    : display(CLK, DIO) // constructor's initializer list
    {
        ...
    }
    void updateDisplay() {
        ...
        display.setSegments(displayData);
    }

    // member variable:
    TM1637Display display;
}


Slowly decreasing the speed on a steppermotor over time

millis() sound like a good way to go.

Check the estimated time until arrival (stopping), and in steps (you define yourself) you changen the (PWM) speed of the stepper motor.

Note, also for accelerating you can use the same step schema but reversed.

There are other ways, but I think those will be too complicated, like setting a (hardware) timer for the next speed change. Changing the speed in ms-accuracy will be more than enough.

Do not use delay, since you still want to be responsive for pressed buttons, and (safety) sensors.


Generated from IDE

Because this is a generic error, I'll answer it. I was getting this on STDERR when using the IDE:

  avrdude: usbdev_open(): did not find any USB device "usb"

This is because in the IDE I was using

Sketch → Upload Using Programmer [Ctrl + Shift + U]

However, I should have been using

Sketch → Upload [Ctrl + U]


Arduino Pro mini to CH340G Connection problem

try reversing the tx/rx lines, if the PRO Mini and serial adapter are chinese, you may want to try using your UNO as ISP programmer. See here for a hint/ex:
https://www.arduino.cc/en/Tutorial/ArduinoISP


http://www.agcross.com/2015/09/the-esp8266-wifi-chip-part-1-up-and-running/

According to the tutorial it's an undocumented bug with no fix.

If you change the name, baud, and set up the wifi and password you should be good to go


Arduino Mega web server always returning JSON data even if JSON is not passed in URL

So figured out the problem, the issue was  I was closing the connection instead when it was json fetched, I had to keep alive the connection.

so replaced client.println("Connnection: close"); with  client.println("Connection: keep-alive");

which fixed the problem.


Connect a multi meter in series with the servo connection from the uno to the servo and see how much current it draws when working (probably less than 20ma, definitely less than 40ma). Then connect it in series with the nano and see what happens. If you get no current then you're activating the wrong pin.

If you see a current draw but the servo doesn't move then you need to use some sort of switch (transistor, FET, relay) to switch the servo. You could also compare the voltage and current read off the nano to the requirement in the datasheet for the servo. Again, this may lead you to needing a switch.

Edit based on comments above... Also try your 5v directly to the servo, then add a forward biased diode in series which should simulate the voltage drop to the level of your nano (0.4-0.6v). If the servo doesn't work with the diode and does without then you can be pretty sure the issue is insufficient volts (which is likely given the rating of 4.8v you mentioned in comments).


Uploading Arduino bootloader to ATmega32U4 with another Arduino?

The only difference you have to take into account is that if you're using an ATmega32U4 board such as Leonardo the SPI pins are not broken out to the pin headers along the edge of the board as is the case with the Uno shown in the tutorial you linked. Instead you should connect the programmer board to the ICSP header pins on your ATmega32U4 board, where the SPI pins are broken out:

MISO: ICSP-1
MOSI: ICSP-4
SCK: ICSP-3

So this means you can't follow the wiring shown on the tutorial exactly but it should be very easy to adapt that tutorial to your needs.


Logging to multiple destinations (serial & SD card)

The simplest thing you can do is to create a simple function that performs both tasks for you.  However, there are certain caveats that you should look out for.  The most basic function would be:

void log(const char *msg) {
    Serial.println(msg);
    myFile.println(msg);
}

However that is not the best way of doing it since that requires all your messages to be in RAM.  So you should really use the __FlashStringHelper type as well as an overload function so you can use the F() macro to save RAM:

void log(const char *msg) {
    Serial.println(msg);
    myFile.println(msg);
}

void log(const __FlashStringHelper *msg) {
    Serial.println(msg);
    myFile.println(msg);
}

And that will pick the right version of log depending on what you pass.  But what if you want to pass some variables, like numbers?  Overloading can help again here.  Another pair of functions now that take two parameters instead of one:

void log(const char *msg) {
    Serial.println(msg);
    myFile.println(msg);
}

void log(const __FlashStringHelper *msg) {
    Serial.println(msg);
    myFile.println(msg);
}

void log(const char *msg, int v) {
    Serial.print(msg);
    Serial.print(" ");
    Serial.println(v);
    myFile.print(msg);
    myFile.print(" ");
    myFile.println(v);
}

void log(const __FlashStringHelper *msg, int v) {
    Serial.print(msg);
    Serial.print(" ");
    Serial.println(v);
    myFile.print(msg);
    myFile.print(" ");
    myFile.println(v);
}

So now you have 4 functions called log, and they can be used in these different ways:

log("This is a message"); // Could be a char * variable
log(F("This is a message"));
log("The temperature is:", temp);
log(F("The temperature is:", temp);

And of course you can keep expanding and expanding the parameters in different ways for different combinations of parameters.  Just be warned that for some combinations of parameters the compiler won't be able to work out which is the right function to call (for instance if you have one that takes a long and one that takes a byte in the same place and you just pass a numeric literal), so you have to think carefully about how you arrange your parameters.


I'm pretty sure I fried my Arduino Uno. Given my setup, what caused it to be fried? (I can't identify the short)

The Uno is not one "thing" that fails. It has various components, some of which may have failed. I wrote a lengthy page about how to test various parts:

Have I bricked my Arduino Uno? Problems with uploading to board

  I plugged my 12V 8A power supply into the power input on the arduino.

Perhaps you reversed the leads, and shorted the USB power to ground, thus causing the PC to turn off? This would probably also blow most of the components on the Uno because they would have had -12V applied to them, assuming it got past the voltage regulator.

However there is a reverse polarity protection diode on the power input jack. Did you use that or the Vin pin? (or the Vcc pin?)

Note that the reverse polarity protection does not protect you if you use the Vin pin.


NodeMCU Arduino set PWM Frequency to specific frequency

PWM frequency is 1kHz by default. Call analogWriteFreq(new_frequency) to change the frequency.

source


As mentioned by chrisl, you cannot use HC-06 as a master device. Its firmware restricts it to behave only as a slave. So even if you are able to process the analog data from LM 35, you won't be able to send it using HC-06. It would be better if you go for HC-05 module and try the command AT+ROLE: x (x = 1 for master/0 for slave) to get the job done.

Coming to the 3v3 voltage constraint, I would suggest you to go for any Zener diode (in reverse biased mode) with 3.3V Reverse breakdown voltage. You can check the circuit for this here and order it from this link. If this is not possible anyhow, then you can also go for LM1117 3V3, but I would personally suggest you to go for zener diode. Comment back if you need any help in future.


Could you tell us which multiplexer IC you are using? This way, we can help you better. Also, why do you need the 8 second cycle? Does it matter if it's a little shorter or longer? If timing does not have to be very precise it would make things a lot easier.

By the way: you say there are 30 sensors, but your table has 32...

The following pseudocode will not work on your Arduino, but you can use the same structure.

int sensorArray[32] // we will store our 32 sensor values here

// these pins control the multiplexer chips
int selectPinZero = 8;
int selectPinOne = 9;
int selectPinTwo = 10;

// these pins will receive the sensor values from the multiplexer chips
int inputPinOne = 0;
int inputPinTwo = 1;
int inputPinThree = 2;
int inputPintFour = 3;

void setup(){
    // make sure the correct pins are inputs and outputs
    pinMode(selectPinZero, OUTPUT);
    pinMode(selectPinOne, OUTPUT);
    pinMode(selectPinTwo, OUTPUT);

    pinMode(inputPinOne, INPUT);
    pinMode(inputPinTwo, INPUT);
    pinMode(inputPinThree, INPUT);
    pinMode(inputPinFour, INPUT);
}

// all done, now keep reading the sensors
void loop(){

    // set selectPins so that each Multiplexer will output its first channel
    digitalWrite(selectPinZero, HIGH); // or low, depending on your Multiplexer IC
    digitalWrite(selectPinOne, HIGH); // or low, depending on your Multiplexer IC
    digitalWrite(selectPinTwo, HIGH); // or low, depending on your Multiplexer IC

    // start reading sensors

    int i = 0;
    while(i<32){
        sensorArray[i] = analogRead(inputPinOne);
        i++; // variable i was 0, now 1

        sensorArray[i] = analogRead(inputPinTwo);
        i++; // variable i was 1, now 2

        sensorArray[i] = analogRead(inputPinThree);
        i++; // variable i was 2, now 3

        sensorArray[i] = analogRead(inputPinFour);
        i++; // variable i was 3, now 4

        /*
        use digitalWrite() on all the selectPins to make the Multiplexer IC output the next channel
        */

        delay(1000); // wait 1000 milliseconds
    }

    /*
    this will repeat until all 32 sensors are read and stored in the array
    */

}

This code is by no means optimized, but written to make it easy for you to understand. Good luck!


Is DS18B20 temperature sensor makes Arduino processing slow?

Indirectly it's the library.

That library uses the OneWire.h library.  The OneWire protocol requires some reasonably precise timing, and because of the the OneWire.h library turns off interrupts while it communicates.

While interrupts are disabled nothing else can happen. That means that the timer interrupt that drives millis() can't "tick" - so the millis count doesn't increase while you communicate with the temperature sensor.


Arduino UNO serial send and receive issue

You need a common ground between the Arduino and the PIC. Connect both grounds one to each other.


By my opinion, it is impossible to calibrate these solid electrolyte based sensors. I achieved best results when I measured the CO2 level in 5 minute intervals, by heating the sensor for 100 seconds. I cant remember these times precisely, but by heating and allowing it to cool down I was able to get quite reliable results. But then I realized that the sensor is getting some offset. If you want to do a two-point calibration, you can put it to fresh air, it should read about 0.04%, or you can breathe directly to the sensor for a short while and it shoud read 4%. But I highly recommend using NDIR CO2 sensor, those are used in home air monitoring devices.


What you're looking for is called motion capture. If you google it, you'll find a Wikipedia article that can give you a starting point for deciding which of the many available techniques will suit your project. Youtube also has several videos explaining motion capture, and different technologies.


The construct you are looking for is called while.
Instead of doing "If the button is pressed then continue" you need to do "while the button is not pressed do nothing".
Assuming you have an "active low" button (that is, a resistor pulling it up to +5V when not pressed, so digitalRead(A2) == LOW is "pressed"), you can do:
while (digitalRead(A2) == HIGH) {
  // Do nothing
}

So while it's not pressed (digitalRead(A2) == HIGH) don't do anything.  As soon as digitalRead(A2) returns LOW (so it is not == HIGH any more) the while loop will finish and your sketch can continue.
I write all about the while loop in an article here.


How to fill a triangle using the LCD5110 Graph library?

After tinkering around for hours I have finally found a great way to fill triangles! Here we go:

for(int x = x1; x<=x2; x++) {
    for(int y = y1; y<=y2; y++) {
     lcd.drawLine(x3, y3, x, y);
    }
}

Great!


You may try:

Serial.println("Sending UDP message");
Udp.beginPacket(destIp, port);
while (myFile.available()) {
  Udp.write(a);
}
Udp.endPacket();
Serial.println("Message sent!");

Or send the message part by part (for example 100bytes or 500bytes at a time)

Though, what makes you think that Arduino would be a platform that can rapidly send large files over network?
Potentially you are better off with an Raspberry Pi.


Can I use my PC or Android mobile as WiFi Shield/Module for Arduino UNO?

This problem can be broken into several components:

Communications channel between the Arduino Uno and the laptop or Android mobile

There are several options. The most common and probably easiest is to do serial communication over USB. The Uno has a USB-serial chip that creates a virtual COM port (VCP) on a computer when you connect the Uno to it via the USB receptacle on the board. This VCP is commonly used to upload sketches to the Uno and also to communicate with the Arduino IDE's Serial Monitor.

Another option for communications between your Uno and the laptop or Android mobile is Bluetooth. You can buy a Bluetooth module for your Uno that will allow this. This may be preferable if you need wireless communication.

Application on the Laptop or Android mobile that interprets communication with the Uno

Now you can communicate between the two devices but you need a program running on the Laptop or Android mobile to actually do something with the communication. This application will receive commands from the Uno, and make the desired interactions with the "cloud server", and perhaps respond to the Uno. You will need to have some sort of a command protocol. The details of this will be dependent on which type of communications channel you chose. There are many ways you can accomplish this and the best option will also depend on whether you will be writing this application yourself or trying to find an existing application that suits your needs.

Arduino Uno firmware

This is a sketch you will write and upload to your Uno that sends commands to the laptop or Android mobile via your chosen communications channel and handles any responses.


Trying to Serial.write RAW code properly

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


How to return Char Array Value in Arduino IDE Function?

char char_array[str_len]; is local to the function - it is created on function entry and its memory is released on function exit. The contents of that memory are undefined once it has been released and its data may or may not be valid.

If the caller creates data and passes it to the function, it survives the entire function call-and-return, and the caller will find the correct data in it. Another (less elegant) way to do it is to make data a global object, which again, gives it a lifetime greater that that of the function, but globals are subject to accidental over-writes and abuse by other functions, so they are not recommended unless they are truly the best solution in a given situation.


Negative voltage: How do I scale a 0 to 5 V signal to -10 V to +10 V?

Your question should read:

  How do I scale a 0 to 5 V signal to -10 V to +10 V?

First write the conversion formula:

Vout = 4 * Vin - 10

Testing the formula gives the following:

Vin = 0.0 V ==> Vout = -10 V
Vin = 2.5 V ==> Vout = 0 V
Vin = 5.0 V ==> Vout = +10 V

You will need an op-amp circuit to create this function. In addition you will need a +12 and -12 V supply.

simulate this circuit – Schematic created using CircuitLab

How it works:

OA1 is an op-amp wired in an inverting summing amplifier configuration. We'll address the inversion later but for now all the answers will be "upside-down". The gain is set by -R2/R1 = -40k/10k = -4. If we feed 1 V in from the ADC we will get -4 V out.
R3 provides a negative input. The gain will be set by -R2/R3 = -40k/48k = -5/6. Since it's connected to -12 it will contribute +10 V to the output.
The actual output will be the sum of the two: in our example, +10 - 4 = 6 V.
C1 and C2 provide noise filtering for the op-amp. Place them close to the chip.

Now, what to do about the inversion? We have three choices:

Fix it in the micro controller code. Set +5 V as maximum reverse speed / torque. Set 0 V as maximum forward speed / torque.
Fix it in the servo amplifier and tell it to reverse its command signal.
Fix it in the electronics. By adding another inverting op-amp we can turn the signal the right way up.

The TL082 opamp suggested has two op-amps in the one 8-pin package.

Ref: Inverting Summing Amplifier.

Servo Enable

simulate this circuit

Delay the servo enable until the micro controller has initialised and all other functions are ready. See manual Section 3.2.3, page 73.

Note that this is a simplified relay drive schematic. You need a transistor drive and a snubbing / flyback diode around the relay so one of the small 5V relay boards would be a good solution as they are already built in. An opto-isolator would be simpler.

Ensure that safety circuits (guarding and e-stops) are correctly wired using safety-rated components (and not only, for example, the micro).


How do I manipulate a large number of moving platforms?

In terms of cost, perhaps it would be best to build a 4x4 prototype.

My first thought was to use inexpensive servos with a flexible rod inside a sheath, perhaps a wire, like a bicycle brake/gear.  The amount of movement could then be governed by the size of the armature on an inexpensive servo.

Servos will position themselves after being given the command, so there's no need to wait and do them one-by-one.  Fire off the command, then use some sort of multiplexed output like multiple 74HC595 shift registers to connect to the next one.

If the tiles were spring loaded, such that they returned to the topmost position by themselves, only a simple pull-string is needed to adjust the tile height.  Even a very light filament (like fishing line) would be strong enough for the pull.  This would allow the servos to be positioned even some metres away from the table.


How do I grab data from my Arduino device using a Python program?

It isn't a good idea to open serial in a loop. It can be opened once at the start (or you can retry once per few seconds, if it fails).

Also the method is_open should return true if the serial was successfully opened so you can use it.

Maybe some working example would be a good way to start.


Trouble with Arduino Nano Every and radio transmission using RH_RF69.h

The Nano Every uses an ATMega4809 processor, so it is different from most Arduino's. It could well be that it isn't supported by the Radiohead library.
The error you shortened to [BlaBlaBla...] could possibly give more information on that.
A full list of what is supported by the Radiohead library is here; you should check if the Arduino Nano Every or the ATMega4809 is on there; alternatively, all the #defines for the supported boards are in the header file.
If it turns out your board is not supported, you could ask the library's authors if they would consider supporting it, or you could use a different board (it should work with an Arduino Nano 33 IoT, I think, but please check first).


Your way of sharing the bits between the three values seems a bit confusing. Your code for saving the bits is correct in the meaning of that you save all relevant information. Your bytes are shared in this way (H means high portion of value, L is the low portion of value):

     ____HX_____
b1: | 0000 0000 |
     _LX_ ___HY___
b2: | 00 | 000000 |
     __HZ__ __LY__
b3: | 0000 | 0000 |
     __LZ____
b4: | 000000 | XX |

This is a rather complex way of dividing the space. Also, since you are not using the remaining 2 bits of b4 you don't have to shift there.

When you are getting garbled values from your SD card, it wildly depends on how you are reading the bytes (you haven't shown us the code for that). As a suggestion I will explain how I would do it.

We have 3 values from analogRead(), which each have 10 bits. So in total we have 30 bits, which can be transmitted in 4 bytes (or 32 bits). When adding bits from another value, I think you can use the + operator (opposing to my comment) if the bits of the different values don't overlay (which should be anyway). For my part I like to use the bitwise or | to show more clearly, what is done there and to easier check for errors in alignment (easy to see in binary representation). Do as you like. I will use the | operator for now.

// Get raw accelerometer data for each axis
unsigned int rawX = analogRead(A0);
unsigned int rawY = analogRead(A1);
unsigned int rawZ = analogRead(A2);

byte b1 = rawX & 0xFF;
byte b2 = rawY & 0xFF;
byte b3 = rawZ & 0xFF;
byte b4 = (rawX & 0x0300) >> 2
          | (rawY & 0x0300) >> 4
          | (rawZ & 0x0300) >> 6;

The low portion of the values are saved in the bytes b1 to b3. The upper 2 bits of every value is saved left-aligned to b4 (The & 0x0300 isolates the upper portion, bit 9 and 10, in the values.).

You can read these values in this way:

rawX = b1 | (( b4 & 0b11000000) << 2);
rawY = b2 | (( b4 & 0b00110000) << 4);
rawZ = b3 | (( b4 & 0b00001100) << 6);

b1 to b3 are the start for our retrieved raw values. Then we add the other 2 bits to the raw values. For this we first isolate the bits from b4 from the positions we used in the upper code. Then we shift them to the left, until they are directly above the 8 bits of the start values.


How does Arduino distinguish between SPI programming data and regular data?

In-system programmer is activated with RESET line. During normal operation reset line is not active and ISP module is disabled.

You can find detailed description of AVR ISP in this document:

http://www.atmel.com/images/doc0943.pdf


Not sure if this will fix your problem, but this is a major error:

  char buf1[8], buf2[6];
  sprintf(buf1, "%08lu", myvote.mydate);
  sprintf(buf2, "%06lu", myvote.mytime);

Take a look at sprintf function reference

  A terminating null character is automatically appended after the content.

So, the text buffers are too small. It should be at least:

char buf1[9], buf2[7];


Neither delay or print should be used in an interrupt routine as they use interrupts themselves, instead set a flag (usually a volatile variable) and test for that in the loop. Also be aware that due to contact bounce the interrupt will trigger multiple times for each button press.


First of all, fix the following part of your code:

if (Qout[i]){pinState= 1;}//Checks the array for the value and if it is true sets the pinstate to 1, HIGH
else{pinState= 1;}//If it equals false set it to 0, LOW

into:

if (Qout[i])
{
    //Checks the array for the value and if it is true sets the pinstate to 1, HIGH
    pinState = 1;
}
else
{
    //If it equals false set it to 0, LOW
    pinState = 0;
}

Of course, if you always set pinState to 0, it won't work as you expect :-)

Note that you should rather use HIGH and LOW constants (more readable) instead of 1 and 0.

Finally, you could make the code much simpler this way:

pinState = (Qout[i] ? HIGH : LOW);


Your ISR is not counting the elapsed milliseconds. Instead, it just sets
a flag and lets the main program do the counting when it sees the flag.
Here:

while(digitalRead(PUSHBUTTON) == HIGH)
{
}

you are waiting for the user to press the button. The program does
nothing else during the wait. It doesn't event count the time. Here:

if (int_flag==1){
    millisecs++;
    int_flag=0;
}

you increment once the millisecond count after the wait.

The obvious solution is to count the milliseconds while waiting for the
button press:

millisecs = 0;  // don't forget to reset the stopwatch!
while (digitalRead(PUSHBUTTON) == HIGH) {  // button not pressed
    if (int_flag) {
        millisecs++;
        int_flag = false;
    }
}

(side note: int_flag should be a bool).

There are still many issues with this program. First of all, it should
check that the user did not press the button before the LED came up.

Then, the interrupt period is not one millisecond, because the interrupt
takes some time to be processed by the CPU and to go through its
prologue. By the time you do TCNT1=timer1_counter; you are at least
several tens of cycles late. You should instead configure the timer to
keep the correct period by itself, typically using CTC mode.

Also, there is no point in letting the main program count the
milliseconds when the ISR could do it. E.g.

ISR(TIMER1_OVF_vect)
{
    millisecs++;
}

// Avoid a race condition when reading millisecs.
static inline unsigned int getMillisecs()
{
    noInterrupts();
    int millisecsCopy = millisecs;
    interrupts();
    return millisecsCopy;
}

Note that the time keeping variables should be unsigned in order to
avoid undefined behaviour on overflows.

Finally, it may be a good learning experience for working with
interrupts, but in the end just using millis() or micros() would be
the easiest way to achieve what you want.


Can I Interrupt on any keypress on this keypad?

No, you can't. Owing to the fact that you have to manually cycle through each row (or column, depending on which way you are holding your head at the time) in order to read which keys are pressed there is no way to relate a button to an interrupt.

The only possible way would be to use an external keypad interface chip (you could roll your own with another Arduino) which has an interrupt signalling facility in it.


WS2812B Led Digital Panel Matrix Flexible Screen 8*8. Some LEDs that are not supposed to, switch on


How to work with WS2812B 16x16 matrix panel from aliexpress

It's just a string of WS2812B LEDs that have been "bent" into a grid. You treat it exactly like any other WS2812B strip of LEDs.
You have 256 LEDs, and as far as the Arduino is concerned, they are just in a line numbered 0-255.
The "grid" arrangement is solely down to you to you to calculate.  Fortunately 256, or 16x16, is very easy to work with: you have a byte which can represent any one of the LEDs, and each half of the byte (a nibble) is one coordinate.
The traditional calculation to convert X and Y into a linear number is:
num = x + y * width

where width is the number of LEDs in the X direction (16).  However since we're working with a width of 16 that can be optimized to use bit-shifting and bitwise operations:
num = x | (y << 4)

That is assuming LED 0 is on the left (either top or bottom) and LED 1 is one place to the right.
Will you need an external power supply for it? Yes, most certainly (and they even provide you with a dedicated power connection for it). 256 LEDs, if all are turned on full brightness at once, could consume up to about 15 amps (20mA per channel, three channels per LED, 256 LEDs).


my servo is only moving once, and then stops You mean it turns 180° then no more? Once it has reached 180° (or 2000 µs) you need to decrease val by one to go the other way (from 2000 to 1000). For example:

int direction = 1;  // 1 or -1
void loop()
{
   int val;

   val = incPulse( servoRoll.read(), direction);
   servoRoll.write(val);
   if (direction <= 1000 || direction >= 2000) {
      direction = -direction;
   }
   delay(10);
}


Why does the serial monitor needs to be repeated a command?

It worked fine for me, if I typed the entire command, "LO:" or LF:" (without the quotes of course). However, if I typed and sent one character at a time, it failed. The problem is quite likely the code:

   if (Serial.available() > 0)
         {string = "";}

If you send all of the characters at once, the while( Serial.available() ) loop will get the whole line and match it. But if there is any pause between characters, what does that if statement do? (Hint: loop() executes way faster than you can type!)

I was using the serial terminal built into the Eclipse IDE. Different terminal software might behave differently when you type a string and send it. Remember, any gaps between characters, and that first if statement gets time to do its dirty work.


No data sent over serial port in linux c++

The Arduino resets the moment you open the serial port.  Once reset the bootloader executes, which consumes (and discards since it's invalid) any serial data for a second or so before your sketch runs.

Because of this anything you send immediately after opening the serial port is ignored.

There are two commonly accepted "fixes" for this:

Delay for a pre-defined period after opening the serial port, and
Have the Arduino send a "READY" signal before doing anything else which your program waits for before sending.


Uno R3's a4 and a5 not working after installing itead SD Shield 3.0

The shield has pull-up resistors for I2C/TWI on pins A4 and A5. Special care (resistor bridge) needs to be taken if using these as analog pins. Please see the schematics for more details.

https://www.itead.cc/wiki/images/4/46/Sch_sd_shield_3.0.pdf

Cheers!


One Arduino collects data, several other Arduinos use the data. What is a simple way to do this?

It is possible to send out data from one Arduino to multiple others at once via serial (UART). You simply connect the TX of your master Arduino to the RX of all the slave Arduinos. All receiving Arduinos will get the same data with that. You only need 1 pin (for the connection sender TX to the multiple RX). This is a bit limited to the number of slaves and the speed, but that doesn't seem to be an issue here (since you only have a few).

This is a 1-way communication, since at any line there must not be more than 1 TX (sender). If you have more than 1 TX on a line, you will burn your hardware as soon as both TX send out data simultaneously.

I remember some sites that stated it to be possible to also do multiple sender UART, when you adhere to a protocol and put in some safety hardware (I think they used diodes and current limiting resistors). But that is somewhat out of scope here. If you really need a 2-way communication, you maybe should rethink the whole structure of your solution. As Juraj suggested in his comment, it might then be easier to unite the functions to less Arduinos.

Be sure, that the Arduinos share the same ground. This is needed for any communication, when you don't utilize extra hardware (like an optocoupler).


Best way to implement score board logic using Arduino and Shift Registers?

There isn't really a best way (and such questions are usually discouraged as they can easily descend into argument).

Personally I would go for chaining all of the '595s together so you only ever use the 3 pins; it gives you the opportunity to use a smaller MCU like the ATtiny when you put it all on a board later which makes it (slightly) cheaper and (potentially) smaller.

From a software point of view, it doesn't make a huge amount of difference - doing it the way I have suggested means you send the 3 values out in the correct order every time one of them updates. Separating the 3 scores with their own dedicated pins means juggling which one needs to be updated each time. Neither option is particularly complicated and with this sort of application efficiency of code is mostly redundant because the entire MCU is dedicated to the (simple) task.


Here is some untested code that uses a non-blocking timer to flash the leds.

uint8_t redLED   = 2;
uint8_t greenLED = 4;
uint8_t blueLED  = 3;

static uint8_t redRunning   = HIGH;   // leds off at start
static uint8_t greenRunning = HIGH;
static uint8_t blueRunning  = HIGH;

// static bool freq = 34;             // not sure what this is

void setup() {
  Serial.begin(115200);               // initialize the Serial
  Serial.write("started");

  pinMode(redLED,   OUTPUT);
  pinMode(greenLED, OUTPUT);
  pinMode(blueLED,  OUTPUT);

  digitalWrite(redLED,   HIGH);       // leds off
  digitalWrite(greenLED, HIGH);
  digitalWrite(blueLED,  HIGH);

//freq     = false;
  tick     = false;                   // time interval signal
  ledState = false;                   // state of led display

  static uint32_t ledTicker = millis();
}

void loop() {

  if (millis() - ledTicker >= 125) {             // Once every 125 ms
    ledTicker = millis();
    tick = true;                                 // set the tick flag
    ledState = !ledState;                        // changes state at every tick
  }

  if (Serial.available() > 0) {
    String s = Serial.readStringUntil('\n');

//  String s = Serial.readStringUntil("#");      // Until CR (Carriage Return)
//  s.replace("#", "");
    Serial.println("s:" + s);

    if (s == "red_ON"   )  redRunning   = LOW ;  // sometimes, this format is easier to read
    if (s == "red_OFF"  )  redRunning   = HIGH;

    if (s == "green_ON" )  greenRunning = LOW ;
    if (s == "green_OFF")  greenRunning = HIGH;

    if (s == "blue_ON"  )  blueRunning  = LOW ;
    if (s == "blue_OFF" )  blueRunning  = HIGH;
  }

  //
  if (tick) {                                    // 125 ms passed, so update the leds
    tick = false;                                // reset tick so that leds change only once every tick

    if (ledState) {                              // state of leds at this tick
      digitalWrite(redLED  , redRunning  );
      digitalWrite(greenLED, greenRunning);
      digitalWrite(blueLED , blueRunning );
    }
    else {                                       // all off this time around
      digitalWrite(redLED  , HIGH);
      digitalWrite(greenLED, HIGH);
      digitalWrite(blueLED , HIGH);
    }
  }
}


Arduino Not Working as Intended when using barrel jack

i agree with majenko, maybe you know how to fix it but if you do not know here is a site with good information to make you're own  5 volt Regulated source.

http://www.rakeshmondal.info/IC-7805-Voltage-Regulator

sorry for my bad english and good luck. :D


How to know positive and negative in breadboard

You decide which rails are positive and which are negative when you connect them to the + an - from your power supply or battery.

A breadboard isn't polarised per se. It's just a bunch of cross-connections inside a perforated plastic case. No active or passive components inside.

Some manufacturers may choose to paint indications regarding where to connect the positive and negative rails, but those are just a guideline. Ultimately it's your choice, you're free to connect + and - wherever you want in the breadboard rails.


comprehensive list of common library methods that do not work in interrupt service routines

The basic rule is quite simple, but the list is practically impossible to produce.

The rule is:

You cannot use anything that relies on an interrupt to function from within an interrupt service routine.

AVR chips only have one interrupt priority. Only one interrupt routine can function at a time. If an interrupt fires whilst an ISR is currently executing that interrupt will be delayed until the ISR finishes.  If that ISR relies on a function that itself needs an ISR to fire (such as millis(), or serial transmission), then it will never get to finish.

A partial list of things to know:

You cannot transmit serial more than there is room in the TX buffer for, or it blocks.
The time generated by millis() (which delay() relies on) never changes.
Servo motors cannot be controlled and will jitter if an interrupt routine takes too long.
tone() generated sounds will also jitter since the ISR is delayed while another ISR is executing

And basically anything else that uses interrupts.


problem using std::map. Are there known obstructing macros?

The C++ standard library is not available for arduino.

Some implementations of similar containers or certain functions exist on the web, but for the most part the standard library is impractical on a device with such small amounts of both RAM and program memory.

An implementation of SGI STL for AVR has been documented here: http://andybrown.me.uk/wk/2011/01/15/the-standard-template-library-stl-for-avr-with-c-streams/

map is mentioned as being particularly impractical for anything less than an arduino mega(1280). An example of maps working is included on the page so it seems like a good lead if you really must use one, but I've never done this myself so I cant guarantee it still works.


Using MouseX in processing to control LEDs. Error in code - LEDs remain off

lightsOn=byte(mouseX);

A byte can be any number from -128 to 127 (Java has no concept of "unsigned" values). The Arduino will reinterpret that as a value from 0 to 255.

if (data>300)

255, the maximum value, can never be more than 300 - so this will always fail.

You need to re-think what data you are sending and how you want to send it.


Why Won't my Serial Read value stay the same

When you type "100" you aren't sending the number 100. You're sending the characters "1", "0", "0", and whatever selected line ending you have (CR, LF, or CR and LF).

So if you have CR+LF for your line ending you're reading the numbers 49, 48, 48, 13 then 10.

You need to read the characters as they arrive and group them into a representation of the number (up until you get the line ending), then convert that representation into an actual number.

Reading Serial on the Arduino


It's most likely a custom part for which there is no public data sheet. LCDs are almost always custom-designed, and require special driver circuitry. This is especially true for such mass-produced items as calculators.


Using HC-08 bluetooth module with arduino

void setup(){
  //Initialize Serial Monitor
  Serial.begin(9600);
  Serial.println("ENTER AT Commands:");
  //Initialize Bluetooth Serial Port
  Serial3.begin(9600);
}

void loop(){
  //Write data from HC08 to Serial Monitor
  if (Serial3.available()){
    Serial.println("Reading from bluetooth");
    Serial.write(Serial3.read());
  }

  //Write from Serial Monitor to HC08
  if (Serial.available()){
    Serial.println("Writing to bluetooth");
    Serial3.write(Serial.read());
  }
}


Arduino micro lost connection after first programming

The USB part of the Atmega32U4 needs quite a bit of software to operate correctly, which is either not included in the basic blinky example or you got a binary for a different Arduino model.

The syslog looks like there is a bootloader present after Reset for a couple of seconds..

[22620.497393] cdc_acm 1-2:1.0: ttyACM0: USB ACM device
     ^
[22627.966141] usb 1-2: USB disconnect, device number 32
     ^

.. which shuts down and starts blinky. This is documented on the ArduinoBoardMicro page.

Re-flashing the chip is a bit tricky in this state, as you must press the reset button at the "right" time just before the software wants to access the chip.


How to control speed of 28BYJ-48 stepper motor without using library?

A stepper motor always needs a driver. As the ULN2003 (or similar) driver is normally shipped together with the 28byj-48 motor, I will assume, that you have this driver.
The ULN2003 has 6 pins:

Vcc and ground need to be connected to your power source. Note, that it is risky to connect Vcc to the 5V pin of the Arduino. While that might work, when there is no load on the motor, a loaded stepper motor can draw rather high currents. Letting these current run through the Arduino might fry the voltage regulator or the power switching diode. High currents should always flow past the Arduino, not through it.

The other 4 pins (which are marked as IN1 to IN4 on my ULN2003 driver board) are for controlling the phases. You need to connect these 4 pins to 4 individual digital outputs on your Arduino. As these are the phases of the stepper motor, you need to activate them in the correct order. You have this pattern
  1000
  0100
  0010
  0001

for full steps, and this pattern
  1000
  1100
  0100
  0110
  0010
  0011
  0001
  1001

for half steps. Each digit of each number represents the status of the corresponding phase; 1 means activated/HIGH, 0 means deactivated/LOW. To move the stepper motor forward, you move in the list of phases down. To move backwards, you move up in the list.

When using a stepper motor, the speed is determined by the number of steps per time interval. Let's assume, we want to use delay(), which is really easy, though not recommended (see explanation below), we can do steps and delay() inbetween:
void loop(){
    step();
    delay(10);
}

This code would do a step and then delay for 10ms. Thus we have about 1 step every 10ms. With 64*64=4096 steps per revolution (the motor itself seems to have 64 steps; additionally there is a gear with ratio 64 mounted on it; this might be different for you) we get a full revolution every 4.096s. When you use half the delay(), the speed will be double: with 5ms delay we get a full rotation every 2.048s. So you can use the delay() to set the speed of the motor.
Now we need the step() function, that I used above. There are multiple ways of writing this in code. I would propose to put the pins and phases into arrays and iterate through them with a static variable, which holds the current position in our phase pattern. Something like this:
//in global scope defining the pins for the phases
int stepper_pins[4] = {2, 3, 4, 5};

void step(bool forward){
    const uint8_t phase_pattern[][4] = {
        {1,0,0,0},
        {0,1,0,0},
        ...
    };
    static uint8_t current_step = 0;
    if(forward){
        current_step = (current_step + 1) % 4;
    } else {
        current_step = (current_step - 1) % 4;
    }
    for(uint8_t i=0;i<4;i++){
        digitalWrite(stepper_pins[i], phase_pattern[current_step][i]);
    }
}

We hold the phase pattern in a 2-dimensional array. The variable current_step is declared static, so it will keeps its value between the executions of the function. Then - depending on the parameter forward - we increment or decrement the current step and take that value modulo 4 (the number of phase patterns). That ensures, that current_step stays in the index range of our phase pattern array and will wrap around from the end of the pattern to the start and vice versa. After that, we loop through the 4 stepper pins and set them according to the current element in the phase_pattern array. You can easily adept that code for half steps.
Note, that this code is totally untested. Also this can be reached with way less code (at least for full steps), but I think this code is better understandable.
Now: Why not using delay()? This function will block the execution of other code. In that time the Arduino is just fiddling thumbs. In general that is considered bad practice. It is good, when you only need that one functionality and no responsiveness. But lets assume, you want to add a button, so that the motor reacts to your button presses. Long delay() calls will impact the responsiveness of your code. So instead you could use a non-blocking coding style. In the Arduino world this is easily done with the millis() function, which returns the number of milliseconds since startup and thus acts like a clock. Refer to the BlinkWithoutDelay example, that comes with the Arduino IDE, and to the many tutorials on the web, that you can find with search terms like "Arduino millis tutorial" or something like that.

EDIT:

how your code controlling the motor speed?

The delay() call is determining the motor speed. If you want to change the speed, you need to change the value of the delay. You didn't mention any input device, so I just leave the speed constant. But of course you can define a variable for the delay and change that delay based on some input device. How exactly that is done depends on your requirements, mainly what type of input you want to use.

if we didn't specify any delays in between steps, will it spin at its max rpm?

When you don't use any delay, then most likely your code will run too fast for the motor. The driver will set the motor phases very very fast. So fast, that the motor cannot follow that (because it has a specific inertia). (Much like the wheels of your car can loose the grip on the street and spin without moving the car, the stator of the motor can loose the magnetic grip on the rotor, which leads to further rotating phases, but a rotor, that is standing still) So you reach the maximum speed before that and it depends on the motor, the driver, how much load is on the motors and how much current your power source can give you (I once tried to provide 3 of these motors with a 1A power supply, but they moved very weak, until I upgraded to a bigger power supply, that can provide about 5A, I think). You need to test yourself, how fast you can drive your motors. So try to lower the delays step by step, until the motor cannot move in your setup anymore. Then you have the minimum delay, and the maximum speed.
Note: The delay() function won't be accurate for very low delays in the single digit milliseconds. In that case you might wanna use delayMicroseconds(), which is more accurate in that range and also can get in you in the microsecond range.


What is the best delay to use between characters sent to the serial port

SoftwareSerial has a considerable overhead. It can often send at 115200 successfully but 9600 is about its limit for receiving, and you're trying both send and receive. In addition, for each character your code receives, it transmits considerably more than that 1 character (11 characters, by my count). It isn't too surprising that it would fall behind. You will need to either reduce the size of what you echo or reduce the rate at which you send characters to it (which is what you accomplished with your delay) so that the transmission (echo) rate can keep up.

Update:

The OP reports success with continuous reception by, and transmission from, the Arduino at 57600 baud (but not at the same time). The transmission rate would be consistent with my experience transmitting at 115200 baud (blindly and for short bursts, to reconfigure ESP8266-01s that were shipped with a preset 115200 rate.


Any way to not explicitly include dependent libraries?

No, it is not possible. The IDE needs to know which libraries you are using so that it can compile the source code for them.

Other IDEs have got around the problem by recursively scanning the libraries themselves and building up a list of dependencies (such as UECIDE) but this is not something that the Arduino IDE has been programmed to do.

The only other possible option might be to create a single massive library that contains everything that the "main" library relies on, however this may cause problems with other libraries also wanting the same things and you ending up with massive conflicts.


Solved simply by condensing code and getting rid of unnecessary variable declarations.

Corrected program:

    int motorPin1 = 3;
    int motorPin2 = 9;
    int DCfanSpeed = 0;

    void setup()
    {
      pinMode(motorPin1, OUTPUT);
      pinMode(motorPin2, OUTPUT);
      digitalWrite(A0, INPUT_PULLUP);
      digitalWrite(A1, INPUT_PULLUP);
      digitalWrite(A2, INPUT_PULLUP);
      digitalWrite(A3, INPUT_PULLUP);
      Serial.begin(9600);
    }

    void loop()
     {

       int voltsZero = analogRead(A0)/204.6; // OFF SWITCH
       if(voltsZero == 5)
        {
          delay(300);
          if(voltsZero == 5) DCfanSpeed = 0;

           while(voltsZero == 5)
            {
              analogWrite(motorPin1, DCfanSpeed);
              analogWrite(motorPin2, DCfanSpeed);
              voltsZero = analogRead(A0)/204.6;

            }
         }

      int voltsOne = analogRead(A1)/204.6;    // LOW SWITCH
      if(voltsOne == 5)
        {
          delay(300);
          if(voltsOne == 5) DCfanSpeed = 128;
          while(voltsOne == 5)
           {
             analogWrite(motorPin1, DCfanSpeed);
             analogWrite(motorPin2, DCfanSpeed);
             voltsOne = analogRead(A1)/204.6;
           }
        }

       int voltsTwo = analogRead(A2)/204.6;  //  MED SWITCH
       if(voltsTwo == 5)
        {
          delay(300);
          if(voltsTwo == 5) DCfanSpeed = 191;
          while(voltsTwo == 5)
           {
             analogWrite(motorPin1, DCfanSpeed);
             analogWrite(motorPin2, DCfanSpeed);
             voltsTwo = analogRead(A2)/204.6;

           }
        }

      int voltsThree = analogRead(A3)/204.6;  //  HIGH SWITCH
      if(voltsThree == 5)
        {
          delay(300);
          if(voltsThree == 5) DCfanSpeed = 255;
          while(voltsThree == 5)
           {
             analogWrite(motorPin1, DCfanSpeed);
             analogWrite(motorPin2, DCfanSpeed);
             voltsThree = analogRead(A3)/204.6;
           }
         }

    }


Arduino UNO and RS485 Communication Problem

I would suggest you simplify your setup to the point where you have a 'working baseline  configuration', and then start building the system up one step at a time from there.

Start by eliminating the SoftwareSerial interface as a possible contributor to the problem.  Get an Arduino Mega with multiple hardware serial ports.

Next, verify that you can send characters to the selected hardware serial port and receive those same characters back when the Txn and Rxn lines (the 'n' here is the selected hardware serial port number) are connected via a jumper wire. This is called a 'loopback' configuration and is a basic serial comms troubleshooting technique (software serial ports don't support simultaneous transmit and receive, so they don't support loopback testing).  Don't proceed until you have this step completed successfully.

Next, get a second RS-485 module and extend your previous 'loopback' configuration with the hardware serial port on the Mega to include the two RS-485 modules.  Then you should be able to send characters out to one RS-485 module and receive the same characters back from the other, by connecting TXn to DI on one of the two RS-485 modules, and Rxn to DO on the other.

At this point you will have verified all the communications connections, so you can be confident that whatever you send will actually show up at the DO port of the RS-485, and whatever shows up at the DI port of the RS-485 will actually make it back to your serial console.  Now you can connect the sensor and figure out any issues do to data formatting, command sequences, and the like.

This basic 'cut the problem in half' building block technique will work on any system, large or small, simple or complex.

Frank


Uno - ESP32 SoftwareSerial communication won't work

On the ESP32 you would never use SoftwareSerial except under exceptional circumstances.
The ESP32 has three hardware UARTs that can be mapped to any pin combination on the board.
The general usage is:
HardwareSerial Serial2(1); // Use UART channel 1

void setup() {
    Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);
}

UARTs are numbered 0-2 where 0 is pre-assigned to the TX/RX (USB connection) pins and is used for debugging and programming.  UARTs 1 and 2 are not normally assigned to anywhere and you can use them as you see fit.


I don't have experience with Processing, but probably that is what you need. It communicates through USB and with the CreateWriter function, you can create a text file.

More about Processing can be found at Processing

Also another thread at Electronics stack exchange might help:

Related question

Alternatives (also mentioned in the above thread):

Use serial port directly with a terminal application on the PC
Use an SD card inside the Arduino to log


declared variable inside void setup is forgotten in void loop

Yes, that is how C and C++ (and most other C-like languages) work. Variables have "scope". Any variable define inside a pair of curly braces (between a { and a }) is only visible inside those braces.

If you want to reference a variable in both setup() and loop(), you have to make it a global variable, defined at the top of your code.

#include "Servo.h"
Servo servo1;
int x_position = 90;  //Define your global var(s) here

void setup() {
    int x_key = A0;  //This var only exists inside the setup function
    servo1.attach(2);
    pinMode(A0, INPUT);
    pinMode(2, OUTPUT);

}

void loop() {
    if (analogRead(A0) < 512) {
        x_position++;
        servo1.write(x_position);
    }
}


Here's an instructable on ESP8266+Arduino+thingspeak.com environment monitors:
http://www.instructables.com/id/ESP8266Arduinothingspeakcom-environment-monitors/

Lots of examples in the thingspeak documentation:
https://www.mathworks.com/help/thingspeak/examples.html

-Rob


You should not use the same Serial interface to debug and talk to your SIM900. You should use a SoftwareSerial interface to talk to the SIM900 and use the hardware Serial to send response back to your computer.

Try this code:

#include <SoftwareSerial.h>

const byte rxPin = 2; // Wire this to Tx Pin of SIM900
const byte txPin = 3; // Wire this to Rx Pin of SIM900

// We'll use a software serial interface to connect to SIM900
SoftwareSerial SIM900(rxPin, txPin);

void setup() {
  Serial.begin(115200);
  SIM900.begin(9600); // Change this to the baudrate used by SIM900
  delay(1000); // Let the module self-initialize
}

void loop() {
  Serial.println("Sending an AT command...");
  SIM900.println("AT");
  delay(30);
  while (SIM900.available()){
     String inData = SIM900.readStringUntil('\n');
     Serial.println("Got reponse from SIM900: " + inData);
  }
}


How to skip the first line and output the second?

IF and only IF you want exactly what you have asked for which is alternate lines not to be output then this is a very crude and quick solution.

Outside of loop() add this declaration:

bool skipNextLine = true;  // true skips the odd lines, false skips even lines

And change the end of your code like this:

  if (EncVariation != 0) {
    encoder0Pos = encoder0Pos + EncVariation;
    int degrees = (encoder0Pos * 6) % 360 ;
    if(degrees<0){ deg = 360 + degs; }
    if (!skipNextLine)
    {  // This will skip alternate lines
        Serial.println (deg);
        skipNextLine = true;
    }
    else
    {
        skipNextLine = false;
    }
  }


How to handle multiple simultaneous Arduino development environments?

I'm yet to see evidence that there is a sound or comprehensive way to do this, so would be pleased to read better suggestions.  As for why you would want to, there are a number of board support plugins/extensions that are moderately functional on some recent Arduino versions, but partially or entirely incompatible with others.

You can achieve a very limited partial version segregation by creating a new sketchbook folder for each version, which would host your libraries and hardware folders.

To get the IDE to pick this up, you could have a custom preferences file (rather than preferences.txt) with that sketchbook location set.  You can specify the file to use on the command line, for example:

/opt/arduino-1.6.8/arduino --preferences-file ~/.arduino15/alternate.txt

However, there is still quite a bit related to extra board support and similar stored in the settings folder, and at present that is hard coded to the same "Arduino15" or ".arduino15" path for all recent versions.

This hard-coding of the settings folder is implemented in the version of Platform.java applicable to the operating system you are running under, so it is not clear how you could change this except at the source level, by modifying the jar, or by playing file-system level tricks with the operating system (process-unique mounts, etc).


In your code this line:

 if ( digitalRead (9 == HIGH)) {

...is likely passing the function "digitalRead()" the value zero as "9 == HIGH" is likely false.

Likely what you want to do is check if the value returned by the function "digitalRead()" is high.  Try:

 if ( digitalRead (9) == HIGH) {

...instead.


A general rule is to keep definitions such as enum's within the context of the class (library). Below is a possible refactoring:

class RTC_DS1307 {
public:
   enum SqwPinMode { OFF = 0x00, ON = 0x80, SquareWave1HZ = 0x10, SquareWave4kHz = 0x11, SquareWave8kHz = 0x12, SquareWave32kHz = 0x13 };

   ...
   static SqwPinMode readSqwPinMode();
   static void writeSqwPinMode(SqwPinMode mode);
   ...
};

Cheers!


Yes it is (see datasheet datasheet) ... the DS3231 has 2 alarms.

There is also a library for the Arduino, see: library.
The alarm(s) can be set (repeatedly) via one of the following functions:

Alarm.alarmRepeat(hours, minutes, seconds, function);
Create an alarm that will call a function every day at a particular time.

Alarm.alarmRepeat(dayofweek, hours, minutes, seconds, function);
Create an alarm that will call a function every week on a specific day at
a particular time.

 "dayofweek" can be dowSunday, dowMonday, dowTuesday, dowWednesday,
 dowThursday, dowFriday, or dowSaturday.

Detailed info and more functions: link


Modbus Communication protocol for Arduino as Slave

It's not very well documented for the slave but maybe that is because it only has two methods...

It looks like the slave library is contained in the same library as the master but with name ModbusSlave485.h

You can see in the .h it only has two public methods. One is connfigure() and the other is update(). see below an extract from the .h which explains what each method does.

#include "ModbusSlave485.h"

mySlave = ModbusSlave485();

void setup()
{
  mySlave.configure(slave, baud, parity, txenpin);
}

void loop()
{
  //check for update from master
  mySlave.update(regs, regs_size)
}

extract from .h

/*
 * configure(slave, baud, parity, txenpin)
 *
 * sets the communication parameters for of the serial line.
 *
 * slave: identification number of the slave in the Modbus network (1 to 127)
 * baud: baudrate in bps (typical values 9600, 19200... 115200)
 * parity: a single character sets the parity mode (character frame format):
 *         'n' no parity (8N1); 'e' even parity (8E1), 'o' for odd parity (8O1).
 * txenpin: arduino pin number that controls transmision/reception
 *        of an external half-duplex device (e.g. a RS485 interface chip).
 *        0 or 1 disables this function (for a two-device network)
 *        >2 for point-to-multipoint topology (e.g. several arduinos)
 */
  void configure(unsigned char slave, long baud);

/*
 * update(regs, regs_size)
 *
 * checks if there is any valid request from the modbus master. If there is,
 * performs the requested action
 *
 * regs: an array with the holding registers. They start at address 1 (master point of view)
 * regs_size: total number of holding registers, i.e. the size of the array regs.
 * returns: 0 if no request from master,
 *  NO_REPLY (-1) if no reply is sent to the master
 *  an exception code (1 to 4) in case of a modbus exceptions
 *  the number of bytes sent as reply ( > 4) if OK.
 */
  int update(int *regs, unsigned int regs_size);

  // constructor
  ModbusSlave485()
  {
    myDevice = RS485();
  }