text:
Two floating point values do not get added and printed on ESP-WROOM-32
I have a Olimex ESP32-PoE board which has a ESP-WROOM-32.
I just found out a strange behaviour for printing floating point numbers on the board.
Sketch
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  float a=34567891.234;
  float b=2.3456;
  a++;
  Serial.print(a+b, 4);
  Serial.println("");
  delay(1000);
}

the sketch is extremely simple where I want to add two floating point numbers, one a big and another small to print their addition result upto 4 places.
Output
on the serial console in the Arduino IDE
34567896.0000
34567896.0000
34567896.0000
34567896.0000
34567896.0000
34567896.0000
34567896.0000
34567896.0000
34567896.0000
34567896.0000
34567896.0000
34567896.0000
34567896.0000

Everytime I increment the float a using a++ i expect it to increment by one and print the result but the output above is completely off.
Without Increment
void loop() {
  // put your main code here, to run repeatedly:
  float a=34567891.234;
  float b=2.3456;
  Serial.print(a+b, 4);
  Serial.println("");
  delay(1000);

}

output
34567896.0000
34567896.0000
34567896.0000

Same output.
Is this Board specific or is the Serial.print not supporting float?

Try doubles.  34567891.234 needs 35 bits of precision to keep the decimals, but floats only have 23.

There is a similar question, but that confuses me even more: https://stackoverflow.com/questions/8561393/is-using-increment-operator-on-floats-bad-style

The thing that confuses me, is that even if the compiler decides to round up both numbers (I remember I had this somewhere, that if you do not specify that the sum is also float, it acts as if they are integers), it would still be 34567895.0000, not 34567896.0000. So I am also at a loss here

As already stated in comments and Dave X's answer, floats have a limited
resolution. That resolution is given by the constant FLT_EPSILON,
which is the difference between 1 and the smallest float larger than 1.
On any system conformant to IEEE 754, FLT_EPSILON is 2−23,
or about 1.19e-7. The implication is that, within the interval
[1, 2], the real numbers that can be exactly represented by floats
are the multiples of FLT_EPSILON. The resolution, however, degrades as
you consider larger numbers. Within the interval [2, 4] it is twice
as coarse. Within [4, 8], it's four times as coarse and so on:
interval     resolution
------------------------------------------
1    – 2     2^-23 ≈ 1.19e-7 (FLT_EPSILON)
2    – 4     2^-22
...
2^23 – 2^24  1
2^24 – 2^25  2
2^25 – 2^26  4
...

Your number a is just slightly larger than 225. Within this
range, the numerical resolution (aka “ulp”: unit in the last place)
is 4 (last line in the table above). Thus floats in this range can
only represent exact multiples of 4. When you write
double a=34567891.234;

the compiler replaces this by the closest float, which happens to be
34567892. Same thing for b, but in this case the rounding error is tiny
and inconsequential (about -1.1e-7). When you write
a++;

you are replacing a with the float that is closest to a+1, which
happens to be a itself. So the instruction has no effect. When yo do
Serial.print(a+b, 4);

you are computing the float closest to 34567892+2.3456, which is
34567896.
A double instead has a resolution DBL_EPSILON which is
2−52, or about 2.22e-16. This gives you some precision
margin, but be aware that AVR-based Arduinos do not really support
doubles and treat the double keyword as a synonym for float. This
may only be an issue if you ever have to move your code to a more
traditional Arduino.

I didn't know about the AVR double-float synonym.  thanks.

Try doubles instead of floats.
Your initial value, 34567891.234 needs 35 bits of precision to keep track of the decimals, but floats only have 24 bits pf precision. So to have enough precision to keep track of the difference between 34567891.234 and 34567891.234+1, you need higher precision storage.
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  double a=34567891.234;
  double b=2.3456;
  a++;
  Serial.print(a+b, 4);
  Serial.println("");
  delay(1000);
}


text:
MKR Fox 1200 doesn't wake up from sleep
I have a Sigfox Arduino meassuring some sensors, sending it to the cloud and then falling asleep.
void setup()
{
Serial.begin(9600);
  while (!Serial) {};
  if (!SigFox.begin()) {
    Serial.println("Shield error or not present!");
    return;
  }
  SigFox.debug();
  delay(100);
  SigFox.end();
}

void loop()
{
SigFox.begin();
  delay(100);
  SigFox.status();
  delay(1);
  SigFox.beginPacket();
  SigFox.print("123456789012");
  int ret = SigFox.endPacket(true);

  if (ret > 0) {
    Serial.println("No transmission");
  } else {
    Serial.println("Transmission ok");
  }
  Serial.println();
  SigFox.end();
LowPower.sleep(20000);
}

The Issue I have is that the sending to the backend doesn't work when leaving the sigfox.debug() away and that it doesn't wake up from the sleep. It stays in sleep forever.

Looks like same problem as described in https://forum.arduino.cc/index.php?topic=483636.0
Solution described in that thread:
Add
LowPower.attachInterruptWakeup(RTC_ALARM_WAKEUP, alarmEvent0, CHANGE);

to setup() and create a dummy function
void alarmEvent0() {
}

No that sadly doesn't fix the issue

source: Stack Exchange

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

sort: votes


text:
How do you use the plastic cover/case that came with Arduino?
They have holes for screw on, on top of the holes on the Arduino itself. Where can I find parts that are compatible with this case/cover? What was the intended use of this case/cover? Thanks.

Looks like there are some taps on the sides, so it should just snap in. USB side at the top (in your image). (PS this case goes on the bottom of the UNO)

just match up the shape of the board to the shape of the case .... the shape is not completely rectangular

What is the point of matching it? I bought a stand from amazon and that just screws to the board itself. Same with the stand that came from the starter kit. I'm probably going to throw this away, if there is no use...

What was the intended use of this case/cover? .... this question is unclear .... only you can answer what you intend to use the cover for

I bought Arduino uno and it came with it... I guess they just don't want the wires that stick out touch metal, like laptop covers? they probably thought leaving the back side naked was a bad idea...

The cover was developed for Arduinos with on-board Ethernet with POE and similar cover has the Ethernet shield with POE. POE - power over Ethernet is 48 V, so it is better to not to touch a soldering point with this voltage.
The arduino.org boards were sold with this cover. Some of them had on-board esp8266 and soldering points leading to esp8266 sensitive pins. Again, better not to touch.
I used the cover to attach the Arduino to a DIN rail over a DIN rail clip.

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


text:
PWM of a frequency signal?
Working on my first real sketch, so will try to keep this short.  Feel free to ask more info if needed.
To power a flyback transformer I need to apply PWM -to- a PWM signal.  The easiest way to describe this is that while a standard PWM signal is 'on' for some set time, then 'off' for the remainder of the period, I need to send a signal where the 'on' is actually a 14kHz square wave of 50% duty...then pulse this signal ~1 to 100% duty at ~500Hz.
No problem with the 14kHz PWM - I found the PWM.h library and set that up.
But what is the best way to chop that up with a second PWM at, say 500Hz?
With some amount of kludge, can I 'bit bang' it with DO - WHILE?  Will WHILE read a variable outside the loop?  Are there easier ways?
i=1;
do {                                //Pulse microsecond 'frames' of high freq signal?
                                    //ie 14kHz carrier PWM'd at 500Hz = 2000 microseconds per 'frame' cycle
                                    //at 50% duty would be 1000 micros high and 1000 micros low

    pwmWrite( outpin, 128 );        //Turn on 14kHz carrier at 50% duty
    delayMicroseconds(1000);        //Delay to generate the 'HIGH' portion of the frame
    pwmWrite( outpin, 0 );          //Turn 14kHz carrier off
    delayMicroseconds(1000);        //Delay to generate the 'LOW' portion of the frame
   } while (i == 1);                //...and keep doing loop while the state is '1' or 'ON'

delay(1000);                        //?Will this allow the above loop  to repeat while waiting here for 1 second?
i=0;                                //i != 1, so break out of the while loop above?
                                    //then continue doing other stuff below...

Any help greatly appreciated.

A 14kHz 50% pwm is not a pwm, it is a tone of 14kHz. How accurate should the 14kHz carrier and the 500Hz modulation frequency be? It is possible with 'tone' for the 14kHz and 'millis' for the 500Hz.

Your do ... while here is an infinite loop.

Thanks for the input.  I considered the tone() command as well.  In this instance they are virtually interchangeable.  tone() might save one step because it is automatically 50% duty, where i have to specify 50% (128) with every call of pwmWrite.  Accuracy is not critical.  The 14kHz tone/pwm I currently have is more than accurate enough.  The 500Hz could drift around quite a bit, too.  Seems like I need to set up the i variable going into the loop and increment it from inside there?

Consider using the TimerOne library to set up a timer/interrupt-based callback for the 500Hz portion, which toggles a 14kHz tone().

Possibly this is a better way to attack from the WHILE side? (sorry, not getting code to work)
'  i = 1 ;
while (i<=100) {
pwmWriteHR( pinout, 128 );
delayMicroseconds(500);
pwmWriteHR( pinout, 0 );
delayMicroseconds(500);
(i ++);
}'

It should work, but it's a contrived way to write a basic for loop.

Using tone() (which uses Timer2) for the carrier signal, and Timer1 for the modulation makes use of peripherals that are part of the microcontroller and thus don't need a while loop to direct. You just set it up/start it and it goes. If you use the TimerOne library, the only significant additional code is to toggle the tone() function on and off. The function you write to do that is repeatedly called at the rate you set in TimerOne.

On an Arduino Mega (or an Uno with the ATmega328P replaced with an ATmega328PB, but then you'd have to adapt the code slightly), this can be done via the output compare modulator:
void setup() {
  // CTC, OC0A toggle on compare match, prescale 1/8
  TCCR0A = _BV(COM0A0)|_BV(WGM01);
  TCCR0B = _BV(CS01);

  // toggle every 35.5 μs at 16 MHz and 1/8 prescale
  OCR0A = 70;

  // phase and frequency correct PWM, TOP is OCR1A, OC1C clear going up and set going down, no prescale
  TCCR1A = _BV(COM1C1)|_BV(WGM10);
  TCCR1B = _BV(WGM13)|_BV(CS10);

  // period of 2 ms at 16 MHz and no prescale
  OCR1A = 16000;

  // on-time of 1 ms at 16 MHz and no prescale
  OCR1C = 8000;

  // no interrupts from the timers
  TIMSK0 = 0;
  TIMSK1 = 0;

  // only output a 1 when both timers are outputting a 1
  PORTB &= ~_BV(PORTB7);

  // halt the timers and reset the prescaler
  GTCCR |= _BV(TSM);
  GTCCR |= _BV(PSRSYNC);

  // reset both timers
  TCNT0 = 0;
  TCNT1 = 0;

  // enable output
  DDRB |= _BV(DDB7);

  // let the timers run
  GTCCR &= ~_BV(TSM);
}

void loop() {
  // Just adjust the frequencies and duty cycle as required here.
  // Everything is handled by the hardware and takes effect immediately upon writing to the register.
  // OCR1A: the desired period of the slower signal, in 8ths of microseconds. Can be up to 65535.
  // OCR1C: the desired on-time of the slower signal, in 8ths of microseconds. Can be up to 65535.
  // OCR0A: 1 less than the desired period of the faster signal, in microseconds. Can be up to 255.
  // The on-time of the faster signal is always half of the period.
  // If necessary, you can trade precision for more range for any of the above values by adjusting the prescaler.
}

With that sketch, pin 13 on the Mega will have the desired waveform. There's two big advantages to this method. First, it doesn't require any CPU resources at all (no loops or interrupts) once it's set up, so you can dedicate all of loop to reading the potentiometer and adjusting the duty cycle without worrying about glitches in the output. Second, being entirely hardware controlled means its output will be accurate and perfectly consistent (the 500 Hz component is perfect, and the 14 kHz component is approximately 14085 Hz). The one disadvantage, though, is that millis and everything else in the Arduino library that uses timers internally won't work quite right, since we're using the same hardware timers that they depend on.

@Sam43 This is now updated to let you vary the duty cycle of the 500Hz signal.

Your 14kHz carrier can be generated by the tone() function that is part of the Arduino core. You can then use the TimerOne library to toggle the tone on and off.
Here is an untested sample sketch demonstrating the usage:
#include <TimerOne.h>

const uint8_t outpin=4;

void setup() {
  // put your setup code here, to run once:
  pinMode(outpin, OUTPUT);
  Timer1.initialize(1000);  // 1000 microseconds per half-cycle
  Timer1.attachInterrupt(toggleCarrier);
}

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

}

void toggleCarrier() {
  static uint8_t isPlaying;
  if (isPlaying) {
    noTone(outpin);
    isPlaying=0;
  } else {
    tone(outpin, 14000);
    isPlaying=1;
  }
}

This code work great as written for the case of a 50% duty cycle at 500Hz. Thank you!! I have a lot more to study with timers and interrupts.
The last piece of the puzzle is that I am reading a variable pot and converting that 0-1023 reading to 1-100% duty on the 500Hz signal. So given the 2000 microsecond full cycle I would read the pot, then cycle anywhere from 20uS on/ 1800uS off, to the full 2000uS on.
I suspect I could add more code to the toggleCarrier() section, but is that the best method? set up another timer?
TIA!


text:
Programing a Bare Pic32
I recently received two types of Pic32 microcontrollers from Microchip, specifically the PIC32MX270F256B and the PIC32MX230F256B. I would like to use an Arduino Uno to setup the bootloader and to do all the programming. I found a tool to upload to the board here, but as it is from a 2012 forum here, I cannot figure out what it is exactly used for. It seems to be able to upload hex files, but in which format and to what is unclear to me. I also found Arduino bootloaders for a similar group of microcontroller here, however I cannot tell exactly which version I need, if any, or how to upload it.
Any help on how to use these tools or others would be greatly appreciated as my only experience with Arduino before this is with a simple to program to Arduino Uno.

To all who have an better idea than I do as to how to tag this, feel free to suggest changes or just edit the post.

I am unaware of any Arduino-based tools for installing a bootloader on a PIC32. If you are going to work with PIC32 you really should invest in a proper programmer.
I often use (pretty much throw-away) Chinese clones of the PICkit2 programmer. You can find them on eBay nice and cheap.  Genuine Microchip programmers are pretty expensive, so these cheap clones are quite handy...
You will also want to install the chipKIT environment into the Arduino IDE.
When it comes to the bootloader there are no official boards that use those chips. So you will need to compile your own version, which is not trivial. You will need to install MPLAB-X and the XC32 compiler and create a new profile within the project with the right settings for your board.
And then of course you will have to craft a board configuration for your custom board.
All-in-all it's quite a complex task porting a new board / chip to the chipKIT environment, and you would probably be better off directly using MPLAB-X and programming directly in C (although it's harder to get started in that environment). The PIC32 chips are considerably more complicated to work with than little AVR chips.


text:
Serial communication between an Uno and an Esplora by connecting their usb ports together
I’m trying to send a character message from an arduino uno to an esplora by connecting their usb ports together.  The esplora has a micro usb port, while the uno uses a usb B port.  To hooked them up, I connected a micro usb to usb A cable to a usb A to usb B cable using a female to female usb A connector.  I even hooked up the uno and esplora grounds together.  But the two boards just don’t seem to communicate.  Ordinarily when hooking up the esplora to my computer, the tx light flashes whenever sending the message and the message appears as expected on the serial monitor.  I’ve also tested sending character messages from the computer to the uno and they seem to be read as expected.  But when connecting the esplora to the uno without going through the computer, those tx lights on the esplora do not seem light up at all and the uno rx lights don’t flash either.
Any idea what could be the issue here?

It will not work. USB communication is master/slave. There must be a 'host' and a 'device'. Uno and Esplora are two 'devices'.
Connect the boards over TTL Serial. Wire Rx and TX pins together, TX to RX and RX to TX. And ground of course.
Serial on Esplora is the USB interface. In 'core' I see the Esplora has a second serial interface called Serial1. According to schematics, the RX and TX pin of Serial1 on Esplora are on LCD header as DC_LCD (RX) and RESET_LCD (TX). Use this Serial1 to communicate with Uno.
On Uno side you should disconnect the Uno from computer to not disturb the Serial interface with USB connection. Or use SoftwareSerial to communicate with Esplora and have debug prints to Serial Monitor.

Which pins on the esplora are the default tx & rx?

I edited the answer.

What do you mean by "In 'core' I see, it is Serial1"?  Could you explain what this means?

Arduino has core packages for different hardware architectures of MCUs and core packages have variants for boards. and boards have differrent software configurations matching the hardware

Juraj:  If i'm using serial communication a rate of 9600, does this mean that I need to use a Serial1.begin(9600) communication instead of the regular Serial.begin(9600) in the esplora code?

it is what I wrote in answer. use Serial1. Serial is USB

Thanks!  That may just solve my other question all together.

you asked about the core and didn't see the point of the sentence?

I wasn't quite sure that I understood it at first.  Thank you for explaining it.  I appreciate your help.


text:
How do I get the request params from a ESPAsyncWebServer?
I currently have the following code
server.on("/on", HTTP_POST, [](AsyncWebServerRequest *request) {
    Serial.println("ON hit.");
    String message;
    Serial.println(request->url());
    if (request->hasParam("device"))
    {
        message = request->getParam("device")->value();
    }
    else
    {
        message = " not specified";
    }
    request->send(200, "text/plain", "On, GET: " + message);
    Serial.print("Device ");
    Serial.println(message);
....

When sending in a request I get the out put, "Device not specified".
I take a look at the request-params() which gives me back a count of params that are in there and it's returning 1. I write this out:
server.on("/off", HTTP_POST, [](AsyncWebServerRequest *request) {
    Serial.println("OFF hit.");
    String message;
    int params = request->params();
    Serial.printf("%d params sent in\n", params);
    for (int i = 0; i < params; i++)
    {
        AsyncWebParameter *p = request->getParam(i);
        if (p->isFile())
        {
            Serial.printf("_FILE[%s]: %s, size: %u", p->name().c_str(), p->value().c_str(), p->size());
        }
        else if (p->isPost())
        {
            Serial.printf("_POST[%s]: %s", p->name().c_str(), p->value().c_str());
        }
        else
        {
            Serial.printf("_GET[%s]: %s", p->name().c_str(), p->value().c_str());
        }
    }
    if (request->hasParam("device"))
    {
        message = request->getParam("device")->value();
    }
    else
    {
        message = "not specified";
    }
    request->send(200, "text/plain", "Off, GET: " + message);
    Serial.print("Device ");
    Serial.println(message);

and get the output now of
1 params sent in
_POST[device]: puddle
Device not specified

If I try to do something like request->getParam(0)->value().c_str()
I get a stack dump of a bunch of hex values that I have no idea what it means: but it looks like a big fat error.

try hasParam("device", true)

usually params are for GET while POST has a separate interface

@Juraj that was it. Want to make an answer? Lol, feel pretty silly.

just in case, someone finds this snipplet:
In addition to @Juraj (correct) answer: If you want to access this param you also have to inform the function, that you want the url parameters:
message = request->getParam("device", true)->value();

For POST request the hasParam needs to know if you want to test the url parameters or x-www-form-urlencoded parameters in body of the POST request. The second parameter of the hasParam is boolean post and it has default value false. Use hasParam("device", true).


text:
How to connect 2 Arduino Unos when one has a TFT LCD display attached to it?
I have to make a school project involving an Arduino Uno with a 2.8" TFT LCD touch screen display. in my project, i have to connect it such that the display is linked to a LED push button that receive inputs and react accordingly, as well as a speaker. However, my TFT LCD display fits perfectly into my Arduino Uno meaning i have no more input slots to connect to my push buttons nor my speaker. initially i found a different TFT display that came with an Arduino Shield that made life simplier however those products were not being shipped to my country:(
i am unable to use an Arduino Mega either since the SD socker in my TFT LCD display does not support the Arduino Mega. i understand in order to have my tft lcd display and my LED buttons and speaker to work i can have 2 Arduino Unos and have them work in Master-Slave however i would still need to have a common ground for both arduinos first and connect them which i am unable to do so since there's simply no way i can fit a jumper cable in there once i place my tft lcd display on the arduino uno. Please help guys:(

Please add a link or additional information about the LCD touch screen shield you are using. There might be pins that are not used by the shield and that may be accesses through jumpers, etc.

If your TFT shield does not expose unused pins and general pins like 5V, Ground, etc, you have to expose them yourself. You can solder directly to the board, but the cleanest way would be to use another layer (for example a prototyping shield) between Arduino and TFT shield. Some of them have the pins in such a configuration, that you can simply stack the TFT shield on top of it (e.g. it exposes all the pins to further shields, that might be stacked on the prototyping shield).

this is my LCD touch screen! https://www.sgbotic.com/index.php?dispatch=products.view&product_id=2756

i am hesitant about getting a protoshield as i understand you have to soldering alrdy and then configure it? please correct me if i am wrong!!

The screw shield I mention in my answer requires no soldering. Just a small screwdriver to tighten the screws to hold your wires that go to the other board.

You can put a screw shield between the TFT shield and the Arduino to make access to the unused pins easier.  You can see an example of a board I offer at www.crossroadsfencing.com/BobuinoRev17/ We have been able to ship to any country to date.

This answer is spam, an advertisement for a product. @CrossRoads please read: https://arduino.stackexchange.com/help/promotion

How else is one to post a picture of a suggested solution?  "Don't tell - show! The best way to avoid being seen as a snake-oil salesman is to demonstrate a solution rather than simply asserting the problem can be solved"  "Always solve the asker's problem. A good answer should at minimum allow the person whose question you're answering to solve their problem."

The relevant thing from that link is: "you must disclose your affiliation in your answers.".

This is not spam. If you have a product that is a solution to the OPs problem there is nothing wrong with suggesting it (provided you disclose your affiliation). I do it often :P Spam is where you try and suggest that Viagra is the solution to the OP's question (which it may be, but that's another issue entirely...) or where you intentionally make it look like you're suggesting someone else's product.

It was spam until the answer was edited and changed to disclose CrossRoad's affiliation with the product for sale.


text:
Dimming multiple leds with pot meter
I'm working on a small project. I have 13 leds which need to be controlled individually (turn on or turn off);
Since I don't have 13 pwm pins I used a potentiometer to change the brightness.
This works fine for as long as all of the leds stay in the state they are. But once one led turns on or off it affects the brightness of all other leds.
In the picture below you can see how I did connect them.
I have the analog pins A0, A1, A2 and A3 occupied by some buttons.
Does anyone know how I can dim the leds in a way where the leds themselves don't affect the brightness?
(note: I am a programmer and not so much of an electrical engineer. Code-related answers are (usually) easy for me to understand. ones about the hardware are not.);

Maybe an extention board like this one from Adafruit, which gives you 16 individual PWM outputs

from Tour: "Don't ask about...    Any question that doesn't require knowledge about the Arduino platform to answer (try Stack Overflow for general coding questions or Electrical Engineering for general electronics questions)"

@chrisl Thanks for that suggestion! It is a bit expensive, but I'll look into it. Do you by any chance know if I can connect multiple I2C boards to an arduino?

@Juraj I guess you're right. Chrisl's suggestion does require a bit of arduino knowledge though, and because I don't have a complex circuit I personally think this forum would be a better place. I want a solution to this problem, and it doesn't have to be purely an electrical engineering solution :)
(I'll keep it in mind for next time though. Thank you for mentioning it)

Read the pot with analogRead(). Do not connect it to the LEDs at all, just 5v, Gnd and wiper to A5 (any of the analog input pins).
LEDs just go from resistor on one leg to Gnd on the other (or 5V, depends on whether anode or cathode is connected to the resistor).
Then use software PWM to control the LEDs.
For example:
byte potPin = A5;
int potValue;
byte ledPin[] = {2,3,4,5,6,7,8,9,10,11,12,13,14};
byte x;

void setup(){
  for (x=0; x<13; x=x+1){
  pinMode (ledPin[x], OUTPUT);
  }
}
void loop(){
potvalue = analogRead (potPin); // 0 to 1023 value
for (x = 0; x<13; x=x+1){
  digitalWrite (ledPin[x], HIGH);
  delayMicroseconds(potValue);
  // 0 = max brightness, 1023 (1.023mS) will be dimmest
  // manipulate potValue if 1023 is not dim enough - double it, triple it, etc.
  digitalWrite (ledPin[x], LOW);
  delayMicroseconds(potValue);
  }
 }

From here, you can play with other setups for controlling the brightness.

the question is "But once one led turns on or off it affects the brightness of all other leds.". Does this solve it?

@Juraj It works like normal pwm, but this would make it rather tricky to do while the arduino needs to do other things, especially ones where 'delay()' is used. It is the main reason why I don't think his suggestion would be suited for my project. Otherwise I think it should work.

Wouldn't be hard to change this to Blink Without Delay style of code, and getting rid of the delayMicroseconds().

but doesn't the overall brightness problem origin in wiring of the LEDs (serial v. parallel)?

The LEDs as pictured only share a common Gnd or +5. They are not wired in serial or parallel - each has its own driver (an Arduino output pin).

The other code takes up time, and the leds will be max brightness when I'm doing some light effects, but after some tweaking I managed to find a working hand-written PWM-ish way to change their brightness. It took me a couple of days before I came up with the idea how I could implement it, but it works almost perfectly now. Thank you for the suggestion!

Glad you got it working well.


text:
Multiple RGB led strips with Uno - options?
I know there's quite a few threads with similar answers already, but I hope you won't mind me asking anyways. One thread has what looks like a good solution but it's old and thought it may be better to ask fresh.
I have ten 12v rgb strips with 4 wires each, a 12v power supply and 30 mosfets. I want to control them individually with an Uno.
I'd like to make a wave effect where the strips increase and decrease in brightness at separate times. It's fine if they are all the same color during a wave. Then a wave of a different color.
(1) I'm thinking of trying the approach in this thread where AMADANON suggests using 3 pins for the color and then each strip gets its own common pin, 13 pins in my case. If I go this route, will I be able to set a color for all strips and a brightness for individual strips? This would let me make the wave effect I'd like.
(2) Alternately I'm thinking of upgrading to a Mega with 54 pins. I assume I could then control each strip individually using 3x10 = 30 pins?
(3) I've read lots of advice on chips to control the strips, but I'm a newbie and would like to keep it as simple as possible (plus delivery to my country takes 3 weeks or more, and I'd like to get started now)
Thanks for any advice!
EDIT:
(I replied to answers in comments, and I now see I should just instead edit this question. Thanks for your patience with a newbie!)
The mosfets are N-Channel MOSFET 60V 30A.
The led strips are rgb non-addressable with 4 wires, wired on both ends so they can be easily daisy-chained. But in my project the strips are snaking around some tracks and connected them in serial poses a problem. I'd prefer to wire each from only one end.
I think I'll try Gerben's and Andrew's advice about a chip and check out PCA9685 chip module as per Andrew's suggestion. Sounds inexpensive!
chrisl's suggestion for using WS2811 chips sounds easy too and maybe less wiring. In the same vein was an idea from this thread from gre_gor:
Setting 10 RGB Strips Independently from Single Arduino
... which talks about chainable STM32 rgb chips, only about 2 bucks on ebay, no mosfets, and pretty efficient.
Thanks for all the advice guys! I'm finishing the box and strips placement now and waiting for my Arduino to arrive which should be any day. This is my first venture into this domain (though I've done plenty of coding and have some experience with electronics).

which LED strips? Many can be daisy chained into longer strips controlled by the same 4 wires.

you should get addressable LEDs; not only could you hook them all up with one pin, you don't have to have the whole strip the same color, which makes for MUCH nicer effects, speaking from experience.

Sounds like you need 30 PWM pins. No Arduino has that. So either get one/multiple external chips that do that for you. Or do PWM in software. Or do multiplexing and software PWM, to require fewer pins (13), like you said in option 2. This will reduce the maximum brightness. It's also not the easiest to write. There might be a library for it.

Hi gre_gor -- I'm really interested in your idea with the STM32 rgb drivers. Will these plug into a breadboard for daisychaining, or are there connector plugs in that size, or will I need to fire up a soldering iron? Thank you.

@Abacaba No you can't put them on the breadboard. You need 4 female dupont wires to daisy chain them.

I know what you mean - LED strips with all the same colour at the same time. I've used these and I assume you can wire up the MOSFETs ok. If you don't need individually-addressable LEDs they can still produce some effects.
To control 30 PWM lines, at first I thought using the Mega would solve it, but as someone else reminded us, only 15 are full (hardware) PWM and some would have to be software PWM. This may be good enough, I don't know. More expensively, you could use two MEGAs with one acting as a slave to get 30 full PWM pins.
Another idea would be to use a PCA9685 chip module. I got a couple of these on ebay some while ago (dirt cheap, under £2/$2 ) and each board provides 16 PWM outputs, all controlled from I2C input. They aren't hard to use and have library code for Arduino. Two of these and an UNO would do it or one and a MEGA.

Thanks! Two megas is definitely a possibility (they're only $11 at kumantech.com) but that PCA9685 module sounds very promising. I'll check that out!

It sounds to me that you have this kind of tape leds.
If I'm right then your led strip has 4 pins:
1- Blue
2- Green
3- Red
4- GND
With this you can create up to (2^8)(2^8)(2^8) = 16,777,216 colors (using PWM or any other dimming technique with the Arduino), BUT ALWAYS having the same color in all the led strip. So, at least as far as I know, you can not do the effects you want with that strip.
What do you need? You need a "smart" tape, one like this
As you will see in the name says addressable, this means that, for example, you can put the green color on led No1 and the red color on led No2 and so on, and you can move those LEDs making very interesting and cute effects!
Hope you can find this fast explanation helpfull.

The OP doesn't want to control the LEDs individually, but only the ten strips he has. The effect would be visible in the difference between the stripes. But yes, if he actually had individually controllable LEDs, this would be way easier, because there would be no need to handle PWM with the Arduino

Sorry about the (perhaps) obvious question: what means "OP"? I see very often when people talk about newbies(?)... And so... yes, it's what you say about the question of the "OP" :D

OP means Original Poster. In this case I mean the user, that asked the question :D

Thanks for the answer! Yes, those are the same kind of strips I have (well, mine are shorter and more expensive!) I think you're right that addressable is probably the best route - and now that I'm thinking about it there could be some very cool effects. But I've already bought the strips and am going to try to use these first 'cause another 100 bucks into the project would be getting spendy!

I have ten 12v rgb strips with 4 wires each, a 12v power supply and 30 mosfets. I want to control them individually with an Uno.

These sound like non-smart LED strips, where you supply 12V on one pin and then there is a control line for each color. Three resistors for each 3 LEDs, with the groups of 3 wired in parallel on the strip. In which case, 3 MOSFETs per strip to sink current to Gnd sounds good, and you can likely one MOSFET control the same color on multiple strips. Thus you can use the 18 IO of an UNO, leaving D0/D1 free for serial comms with your PC.
Uno has 6 hardware PWM pins for 256 levels of brightness via analogWrite(), and you can create software PWM for the other pins as well.
Which MOSFET do you have?

Thanks for the answer! I've got N-Channel MOSFET 60V 30A, from here: https://www.sparkfun.com/products/10213.

As stated before by other users, there are multiple ways to go, but you will have to make compromises.

When using an Arduino Mega, you will have to bitbang the PWM signal (directly or by using some timer interrupts), because only 15 of it's pins can be used as native PWM pins.
In my opinion it would be the cleanest solution, to use a single driver chip for each LED strip. You can use the WS2811 chip, which is used in most LED strips with individually addressable LEDs. It outputs 3 PWM signals (for red, green and blue) and gets controlled by shifting bits through it's input. Also these chips can be daisy-chained; meaning, that only the first is hooked up to the Arduino and all other chips will be chained together (serial output to serial input). In this solution each chip would controll one of the ten LED stripes (note, that you still have to use a capable MOSFET between WS2811 and strip, since the chip cannot provide enough power for a whole strip), and they would be chained together, effectively only using 1 pin on the Arduino. You can then use librarys like the Adafruit_Neopixel to control the strips. Each of your strips then corresponds to 1 LED in the library. You can buy the WS2811 chips at various sources. When googling I found them for 5$ at Adafruit, but you may find them somewhere else for less (This was simply the first shop, where I found them. Didn't searched long). The datasheet (for example here) contains example applications, which show, how the chips have to be connected. For this solution, you would have to replace the depicted LEDs with MOSFETs, that drive the strips PWM lines.

Thanks so much! I appreciate the links. It would tricky with my project to chain the strips without drilling holes in my case (which I suppose I could). Is there a way to chain them all from one end with the other ends of strips terminating? I'll look at the examples and see if there's clues there.

I don't understand, what you mean. The driver chips have to be chained together, not the strips. And you can put the chips, where you need them. Either directly with your Arduino or where the strips are.


text:
How to flash an ATMEGA2560 using a WIZnet 5500?
I am wondering if anyone has ever flashed a ATMEGA2560 utilizing a WIZnet 5500? I have looked at this bootloader package but it only supports the 5100. I may have to do it myself but am a little worried as there doesn't seem to be any support/documentation online and I am not the best programmer. Any help would be greatly appreciated.

The latest Ariadne bootloader from 'codebender' is in his 'personal' GitHub repository. It has W5500 support. Per created his fork with better documentation and a hardware package earlier. The loathingKernel's repo still lacks good documentation.
I installed Per's Ariadne package over Board Manager and then I replaced the files in Per's package with files from loathingKernel's repo. The I flashed the bootloader to Mega without problems and the Ariadne bootloader worked for me over W5500.
I configured the upload from IDE too.

i trying to do same, but use arduino nano + wiznet5500 board. Default configuration with tftp server on 192.168.1.128 is started, but not responing for my tftp client. And I suspect 7KB of memory for the Ariadne bootloader and 26KB for the main firmware will overflow flash-memory microcontroller memory, since there is only 30KB. I'll try Mega, like you

@hwak, did you reset to bootloader. for Mega there is a better library now https://github.com/jandrassy/ArduinoOTA

thank you. It’s a pity that Mega is very large. I would like something smaller so that it fits into standard electrical sealed boxes 100х100 millimeters

@hwak, Nano Every is good, but it has no OTA solution yet. I plan to try to make one over SD card and SD bootloader. but I have too many Arduino plans and not enough free time for it.


text:
Why can I wake Arduino only once with this code?
This is my enhanced code for a daylight alarm on Arduino UNO with an added MP3-Player.
The device is supposed to sleep all the time except when I hit the play button (then it is supposed to play music) or when the RTC wakes it up, both via interrupt. When the RTC wakes it up it will start its actual daylight alarm routine.
I just implemented the sleep/power-down code and got it working so that I could wake it up and put it to sleep with pins 9 (sleep) and 2 (wake up via interrupt). There was a problem though and I had to change the code.
Apparently while trying to fix it I broke something. The current behiour upon startup is:
1. Go to sleep (correct)
2. When I bridge pin 2 and ground, it wakes up. (correct)
3. When I then bridge pin 9 and ground it goes to sleep. (correct).
4. When I bridge pin 2 and ground again it does not wake up again.
I have changed the code so that in addition to playing music the builtin LED will light up.
#include <avr/sleep.h>
/************ init mp3-player ***************/
#include <SoftwareSerial.h>

#define ARDUINO_RX 4  //should connect to TX of the Serial MP3 Player module
#define ARDUINO_TX 5  //connect to RX of the module

SoftwareSerial mp3(ARDUINO_RX, ARDUINO_TX);
static int8_t Send_buf[8] = {0}; // Buffer for Send commands.  // BETTER LOCALLY
String sbyte2hex(uint8_t b);

#define CMD_SLEEP_MODE    0X0A
#define CMD_WAKE_UP       0X0B
#define CMD_SEL_DEV       0X09
#define CMD_PLAY          0X0D
#define CMD_STOP_PLAY     0X16  // Stop playing continuously.
#define CMD_FOLDER_CYCLE  0X17
#define CMD_SET_DAC       0X1A
#define DAC_ON            0X00
#define DAC_OFF           0X01
#define DEV_TF            0X02

/**************** init the real time clock ***************/
#include <Rtc_Pcf8563.h>
Rtc_Pcf8563 rtc;

/**************** setup pins & buttons ***************/
const byte led = 11; // Pin LED is connected to
const byte sixAmPin = 6; // Pin for set-alarm-to-6am-button
const byte sevenAmPin = 7; // Pin for set-alarm-to-7am-button
const byte eightAmPin = 8; // Pin for set-alarm-to-8am-button
const byte stopPin = 9; // Pin for stop button
const byte timeResetPin = 10; // Pin for reset-clock-to-9am-button (useful e.g. after battery failure)
const byte playPin = 2; // Pin for play-music-button (and interrupt!)
const byte rtcIntPin = 3; // Pin for RTC interrupt

byte sixAmButton = 1; // State of 6am-set-button
byte sevenAmButton = 1; // State of 7am-set-button
byte eightAmButton = 1; // State of 8am-set-button
byte stopButton = 1; // State of stopButton
byte timeResetButton = 1; // State of time-set-button
byte playButton = 1; // State of play-music-button

byte brightness = 0; // LED brightness
bool wakeupMode = false;
unsigned long prevStepTime = millis();
unsigned long time;

/*************** Changeable variables here **************/
byte setHour = 6;
byte setMin = 30;
byte fadeDuration = 30; // Duration of fade in minutes (default: 30)
byte afterBurn = 30; // Keep light on after alarm for this many minutes (default: 30)
/********************************************************/

unsigned long keepLight = afterBurn * 60000UL; // Calculate time to keep LED on after fade (in ms)
int fadeStepLength = fadeDuration * 60000 / 255; // Calculate step duration for increasing LED brightness (in ms) (default: fadeDuration * 60000 / 255)

void setup() {
  /*DEBUG*/
  pinMode(LED_BUILTIN, OUTPUT);
  digitalWrite(LED_BUILTIN, HIGH);
  /*DEBUG END*/

  // Serial.begin(9600); //uncomment after testing
  mp3.begin(9600);
  delay(500);

  sendCommand(CMD_SEL_DEV, 0, DEV_TF);
  delay(500);

  // declare LED pin to be an output:
  pinMode(led, OUTPUT);

  // declare button pins as inputs:
  pinMode(stopPin, INPUT_PULLUP);
  pinMode(sixAmPin, INPUT_PULLUP);
  pinMode(sevenAmPin, INPUT_PULLUP);
  pinMode(eightAmPin, INPUT_PULLUP);
  pinMode(timeResetPin, INPUT_PULLUP);
  pinMode(playPin, INPUT_PULLUP);
  pinMode(rtcIntPin, INPUT_PULLUP);

  attachInterrupt(digitalPinToInterrupt(playPin), wakeUpPlay, FALLING);
  attachInterrupt(digitalPinToInterrupt(rtcIntPin), wakeAlarm, FALLING);
}

void loop() {
  goToSleep();
}

void wakeup() {
  // If wake-up-mode is true and brightness < 255, add +1 to brightness every 7 seconds (256 steps)
  wakeupMode = true;
  while (wakeupMode == true) {
    //update clock
    time = millis();

    // If current time is wakeup-time, increase LED brightness slowly over the course of 30 minutes
    if (brightness < 255 ) {
      // Delay brightening in steps. Do only if interval has passed.
      if (time > prevStepTime + fadeStepLength) {
        brightness ++;
        prevStepTime = millis(); // Resets counter to restart interval
      }
     }
    // Turn off light and exit wakupMode x minutes after max brightness
    else if (brightness == 255 && time > prevStepTime + keepLight) {
      brightness = 0;
      wakeupMode = false; // Exit wakeupMode loop
    }
    readButtons(); // Check for button input
    analogWrite(led, brightness); // Set LED brightness accordingly
  }
  goToSleep;
}

void readButtons() {
  // Always run this:
  // Check if alarm gets set for 6, 7 or 8am
  sixAmButton = digitalRead(sixAmPin);
  if (sixAmButton == LOW) {
    rtc.setAlarm(5, 30, 99, 99);
  }
  sevenAmButton = digitalRead(sevenAmPin);
  if (sevenAmButton == LOW) {
    rtc.setAlarm(6, 30, 99, 99);
  }
  eightAmButton = digitalRead(eightAmPin);
  if (eightAmButton == LOW) {
    rtc.setAlarm(7, 30, 99, 99);
  }

  // If stopButton is pressed: stop playing music, turn off LED, sleep mp3-player, sleep arduino
  stopButton = digitalRead(stopPin);
  if (stopButton == LOW) {
    wakeupMode = false;
    brightness = 0; // uncomment after testing
    analogWrite(led, brightness); // Set LED brightness accordingly
    sendCommand(CMD_STOP_PLAY);
    sendCommand(CMD_SLEEP_MODE);
    delay(200);
    goToSleep();
  }

  // If timeResetButton is pressed, reset RTC to 9am
  if (timeResetButton == LOW) {
    rtc.setTime(9, 0, 0);
  }

  // If Play music button is pressed, start playing music
  playButton = digitalRead(playPin);
  if (playButton == LOW) {
    playMusic();
    }
}

void playMusic(){
  digitalWrite(LED_BUILTIN, HIGH);
  sendCommand(CMD_WAKE_UP);
  delay(200);
  sendCommand(CMD_FOLDER_CYCLE, 1, 0);
  while (1){
    readButtons();
  }
}

void wakeUpPlay(){
  sleep_disable();
  detachInterrupt(digitalPinToInterrupt(playPin));
  detachInterrupt(digitalPinToInterrupt(rtcIntPin));
  playMusic();
}

void wakeAlarm(){
  sleep_disable();
  detachInterrupt(digitalPinToInterrupt(playPin));
  detachInterrupt(digitalPinToInterrupt(rtcIntPin));
  wakeup();
}

void goToSleep() {
  sleep_enable();
  attachInterrupt(digitalPinToInterrupt(playPin), wakeUpPlay, FALLING);
  attachInterrupt(digitalPinToInterrupt(rtcIntPin), wakeAlarm, FALLING);
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  digitalWrite(LED_BUILTIN, LOW);
  delay(500);
  sleep_cpu();
}

/**************************/
/** Stuff for MP3 player **/
/**************************/

/********************************************************************************/
/*Function: Send command to the MP3                                             */
/*Parameter: byte command                                                       */
/*Parameter: byte dat1 parameter for the command                                */
/*Parameter: byte dat2 parameter for the command                                */

void sendCommand(byte command){
  sendCommand(command, 0, 0);
}

void sendCommand(byte command, byte dat1, byte dat2){
  delay(20);
  Send_buf[0] = 0x7E;    //
  Send_buf[1] = 0xFF;    //
  Send_buf[2] = 0x06;    // Len
  Send_buf[3] = command; //
  Send_buf[4] = 0x01;    // 0x00 NO, 0x01 feedback
  Send_buf[5] = dat1;    // datah
  Send_buf[6] = dat2;    // datal
  Send_buf[7] = 0xEF;    //
  Serial.print("Sending: ");
  for (uint8_t i = 0; i < 8; i++)
  {
    mp3.write(Send_buf[i]) ;
    Serial.print(sbyte2hex(Send_buf[i]));
  }
  Serial.println();
}

/********************************************************************************/
/*Function: sbyte2hex. Returns a byte data in HEX format.                       */
/*Parameter:- uint8_t b. Byte to convert to HEX.                                */
/*Return: String                                                                */

String sbyte2hex(uint8_t b)
{
  String shex;

  shex = "0X";

  if (b < 16) shex += "0";
  shex += String(b, HEX);
  shex += " ";
  return shex;
}

/********************************************************************************/
/*Function: shex2int. Returns a int from an HEX string.                         */
/*Parameter: s. char *s to convert to HEX.                                      */
/*Parameter: n. char *s' length.                                                */
/*Return: int                                                                   */

int shex2int(char *s, int n){
  int r = 0;
  for (int i=0; i<n; i++){
     if(s[i]>='0' && s[i]<='9'){
      r *= 16;
      r +=s[i]-'0';
     }else if(s[i]>='A' && s[i]<='F'){
      r *= 16;
      r += (s[i] - 'A') + 10;
     }
  }
  return r;
}

I can only imagine that the problem lies in the way I send Arduino to sleep when playing music (i.e. the way I call goToSleep(); from the wakeUpPlay()-class). Waking up from sleep does work when sleep was induced from the main loop (apparently). Do you have any idea what is wrong?
(I thought about reducing my code to the bare minimum so it is less confusing for you - but then I'd probably change too much to find the bug).

reducing the code to bare minimum is the way to go for finding the bug   ...... just comment out sections of code

True - I did reduce it but couldn't find the problem. But for asking the questioned I figured it would be better to present the code in its entirety.

All your music playing code is inside a interrupt. While an interrupt is running all other interrupts are disabled. It's advised to keeps interrupt routines as short as possible.
You could have the interrupt routine set a boolean variable. Then in the loop function read that variable and call the play-music function.
volatile boolean startPlayback = false;

...

void wakeUpPlay(){
  startPlayback = true;
  sleep_disable();
  detachInterrupt(digitalPinToInterrupt(playPin));
  detachInterrupt(digitalPinToInterrupt(rtcIntPin));
}

...

void loop() {
  goToSleep();
  if( startPlayback )
  {
    startPlayback = false;
    playMusic();
  }
}

Do something similar with wakeAlarm.

Thanks. I did wonder where the program ends up once it got inside the wakeUpPlay routine - or where it would go afterwards. But I did not take the step back necessary to get a look at where it "came from" and so I just did not realize it was essentially still inside the interrupt.


text:
CH340G and CP2102 devices not recognized with Thinkpad L380
I have three different devices, none of them gets recognized on my new Thinkpad L380 running Windows 10:

Arduino Nano Clone with CH340G chip (USB2Serial)
NodeMCU (Lolin V3) with CH 340G chip (USB2Serial)
NodeMCU (ESP-WROOM-32) with CP2102 chip (USB2UART)

All three of them are recognized properly both on my desktop computer running Windows 10 (on USB 2.0 ports) as well as on my other laptop (Acer Switch Alpha 12, Win10, USB 3.0 port).
But even after hours of trying I was not able to connect those devices to my Thinkpad.
Things I've tried so far:

Of course, simply installing the Arduino IDE and try plug'n'play
Downloading and installing the CH340G driver from the official website
Disabling Secure Boot, enabling testsigning mode and reinstalling the CH340G driver
For the CP2102 device I only tried installing the driver under "normal" Windows (e.g. no testsigning enabled) since it also worked that way on my desktop computer

I have to admit that it's been a while since I set up the drivers on my other laptop and desktop computer, but I cannot remember that there was anything unusual I had to do back then.
Does anybody else know about problems regarding Thinkpad laptops? At first I thought USB 3.0 might be the problem, but the Acer laptop works just fine with the USB 3.0 port.
Update
Somehow the laptop now at least recognizes the Arduino Nano clone in the device manager and I can choose the COM port in the Arduino IDE. I can't tell what made the difference. All I did was to plug in a dongle for a wireless mouse in the USB ports to verify that they are working with "normal" devices and afterwards the Nano was recognized at least with a yellow "!" in the device manager. I then was able to uninstall the CH340 drivers and reinstall them. The device manager now displays the Nano as correctly installed.
But uploading a sketch fails. It outputs the errors:
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x0a
avrdude: ser_send(): write error: sorry no info avail
avrdude: ser_recv(): read error: Access denied

The RX LED is faintly blinking in red at the beginning of the process, then the upload seems to get stuck until the error messages are displayed.
The NodeMCU Lolin V3 with the same CH340 chip is still not recognized, though.
Serial communication (with the Serial monitor of the Arduino IDE) is now possible. I uploaded the "ASCIITable" example using my Desktop PC, connected the Arduino to the ThinkPad and could successfully read the output over the serial interface.

Using the CP2102 drivers from silabs will fail if your CP2102 is fake (as about 80% are). There are special "hacked" drivers you need (no idea where they are, I use Linux which never has any of these issues).

Since the driver works on my Desktop Computer, I assume this should not be the problem. Anyway it would still not explain the behavior of the CH340G devices.

I recently bought a cheap USB 2.o hub.
Turns out that the CH340G devices are recognised if I plug them in the hub rather than in the laptop directly. Maybe this helps somebody else who is searching for a solution, even though I can't explain why the hub is making a difference.


text:
I do not know what the board is. Can someone please help

It says that it is a pro micro, but I have searched the arduino website and i cannot find something that looks like this or is called this.

Sparkfun created a minimal version of the Arduino micro board and called it the pro micro. https://www.sparkfun.com/products/12640 Perhaps you can use it as a normal arduino micro board (with a few missing pins) or install the Sparkfun boards. With this cheap board, you don't know what kind of bootloader it has.

If the chip is an ATmega 32u4 I would guess a cheap clone of the Sparkfun Pro Micro

@Jot It plugged it in and it is reading it as an Arduino Leonardo

That is the same. The arduino micro is a minimal Leonardo and the pro micro is a minimal micro. I don't know if they all share the same bootloader. Use a picture of the pinmapping https://learn.sparkfun.com/tutorials/pro-micro--fio-v3-hookup-guide/hardware-overview-pro-micro  and you can use it as a leonardo as well. The leds can also be used (with limitations). The 3.3v/8MHz version is slower than the 16MHz Leonardo. Since "j1" is not soldered in your photo, I assume that you have a 3.3v/8MHz version.

Oops, I see a 16MHz x-tal. Maybe you should solder jumper "j1" to make it run at 5v.

I got it, just it is now not showing up on my com ports now but it was before

An Arduino compatible board don't have to look like one in Arduino web site.
There are many clones and custom boards are available.
Since it says pro micro, choose Pro micro from bard option and try uploading some code.

By default there is no Pro Micro support in the IDE. It needs to be installed.

As far as i can remember, Arduino IDE has by default support for pro micro. Even it doesn't, Leonardo has default support on arduino IDE. Which can also be choosed to program this board for testing.


text:
Why does my Esplora only send serial data when the serial monitor is on?
I've noticed that when I'm sending serial data to my computer's serial monitor, the tx light only lights up when the serial monitor is open.  When I close the monitor, it seems to stop sending data.  Is this a normal thing?
The reason I ask is because I'm really trying to send data from my esplora to an uno, and I notice that despite (1) having the grounds of both arduinos connected and (2) connecting the esplora's tx pin (reset_lcd) to the uno's rx pin (pin 0) and the esplora's rx pin (dc_lcd) to the uno's tx pin (pin 1), the tx light on the esplora and the rx pin on the uno don't light up at all.
What could be the problem?

have you looked at the schematic of the Esplora board? .... What could be the problem? .... why do you think that there is a problem? .... you also said nothing about the actual data transfer between the Esplora and the Uno

I’m sending integers as characters from the esplora to the uno and trying to read them as integers on the uno.

that says what you are doing ..... it does not say what happens .... you really need to clarify what is happening

@jsotola: nothing happens.  The tx/rx pins don’t light up at all, indicating that no data is being transfered.  I can’t figure it out because i can’t communicate from the uno to the serial monitor while wiring the tx & rx pins.

Esplora is based on a MCU with native USB. The native USB reports connected only when it really connects. You have in setup() a while loop until the USB Serial is valid. The skech waits there for connection. Comment out the while (Serial) loop.
The TX and RX LEDs of Esplora are connected to the native USB port Serial interface. They will not light for the Serial1 interface.
You should disconnect the Uno from computer to not disturb the Serial interface with USB connection. Or use SoftwareSerial to communicate with Esplora and have debug prints to Serial Monitor.


text:
Arduino Uno ADCH register stuck at 255 when read from ISR
I'm working on a project that will essentially become an oscilloscope in the long run. I am following this guide. My code is uploaded here for more reference.
In my .ino file I have called functions to set up register such that I have a timer ISR called at a frequency of 100 KHz, and an ADC clock rate of 2 MHz. The ADC is also set so that the result is left shifted so ADCH contains an 8-bit result. In a separate .h file I have an ADC ISR that looks like this:
ISR(ADC_vect)
{
  // Read 8-bit conversion result from ADCH.
  uint8_t byte0 = ADCL;
  uint8_t byte1 = ADCH;

  data_byte = byte1;
  flag = true;
}

The loop() function is the following:
void loop()
{
  if (flag == true)
  {
    //Serial.println("ISR HIT");
    Serial.println(data_byte);
    flag = false;
  }
}

So, when the ISR is called the flag is set to true, and in the loop() function I am notified with an "ISR HIT" printed on the serial monitor, this operation is successful.
However, I also have a volatile global variable in my .ino function called data_byte (also declared as an extern in the .h file) that I set byte1 to. When byte1 is printed to the serial monitor the result is:
255
255
255

Any ideas on why the value of ADCH is stuck at 255? My hardware is simply a light sensor connected to pin A0, 3.3 V, and GND.

At 9600 baud sending "ISR HIT" can be done 120 times per second. You want to send it 100000 times per second.

You never set nor print data_byte. Or maybe you do in a version of the program you didn't publish. If we cannot see the code, there is no point in trying to guess what could be wrong.

@Jot Thank you! I did not take that into consideration. Ideally I would set the baud rate to ~800,000 bps (or higher) but right now I've just set it to 250,000 because my serial monitor on my computer isn't letting me go higher.

@EdgarBonet My apologies, I had removed that bit of code for debugging purposes. The updated code is in github and I've updated the code snippets in this question.

Your program works for me: connecting AREF to 5V and A0 to 3.3V gives a stream of numbers around 187. Please, show us the complete schematic of the circuit you are using.

@EdgarBonet Thank you for your comment, I figured out what was wrong from it. I assumed my setup used the internal 5 V reference, however I realize now that I need to apply voltage to AREF (I applied voltage from the 5 V pin), and now my setup works. If you would write it as an answer I would gladly accept, thank you so much!

It would seem the problem lies here:
// Set Register to all zeros since Vref
// will be set to internal voltge and
// analog pin A0 is used.
ADMUX = 0x00;

According to the datasheet, the bits REFS[1:0] of the ADMUX register
select the voltage reference as:

00: AREF, Internal V ref turned off
01: AVCC with external capacitor at AREF pin
10: Reserved
11: Internal 1.1V Voltage Reference with external capacitor at AREF pin

Settings those bits to zero means that you are now supposed to provide
your own reference through the AREF pin. If you want to use the 5 V
supply as a reference, you should set them to 01. This is confirmed by
the block schematic. Here is the part of that schematic relative to the
reference voltage:

When REFS0 is zero, the highlighted transistor does not conduct, hence
the only way to provide a voltage reference is through the AREF pin.

Answer accepted! Thank you again for such a through and well explained answer.


text:
Modbus IP with Simply Modbus TCP
include SPI.h
include Ethernet.h
include Modbus.h
include ModbusIP.h

//Modbus Registers Offsets (0-9999)
const int SENSOR_IREG = 100;
//Used Pins
const int sensorPin = A0;

//ModbusIP object
ModbusIP mb;

long ts;

// Set Port to 502
EthernetServer server = EthernetServer(502);

void setup() {
  //Assign the modbus device ID.
  regBank.setId(1);

    byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

    byte ip[] = { 192, 168, 1, 177 };

    mb.config(mac, ip);

    // Add SENSOR_IREG register - Use addIreg() for analog Inputs
    mb.addIreg(SENSOR_IREG);

    ts = millis();

}

void loop() {

   //Call once inside loop() - all magic here
   mb.task();

   if (millis() > ts + 2000) {
       ts = millis();

       mb.Ireg(SENSOR_IREG, analogRead(sensorPin));
   }
}

I am trying to read data from the first analog pin through ModbusTCP using SimplyModbusTCP but I keep getting errors when I poll my Arduino. I am using an Arduino UNO with a Ethernet Shield W5100 and Modbus Library. I am request data from Ip address 192.168.1.177 Port:502 Slave:1 and Function Code:03. The error I get is "Error 66 occurred at TCP Read in SMT8.0.vi. LabVIEW: The network connection was closed by the peer."

did you test the Ethernet shield with some basic Ethernet library example?

Yes I did and it worked fine. I can even ping the unit through cmd.

did you set the register address 100? try 101 in client too

Tried both, with same results

Removed that and I am still getting the same result

still error 66?

input registers is function 04

II get the same thing

Looks like SimplyModbus was the problem, used Modbus poll and was able to read data.

You should not create the Ethernet server. The library creates the server and your server takes the port first.
Modbus function code to read Input registers is 04.

I removed that line and still get the same results

Tried function code 4 and got the same result

try again register 101


text:
State change detection with a colour sensor
I have added static variables to this code and instead of getting repeated notes whilst dwelling on green, I get a single note instead. This is what I wanted. However, my loop isn't allowing for a new note to be fired either when the sensor returns to a green colour. I'm afraid I'm not getting the hang of this!
  /*
  // TCS230 color recognition sensor
  // Sensor connection pins to Arduino are shown in comments

  Color Sensor      Arduino
  -----------      --------
  VCC               5V
  GND               GND
  s0                8
  s1                9
  s2                12
  s3                11
  OUT               10
  OE                GND
*/
#include <MIDI.h>

const int s0 = 8;
const int s1 = 9;
const int s2 = 12;
const int s3 = 11;
const int out = 10;

// LED pins connected to Arduino
int redLed = 5;
int greenLed = 6;
int blueLed = 7;
// Variables
int red = 0;
int green = 0;
int blue = 0;
int indeks = 0;
const int rgbr = 7;
const int rgbg = 6;
const int rgbb = 5;

MIDI_CREATE_DEFAULT_INSTANCE();

void setup()
{
  MIDI.begin();                      // Launch MIDI and listen to channel 4

  Serial.begin(9600);
  pinMode(s0, OUTPUT);
  pinMode(rgbr, OUTPUT);
  pinMode(rgbg, OUTPUT);
  pinMode(rgbb, OUTPUT);
  pinMode(s1, OUTPUT);
  pinMode(s2, OUTPUT);
  pinMode(s3, OUTPUT);
  pinMode(out, INPUT);
  pinMode(redLed, OUTPUT);
  pinMode(greenLed, OUTPUT);
  pinMode(blueLed, OUTPUT);
  digitalWrite(s0, HIGH);
  digitalWrite(s1, HIGH);
}

void loop()
{
  color();

  int tmpr = (((20 - red) - 10) * 30); //int tmpr=(((20-red)-10)*30);
  int tmpg = (((20 - green) - 10) * 30); //int tmpg=(((20-green)-10)*30);
  int tmpb = (((20 - blue) - 10) * 30); //  int tmpb=(((20-blue)-10)*30);

  if (tmpr < 0)
    tmpr = 0;

  if (tmpg < 0)
    tmpg = 0;

  if (tmpb < 0)
    tmpb = 0;

  if (tmpg > tmpb && tmpg > tmpr)
  { tmpb = 0;
    tmpr = 0;
  }
  analogWrite(rgbr, tmpr );
  analogWrite(rgbg, tmpg );
  analogWrite(rgbb, tmpb );

  static uint8_t noteOn;

  if (tmpg > 149 && tmpg < 151) {
    static uint8_t noteOn = 0;
    if (!noteOn) {
      noteOn = true;
      MIDI.sendNoteOn(79, 127, 1);    // Send a Note (pitch 79, velo 127 on channel 1)
      MIDI.sendControlChange(64, 127, 1);

    }
  }
  else {
    static uint8_t noteOn = 1;
    if (noteOn) {
      noteOn = false;
      MIDI.sendNoteOff(79, 0, 1);     // Stop the note
      MIDI.sendControlChange(64, 0, 1);

    }
  }
}

void color()
{
  digitalWrite(s2, LOW);
  digitalWrite(s3, LOW);
  //count OUT, pRed, RED

  red = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH);

  digitalWrite(s3, HIGH);
  //count OUT, pBLUE, BLUE
  blue = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH);
  digitalWrite(s2, HIGH);
  //count OUT, pGreen, GREEN
  green = pulseIn(out, digitalRead(out) == HIGH ? LOW : HIGH);

}

please include your attempts, so that we can see in which area you need help

Hello, I've replaced my code with new suggestions but still to no avail...

please format your code correctly ..... highlight all of the code text and click {} button

you are keeping track of only one note (any note)

problem is, that I don't know how to keep track of the note that I have

us an array (use boolean values, they are true/false) .... http://www.cplusplus.com/doc/tutorial/arrays/   .... when you play a note, set the corresponding array element .... when you stop the note, clear the corresponding array element

i re-read your question .... the thing that is adding to the difficulty is that you are trying to do multiple things during the development of your code ..... best thing to do is to start another sketch that is the same as this one with one major difference, there is no midi code .... replace the midi code with a subroutine that turns on an LED when the sensor detects green color and turns off the LED when the sensor no longer detects green color ............. when you have a solidly working program, then add the code for midi

That's the thing, I want the midi note or as you suggest, an LED, to light only the once whilst on green and not continually. When sensor values change and green is encountered again then the allocated note will play (once). I will strip back the code but I really thought the issue was simple, though unobtainable to me so far...

you have not defined the program's desired behavior correctly ..... you determined that the note should play when the sensor is over a green area ..... that is not what should happen ..... the note should play when the sensor enters a green area .....  those two behaviors are completely different ..... that means that you have to keep track of the background color

Because the MIDI library for Arduino does not keep track of which notes are on or off, you will have to do that yourself.
Add a static variable called noteOn that will hold a 0 or a 1, keeping track of whether you have a note turned on or not.
Then, when your loop() determines that it should turn on a note, it first checks if a note is already on. If the note is not already on (!noteOn), then send note on command, and set noteOn=true (same as noteOn=1) so that next time around, you won't send the note on command again.
void loop()
{
  static uint8_t noteOn;

  [...]

  if (tmpg > 149 && tmpg < 151) {
    if (!noteOn) {
      noteOn = true;
      MIDI.sendNoteOn(79, 127, 1);    // Send a Note (pitch 79, velo 127 on channel 1)
      MIDI.sendControlChange(64, 127, 1);
    }
  } else {
    if (noteOn) {
      noteOn = false;
      MIDI.sendNoteOff(79, 0, 1);     // Stop the note
      MIDI.sendControlChange(64, 0, 1);
    }
  }
}

Thanks jose can u c! Can you tell me what this means ( [...]) Also, what do you mean by keeping track of which notes are on or off? I have tried you code but unfortunately i still have the same problem of repeated notes...

[...] is just where I omitted some of your code that was unrelated to the relevant additions to answer the question.

I edited the answer to have a more explanation of what I mean by keeping track of which notes are on or off.

I thought I should attach my code with your additional code but i don't understand how or where I should post that!

Possibly should I edit my original post and replace it with the new code?

Yes, edit the question, add your revised attempt.

One more thing -- the logical AND operator is &&, not &.

I have changed the static variable noteOn to equal a '0' in the first if and then in the 'else if' I've changed it to a '1'. this gives me a first note played once but only once. I thought 'noteOn' was already keeping track but it isn't?


text:
Atmega32u4 issue
I made a custom ATmega32u4 board for my project. Components came from clone of Arduino Pro Micro (with bootloader and code which I uploaded) from AliExpress. I soldered everything in to my board according to my schematic but the board doesn't work. I don't have any signal from that.
https://i.stack.imgur.com/qskHc.jpg

Did you buy the atmega32u4 with bootloader? Which bootloader? How can you be sure that it has a bootloader? Even the arduino micro has a icsp header. Can you solder wires to it for a icsp header? Then you can upload a sketch with a programmer without bootloader. For example a sketch to toggle a pin or blink a led. After that you can try to use tx and rx with a extra usb-serial module to a computer. After that you can try the bootloader and try to upload a sketch.

Firstly i upload code to orginal board and everything was working. Then i soldered everything and i dont have any response from my custom board.

It's hard to tell from those pictures, but do you actually have any power going into VCC?

Now I've got into whatever EDA that is you're using I can see that no, it would appear not.  You actually have to provide power to the chip for it to successfully run...

I connect this wire and everything is working nice right now. Thanks for fast help ;)

Please don't forget to accept the answer, or post one of your own and mark it as accepted 48 hours later, as this will help other people with the same issue.

You have an error in your schematic.
You have used the net name VCC for your main power circuit. However your USB incoming power is labelled as +5V.
That means you have two separate nets - +5V with power on it, and VCC isolated from it entirely.
You need to connect those two nets together - name them both VCC or both +5V so they form a single net (easiest is to adopt VCC since you use that on other connections too).
To "fix" your current PCB you could connect a small wire from the cathode of D2 to pin 44 AVCC on the main chip which will bridge the two nets together.


text:
(ultrasonic sensor code : No such file or directory)
I'm beginning in Arduino I do not understand what the error means. Please tell me where I can find the resources to understand it and allow the code to compile.
#include <RCSwitch.h>
#include <Ultrasonic.h>

Ultrasonic ultrasonic(11,10);
RCSwitch mySwitch = RCSwitch();

int i;

void setup() {
    mySwitch.enableTransmit(4);
}

void loop() {
    i = ultrasonic.Ranging(CM);
    mySwitch.send(i, 24);
    delay(100);
}

Arduino: 1.8.7 (Windows 7), Board: "Arduino/Genuino Uno"
433mhz-lcd-water-level-transmitter:2:24: error: Ultrasonic.h: No such
  file or directory
compilation terminated.
exit status 1 Ultrasonic.h: No such file or directory
This report would have more information with "Show verbose output
  during compilation" option enabled in File -> Preferences.

Did you install the library?

I did add an ultrasonic library but have the same error

Thanks for all my problem is solved download ultrasonic code here https://www.arduinolibraries.info/libraries/ultrasonic i found another library ultrasonic solve my first problem(Ultrasonic.h: No such file or directory) but then have another error... it say(class Ultrasonic' has no member named 'Ranging').... in this time i changed some of my code and now working good my code after solve include include Ultrasonic ultrasonic(11,10); // (Trig PIN,Echo PIN) RCSwitch mySwitch = RCSwitch(); int i; void setup() { mySwitch.enableTransmit(4); } void loop() { Ultrasonic ultrasonic(11,10,3000); // (Tri

It means what it says:

Ultrasonic.h: No such file or directory

The file Ultrasonic.h can't be found.
Anything in your code that starts #include... is usually a library. These are third party pieces of software that you have to obtain and install into the relevant location (See Installing Additional Arduino Libraries).
Some libraries are bundled with the IDE, and some are available through the "library manager" in the IDE. However most aren't, and you will have to get used to finding those libraries and installing them.
The location you got your example code from will most likely link you to where to find the relevant libraries to get the code working.

This kind of error means that the Arduino IDE (assuming that is what your are using) did not find 'Ultrasonic.h' in a folder named 'libraries' within your Arduino sketch folder. (Some libraries are contained in other places within the IDE's executable, but putting your additional libraries in '.../libraries' keeps everything easy to find and maintain).
Go to File | Preferences (in Windows or Linux) or Arduino | Preferences (Mac). The top box in that dialog is the path to your sketch folder. That folder should contain one called 'libraries'.
The libraries folder should have a folder for each library, so in this case, there should be a folder named 'Ultrasonic', containing files 'Ultrasonic.h' and 'Ultrasonic.cpp'. There may be other items in there as well, perhaps an Examples folder, a 'keywords.txt' file (helps the IDE with syntax coloring), a text file with release notes, etc., but the important structure is
[path/to/your/sketch/folder]
     libraries
         Ultrasonic
              Ultrasonic.h
              Ultrasonic.cpp
         someotherlibrary
              someotherlibrary.h

etc.

the .h and .cpp of the library can be in src subfolder if 'new' library format is used

Indeed - thanks for pointing that out. The above should be taken as the minimum basic structure.

i found another library ultrasonic solve my first problem(Ultrasonic.h: No such file or directory) but then have another error... it say(class Ultrasonic' has no member named 'Ranging')....
in this time i changed some of my code and now working good
my code after solve
#include <RCSwitch.h>
#include <Ultrasonic.h>

Ultrasonic ultrasonic(11,10); // (Trig PIN,Echo PIN)
RCSwitch mySwitch = RCSwitch();

int i;

void setup() {
  mySwitch.enableTransmit(4);
}

void loop() {
Ultrasonic ultrasonic(11,10,3000); // (Trig PIN,Echo PIN, Max.TimeOut in µsec )
  mySwitch.send(3000 ,24);
  delay(100);
}


text:
Fluctuating voltage coming out of arduino uno 3.3 output pin
Problem with my arduino is when I check voltage of 3.3 volt pin using multimeter , voltage varries a lot from 1.5v upto 5v. Due to which esp8266 wifi module connected to this 3.3v pin gets very hot.
Is the arduino is faulty or can me made to produce steady 3.3 v . Kindly suggest .
Thank you.

Please post your circuit.

The ESP8266's power consumption is higher than the power regulator on the Arduino UNO board can deliver. You have to find another power source!

The Arduino cannot power an ESP8266 directly.
A genuine Arduino has the LP2985 which can provide up to 150mA (about a quarter of what you need for an ESP8266) and will go into "thermal shutdown" when it gets overloaded.
However, a Chinese (or other cheap) clone could use something even less powerful, with or without thermal protection.  In this case overloading the 3.3V pin could irreversibly damage the 3.3V regulator (which may be internal to the USB chip, killing the USB connection in the process) and thus render it unable to regulate the voltage down to 3.3V properly.
If the latter is the case then it is also possible that the higher voltage passed through by the failed regulator could have also killed the ESP8266 chip.

I am sure the voltage is stable without load. Voltage fluctuations are sign of not enough current available.
If you look into the Uno specs, you will find out that the 3.3 V pin can supply max 50 mA.
If you look into esp8266 datasheet in power section you will find out that it needs far more current than 50 mA.
Power the esp8266 from 5V pin over a voltage converter.

Actually that limit of 50mA is a lie. It used to be the case, when the 3.3V was taken from the internal regulator of the FT232 chip (that pin was actually intended to just have a capacitor on it, but Arduino decided to leach power from there too), and that was limited to 50mA. But the LP2985 3.3V regulator used on modern Uno boards can actually provide up to 150mA. Still, that's way below what the ESP8266 needs, so your answer is still correct :)

I have only Uno WiFi and it can 1A from 3.3V pin :).

Is that all? I have the chipKIT Pro MZ (one of only 10 in existence) and it can provide 3A from the 3.3V pin :P  Thanks to the TPS82130SILT (sexxxxiest regulator module ever created...!)


text:
Need help on Arduino as ISP
If I use an Arduino board to bootload a new chip, is it still possible to use the microcontroller on the board for another project, or it will only be for bootloading new chips.

There are more ways to flash a bootloader to new AVR chip. To which you refer? If you replace the chip on Uno to burn a bootloader to it with a programmer, then it is very unclear what you are asking, because the original chip is not involved in this process.
If you ask about ArduinoISP sketch, then simply it is a sketch. You upload it as any other sketch and replace it with any other sketch.


text:
Powering Arduino and LED strips from one adapter
My project has my Arduino controlling 10 led strips. I'm going with a plan by @gre_gor that is posted here: Setting 10 RGB Strips Independently from Single Arduino
...where each strip is controlled by an STM32 driver.
I'm packing all electronics into a tight space and will need to have the power adapter external with just the cable coming in.
I need power both to the arduino and directly to the stm32's.
Question: can I simply split the 12V power cable to send power to both the led strips and the arduino? Or is there something I should worry about?

Powering an Arduino and LED strips is no different to powering your TV, satellite receiver, DVD player, etc all from one socket in the wall.
Connect all the grounds (-) together, and connect all the powers (+) together.
All you need to worry about is that the total current draw of all the devices combined doesn't exceed the amount of current that the power supply can provide (oh, and that they all operate at the same voltage, of course).


text:
Change operational mode of CAN transceiver
I have two MCP2515 stand-alone CAN controllers with SPI interface, two TJA1042 CAN transceivers and two Arduino Uno boards. As you may know TJA1042 have two operational modes:

Sleep mode
Normal mode.

If I want to change the mode of operation of one transceiver from sleep mode to normal mode(wake it up), I should send a wake up pattern waves from the other transceiver which is in normal mode. for example one of the wake up patterns is: 5.5 µS low, 5.5 µS high and again 5.5 µS low. Now I don't know how to send these patterns with Arduino because MCP2515 is SPI interface.
I use this library: MCP_CAN

Transmitting this "wake signal" does not "wake" the transceiver.  What it's actually doing is the transceiver, when in "standby" mode, only allows through signals that have a dominant or recessive state that is longer than the filter time (5.5µs). Any transitions in the bus after a stable period of 5.5µs or more will get passed through.
The transceiver does not enter "normal" mode at that point. It is down to the CAN device to activate the transceiver through setting the STB pin LOW.

When pin RXD goes LOW to signal a wake-up request, a transition to Normal mode will not be triggered until STB is forced LOW.

Exactly what you send is of no consequence to the transceiver - only whether it has D and R states that are longer than 5.5µS.  It's up to the CAN device to interpret them and know if it should wake up the transceiver and place it in NORMAL mode.
And the MCP2515 also doesn't care what it receives.  When the WAKEIE bit is set it will cause the MCP2515 itself to wake from its sleep mode when anything is received - at which point it signals to the Arduino through its INT pin that it's woken up.
However your chosen library has no ability included in it to control the WAKEIE bit of MCP_CANINTF - only the TXxIF bits are supported.  So you will have to expand the library to provide that facility.
The general idea of operation is:

The transceiver lets through a "slow" signal (like transmitting 0b00110011)
The MCP2515 receives "something"
INT pin goes LOW and the Arduino reacts to it
The Arduino drives STB LOW and reception can proceed normally.

Note that it is the Arduino that will be controlling STB, not the MCP2515.

Thanks for answering me. Actually I have some testcases that I should test each of them. In each of them the R or D duration is different, So it's easy for me to use digital write and delay functions of Arduino.Maybe it's a stupid question but, Can I use GPIO of MCP2515 for it?

There are two pins that can be controlled as outputs - and they are primarily designed to be IRQ pins to indicate the receive interrupts to the MCU. If you are using a shield with the transceiver already wired, then no you can't, since you can't control the TX and RX pins as GPIO. If it's not already wired and you're wiring it yourself, then why would you? Just wire it to the Arduino and don't use the MCP2515.

Thank you for helping me.Sorry for asking a lot of questions! Yes it becomes easy if I didn't use MCP2515, But I also have problem with baud rate of transceiver. When I don't use MCP2515 to set baud rate of CAN transceiver, bus signals aren't sharp enough. I don't use a shield and my mean of using GPIO was to send pulses using RXnBF pin of MCP2515. Is it possible?@Majenko


text:
7 segment multiple display, only display 1 digit
I try to create a display so that when I press the button, the counter is increased by one. The problem is only one of them light up and it is not showing the correct output, it is showing the combination of both digit (e.g. 01 showing 0, 02 showing 8). Here is my full code.
const int a = 8;  //For displaying segment "a"
const int b = 9;  //For displaying segment "b"
const int c = 4;  //For displaying segment "c"
const int d = 5;  //For displaying segment "d"
const int e = 6;  //For displaying segment "e"
const int f = 2;  //For displaying segment "f"
const int g = 3;  //For displaying segment "g"
const int D1 = 7;
const int D2 = 13;

bool bPress = false;
const int IncbuttonPin = 10;

// Variables will change:
int buttonPushCounter = 0;   // counter for the number of button presses
int buttonPushCounterD1 = 0;
int buttonPushCounterD2 = 0;

int IncbuttonState = 0;
int lastIncbuttonState = 0;

void setup() {
  // put your setup code here, to run once:
  pinMode(a, OUTPUT);  //A
  pinMode(b, OUTPUT);  //B
  pinMode(c, OUTPUT);  //C
  pinMode(d, OUTPUT);  //D
  pinMode(e, OUTPUT);  //E
  pinMode(f, OUTPUT);  //F
  pinMode(g, OUTPUT);  //G
  pinMode(D1, OUTPUT);
  pinMode(D2, OUTPUT);

  pinMode( IncbuttonPin , INPUT_PULLUP );
  Serial.begin(9600);

}

void loop() {

   IncbuttonState = digitalRead(IncbuttonPin);

   checkIncButtonPress();

  if( bPress ){
    bPress = false;
     turnOff();
     lightDigit1(buttonPushCounterD1);
     delay(5);
     lightDigit2(buttonPushCounterD2);
     delay(5);
  }
}

void checkIncButtonPress()
{
   // compare the IncbuttonState to its previous state
  if (IncbuttonState != lastIncbuttonState) {
    // if the state has changed, increment the counter
    if (IncbuttonState == LOW) {
      // if the current state is HIGH then the button went from off to on:
      bPress = true;
      buttonPushCounter++;
      buttonPushCounterD1 = buttonPushCounter / 10;
      buttonPushCounterD2 = buttonPushCounter % 10;
      Serial.println("on");
      Serial.println(buttonPushCounterD1);
      Serial.println(buttonPushCounterD2);

    } else {
      // if the current state is LOW then the button went from on to off:
      Serial.println("off");
    }
    // Delay a little bit to avoid bouncing
    delay(50);
  }
  // save the current state as the last state, for next time through the loop
  lastIncbuttonState = IncbuttonState;

}

void lightDigit1(byte digit) {
  digitalWrite(D1, LOW);
  digitalWrite(D2, HIGH);
  displayDigit1(digit);
}

void lightDigit2(byte digit) {
  digitalWrite(D1, HIGH);
  digitalWrite(D2, LOW);
  displayDigit2(digit);
}

void displayDigit1(byte digit)
{
 //Conditions for displaying segment a
 if(digit!=1 && digit != 4)
 digitalWrite(a,HIGH);

 //Conditions for displaying segment b
 if(digit != 5 && digit != 6)
 digitalWrite(b,HIGH);

 //Conditions for displaying segment c
 if(digit !=2)
 digitalWrite(c,HIGH);

 //Conditions for displaying segment d
 if(digit != 1 && digit !=4 && digit !=7)
 digitalWrite(d,HIGH);

 //Conditions for displaying segment e
 if(digit == 2 || digit ==6 || digit == 8 || digit==0)
 digitalWrite(e,HIGH);

 //Conditions for displaying segment f
 if(digit != 1 && digit !=2 && digit!=3 && digit !=7)
 digitalWrite(f,HIGH);
 if (digit!=0 && digit!=1 && digit !=7)
 digitalWrite(g,HIGH);
}

void displayDigit2(byte digit)
{
// digitalWrite(D1, HIGH);
// digitalWrite(D2, LOW);
 //Conditions for displaying segment a
 if(digit!=1 && digit != 4)
 digitalWrite(a,HIGH);

 //Conditions for displaying segment b
 if(digit != 5 && digit != 6)
 digitalWrite(b,HIGH);

 //Conditions for displaying segment c
 if(digit !=2)
 digitalWrite(c,HIGH);

 //Conditions for displaying segment d
 if(digit != 1 && digit !=4 && digit !=7)
 digitalWrite(d,HIGH);

 //Conditions for displaying segment e
 if(digit == 2 || digit ==6 || digit == 8 || digit==0)
 digitalWrite(e,HIGH);

 //Conditions for displaying segment f
 if(digit != 1 && digit !=2 && digit!=3 && digit !=7)
 digitalWrite(f,HIGH);
 if (digit!=0 && digit!=1 && digit !=7)
 digitalWrite(g,HIGH);
}

void turnOff()
{
  digitalWrite(a,LOW);
  digitalWrite(b,LOW);
  digitalWrite(c,LOW);
  digitalWrite(d,LOW);
  digitalWrite(e,LOW);
  digitalWrite(f,LOW);
  digitalWrite(g,LOW);
}

when I remove the code
     lightDigit1(buttonPushCounterD1);
     delay(5);

It is showing the correct output, but only for 1 digit.
Anyone can help me on this? Thanks.

You aren't multiplexing your displays properly.
At the moment you are doing:

Do nothing until the button is pressed
Switch on display 1
Turn on the segments for digit 1
Wait 5ms
Switch off display 1
Switch on display 2
Turn on the segments for digit 2
Wait 5ms
Go to 1

For about 5ms you will get a brief flash on one digit, but since you don't turn off the segments you turned on for that digit they are just added to for the second digit - which you display for an extended period.
To multiplex properly you must:

Turn off segments that are no longer used for the current display (best to turn them all off)
Repeatedly display both digits all the time.

Ideally your method would be:

Turn off all segments
Turn on segments for digit 1
Turn on digit 1
Delay 5ms
Turn off digit 1
Turn off all segments
Turn on segments for digit 2
Turn on digit 2
Delay 5ms
Turn off digit 2
Go to 1 (usually the loop() handles that for you).

And separate to that you handle your button press and changing the value to display.
Also note the turning off of a digit before arranging the segments for the next digit. This prevents ghosting where you get a faint impression of the previous digit overlaid on the current digit.


text:
Assembly for loop repeating 2 times when it's only suppose to do it once
I'm programming an Arduino Nano so I belive that this question should be qualified for this SE.
I am trying to dim up an LED using a for loop in AVR assembly.
My problem is that the cycle is repeated twice before ending, while it is suppose to end after the first cycle.
A cycle is when the red_loop is repeated 256 times (to dim the led up). At that point, the value should overflow causing the variable to go back to 0. The code should stop there, but mysteriously, it does another cycle and then it stops.
Does anyone know why?
Here is my code :
.org 0x000

ldi r16, 0b111
out ddrb, r16

ldi r16, 0xff
out portb, r16

ldi r16, 0

; ff00 pin
; ff01 value
; ff02 led

ldi r16, 0b000
sts $ff00, r16

ldi r16, 0
sts $ff01, r16

red:
    ldi r16, 0b001
    sts $ff00, r16

red_loop:
    rcall pwm

    lds r16, $ff01
    inc r16
    sts $ff01, r16
    cpi r16, 0
    brne red_loop

end:
    rjmp end

pwm:
    ldi r24, 190

pwm_pre_loop:
    ldi r17, 0

pwm_loop:
    lds r16, $ff01
    cp r17, r16
    brge off

    cp r17, r16
    brlo on

pwm_loop_check:
    inc r17
    cpi r17, 0
    brne pwm_loop

    inc r24

    cpi r24, 0
    brne pwm_pre_loop

    ret

on:
    lds r16, $ff00

    sbrc r16, 0
    cbi portb, 0

    sbrc r16, 1
    cbi portb, 1

    sbrc r16, 2
    cbi portb, 2

    rjmp pwm_loop_check

off:
    lds r16, $ff00

    sbrc r16, 0
    sbi portb, 0

    sbrc r16, 1
    sbi portb, 1

    sbrc r16, 2
    sbi portb, 2

    rjmp pwm_loop_check

you did not say what cycle means, so i am assuming that it means red_loop ..... are you sure that the red_loop repeats only two times?.... i am not very familiar with avr assembly instructions, but it looks like the red_loop repeats a lot more than two times

AVR asembly is not Arduino

What kind of Arduino is that? Unless you have something like 64K of SRAM, $ff00 is going to be out of range.

I suggest re-writing this code in C and taking a look at the assembly output of the compiler as a reference. Also, it might be a good idea to feed this into a simulator. E.g. http://www.avr-asm-tutorial.net/avr_sim/index_en.html

@jsotola a cycle is when the red_loop is repeated 256 times. After that, the value will overflow which will cause the value to be 0. At that point. It should stop

@Juraj I am programming an Arduino Nano, so this question should be qualified for this site.

@EdgarBonet. surprisingly, I can write to $ff00 with no problem. Now that I think of it, it's a little weird that it's even possible...

The address will simply be "wrapping around" and higher bits being discarded.

SRAM starts at 0x100 - you should be using that as the base for your memory accesses.

To make things easier on yourself you should define your variables in a .DSEG so you don't have to worry about the addresses. (and don't forget to ensure your code is in a .CSEG...)

are you sure that red_loop runs twice? .... how are you determining that?

@jsotola red_loop actually runs 512 times (2 times 256). I only want it to run 256 times. I know it because I have a led that is connected to it and it is suppose to light up gradually once only. But instead, it lights up gradually once, then it goes to off and does it again. Then it stops.

things may not be as you think ..... maybe the LED cycles in 128 steps

The problem is that the register r17, which you use as a PWM timing
ramp, overflows twice every time you enter pwm_pre_loop:

when you increments it past 127, it overflows to −128
when you increment it past 255, it overflows to 0.

When using a counter the way you are using r17 here, you usually have
it overflow only once per cycle: either you consider it holds a signed
number which overflows from 127 to −128, or you consider it holds an
unsigned number which overflows from 255 to 0. I guess the latter is
more common. Your code is confused about that register's signedness:

The instruction brge (named “Branch if Greater or Equal (Signed)” in
the instruction set datasheet) tests the S (sign flag) bit of the
status register, which is useful for signed comparisons.
The instruction brlo (“Branch if Lower (Unsigned)”) tests the carry
flag, which is used for unsigned comparisons.

You should decide once on the signedness of the counter, and then use it
consistently. Since here unsigned makes more sense, you can just replace
brge by brsh (“Branch if Same or Higher (Unsigned)”).
Or better yet, remove the second test, which is redundant:
pwm_loop:
    lds r16, value
    cp r17, r16
    brsh off  ; if (r17 >= r16) goto off;
    rjmp on   ; else goto on;

Note by the way that you can name your RAM variables. And you can use
some of the other available registers instead of the RAM.


text:
If/Else Statements on Arduino not executing
I have a bit of code below, the problem is only the first 'if' statement will execute when called on. When I call on u, q, or any of the other if statements it will go straight to the else and not execute. Tried switching the following ifs to 'else if' but got the same result.
#include "Arduino.h"
#include <Adafruit_Sensor.h>
#include <DHT.h>
#include "DHT.h"

DHT dht1(3, DHT11);
DHT dht2(2, DHT11);

void setup()
{
  pinMode(13,OUTPUT);
  pinMode(12,OUTPUT);
  pinMode(11,OUTPUT);
  pinMode(10,OUTPUT);
  pinMode(9,OUTPUT);
  pinMode(8,OUTPUT);
  pinMode(7,OUTPUT);
  pinMode(6,OUTPUT);
  pinMode(5,OUTPUT);
  pinMode(4,OUTPUT);
  digitalWrite(13,LOW);
  digitalWrite(12,LOW);
  digitalWrite(11,LOW);
  digitalWrite(10,LOW);
  digitalWrite(9,LOW);
  digitalWrite(8,LOW);
  digitalWrite(7,LOW);
  digitalWrite(6,LOW);
  digitalWrite(5,LOW);
  digitalWrite(4,LOW);
  Serial.begin(9600);
  dht1.begin();
  dht2.begin();
}

void loop()
{
  float DHT11_t = dht1.readTemperature(true);
  float DHT21_t = dht2.readTemperature(true);

  if(Serial.read() == 'u')
  {
    Serial.println();
    Serial.print(DHT11_t,1);
    Serial.println();
    Serial.print(DHT21_t,1);
    Serial.println();
  }

  if(Serial.read() == 'c')
  {
    digitalWrite(13,LOW);
    digitalWrite(12,LOW);
    digitalWrite(11,LOW);
    digitalWrite(10,LOW);
    digitalWrite(9,LOW);
    digitalWrite(8,LOW);
    digitalWrite(7,LOW);
    digitalWrite(6,LOW);
    digitalWrite(5,LOW);
    digitalWrite(4,LOW);
    Serial.print("NDX");
    Serial.println();
    Serial.print("u");
    Serial.println();
  }

  if(Serial.read() == 'q')
  {
    digitalWrite(13,HIGH);
    digitalWrite(12,HIGH);
    digitalWrite(11,HIGH);
    digitalWrite(10,HIGH);
    digitalWrite(9,HIGH);
    Serial.print("STX");
    Serial.println();
    Serial.print("u");
    delay(2000);
    Serial.print("u");
    delay(2000);
    Serial.print("u");
    delay(2000);
    Serial.print("u");
    delay(2000);
    Serial.print("u");
    delay(2000);
    digitalWrite(13,LOW);
    digitalWrite(12,LOW);
    digitalWrite(11,LOW);
    digitalWrite(10,LOW);
    digitalWrite(9,LOW);
    Serial.print("NDX");
    Serial.println();
    Serial.print("u");
    Serial.println();
  }

  if(Serial.read() == 'w')
  {
    digitalWrite(8,HIGH);
    digitalWrite(7,HIGH);
    digitalWrite(6,HIGH);
    digitalWrite(5,HIGH);
    digitalWrite(4,HIGH);
  }

  else if(Serial.read() == 'e')
  {
    digitalWrite(13,HIGH);
    digitalWrite(12,HIGH);
    digitalWrite(11,HIGH);
    digitalWrite(10,HIGH);
    digitalWrite(9,HIGH);
  }

  if(Serial.read() == 'r')
  {
    digitalWrite(8,HIGH);
    digitalWrite(7,HIGH);
    digitalWrite(6,HIGH);
    digitalWrite(5,HIGH);
    digitalWrite(4,HIGH);
  }

  if(Serial.read() == 't')
  {
    digitalWrite(13,HIGH);
    digitalWrite(12,HIGH);
    digitalWrite(11,HIGH);
    digitalWrite(10,HIGH);
    digitalWrite(9,HIGH);
    delay(30000);
    digitalWrite(13,LOW);
    digitalWrite(12,LOW);
    digitalWrite(11,LOW);
    digitalWrite(10,LOW);
    digitalWrite(9,LOW);
    delay(750);
    digitalWrite(8,HIGH);
    digitalWrite(7,HIGH);
    digitalWrite(6,HIGH);
    digitalWrite(5,HIGH);
    digitalWrite(4,HIGH);
    delay(30000);
    digitalWrite(8,LOW);
    digitalWrite(7,LOW);
    digitalWrite(6,LOW);
    digitalWrite(5,LOW);
    digitalWrite(4,LOW);
  }

  if(Serial.read() == 'y')
  {
    digitalWrite(13,HIGH);
    digitalWrite(12,HIGH);
    digitalWrite(11,HIGH);
    digitalWrite(10,HIGH);
    digitalWrite(9,HIGH);
    delay(30000);
    digitalWrite(13,LOW);
    digitalWrite(12,LOW);
    digitalWrite(11,LOW);
    digitalWrite(10,LOW);
    digitalWrite(9,LOW);
    delay(750);
    digitalWrite(8,HIGH);
    digitalWrite(7,HIGH);
    digitalWrite(6,HIGH);
    digitalWrite(5,HIGH);
    digitalWrite(4,HIGH);
    delay(30000);
    digitalWrite(8,LOW);
    digitalWrite(7,LOW);
    digitalWrite(6,LOW);
    digitalWrite(5,LOW);
    digitalWrite(4,LOW);
  }

  else
  {
    digitalWrite(13,LOW);
    digitalWrite(12,LOW);
    digitalWrite(11,LOW);
    digitalWrite(10,LOW);
    digitalWrite(9,LOW);
    digitalWrite(8,LOW);
    digitalWrite(7,LOW);
    digitalWrite(6,LOW);
    digitalWrite(5,LOW);
    digitalWrite(4,LOW);
  }

}

We already told you that it is not working: https://arduino.stackexchange.com/questions/56646/simple-timings-in-arduino-code

Serial.read() takes the first byte out of the serial buffer. Once it's executed, this byte is gone, so the Serial.read() in the next if statement will fetch the next byte (if available). What you can do is assign the result of Serial.read() to some variable before the first if statement, and then use that variable instead of Serial.read() in the if statements.

Can you post the fix? I tried defining the var but got 'not declared in this scope'

@nuggetchris Please take a look at the example from https://www.arduino.cc/en/Serial/Read. It should work if you put your if statements after incomingByte = Serial.read(); (inside if (Serial.available() > 0) { }).

And this is also switching Serial.read() == x within the if statement with incomingByte == x?

@nuggetchris: Yes. Sorry, I forgot to mention it.

Ok, it seems to work as long as I define a data type before incomingByte. Since it's only letters, I went with char. Only problem now is, the serial.printed letters the program produces, such as in the 'u' in the if statements, it doesn't seem to recognize. It only prints the 'u' but does not execute what the 'u' is stated to execute in the first if statement

Technically could insert logic directly in place of the call but if I could streamline it as planned would be much better

@nuggetchris: I'm not sure why it doesn't recognize characters in the if statements. You are using == inside if(), right? Try the following minimal example: https://pastebin.com/raw/tFrRYceK. I've tested it, and it works ok.