text:
Self made ATMega32U4 board first programming
I'm stepping into Arduino world and decided to build a small board to implement a gamepad. Prior designing the board I tested my firmware on a Arduino Pro Micro USB so I decided to make something similar. My board use an ATMEGA32U4-AU instead  ATMEGA32U4-MU because it's simpler to solder. Connecting the board to my PC I noticed a new device named ATmega32U4 appear between Windows devices this sounds like the board is working.
Now the problem is how to program it with the correct bootloader (?) and make it a real Arduino board.
I found some spurious articles about how to make it but I have not a clean idea. Someone can help me?
I can share everything you need to focus on the board.
UPDATE ---------------------------------------------------------------------
Before installing Arduino bootloader I tried programming a sample firmware on the board trough Atmel FLIP (successfully). After that I never been able to program the board again (neither trough FLIP or other means)
I connected my board to Arduino ISP and since Windows seems unable to find the correct driver I had to install it manually, after that I tried to install the bootloader trough Install bootloader option of Arduino IDE (selecting Arduino ISP as programmer) but I had no success:
This's the log:
avrdude: Version 6.3-20190619
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

         System wide configuration file is "C:\Users\tux\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino17/etc/avrdude.conf"

         Using Port                    : usb
         Using Programmer              : arduinoisp
avrdude: usbdev_open(): Found USBtinyISP, bus:device: bus-0:\\.\libusb0-0001--0x2341-0x0049
         AVR Part                      : ATmega32U4
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PA0
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65    20     4    0 no       1024    4      0  9000  9000 0x00 0x00
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0x00 0x00
           lfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           lock           0     0     0    0 no          1    0      0  9000  9000 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : USBtiny
         Description     : Arduino ISP Programmer
avrdude: programmer operation not supported

avrdude: Using SCK period of 10 usec
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.

avrdude done.  Thank you.

Error during bootloader writing.

I can clearly see that my firmware is not running when I start the booloader process (probably because it reset the board).
From the log it seems that everything is going correctly until:
programmer operation not supported
What does it means? Is the programmer unable to program such chip? How can I fix this?
If I reset my board prior trying to burn again a new firmware over it will it work or I just have to put a brand new micro on it?
Best regards,
 Mike

Sounds like you're in DFU programming mode. There's an app for that.

You mean this: https://www.microchip.com/developmenttools/ProductDetails/flip#additional-summary ?

Looks like it. I never use it, so don't know for sure, but it certainly rings a bell.

I don't think it can be used to replace a bootloader probably I can use it to program flash with a Arduino hex.

You could use a different Arduino with the ArduinoAsISP sketch, and burn the bootloader (and fuses) using the ISP pins on the ATMega32u4

I see ... should I use the install bootloader function in ArduinoIDE?

The problem was a wrong MISO connection given by a bugged ATMega32U4 footprint.


text:
Increase PWM bit resolution
I would like to increase the PWM bit resolution of the Arduino Uno.
At this moment it is 8-bit which I consider too low.
Is this possible without losing the ability of interrupts and delays?
Koen
EDIT
This setup delivers a 16-bit resultion
void setupPWM16() {
    DDRB |= _BV(PB1) | _BV(PB2);        /* set pins as outputs */
    TCCR1A = _BV(COM1A1) | _BV(COM1B1)  /* non-inverting PWM */
        | _BV(WGM11);                   /* mode 14: fast PWM, TOP=ICR1 */
    TCCR1B = _BV(WGM13) | _BV(WGM12)
        | _BV(CS11);                    /* prescaler: clock / 8 */
    ICR1 = 0xffff;                      /* TOP counter value (freeing OCR1A*/
}
/* Comments about the setup
Changing ICR1 will effect the amount of bits of resolution.
ICR1 = 0xffff; (65535) 16-bit resolution
ICR1 = 0x7FFF; (32767) 15-bit resolution
ICR1 = 0x3FFF; (16383) 14-bit resolution etc....

Changing the prescaler will effect the frequency of the PWM signal.
Frequency[Hz}=CPU/(ICR1+1) where in this case CPU=16 MHz
16-bit PWM will be>>> (16000000/8)/(65535+1)=30.5175Hz
*/

/* 16-bit version of analogWrite(). Works only on pins 9 and 10. */
void analogWrite16(uint8_t pin, uint16_t val)
{
    switch (pin) {
        case  9: OCR1A = val; break;
        case 10: OCR1B = val; break;
    }
}

The Arduino Uno is based on an ATmega382P microcontroller. This chip has
two 8-bit timers, driving two PWM channels each, and one 16-bit timer,
driving the last two channels.
You cannot increase the resolution of the 8-bit timers. You can,
however, put the 16-bit timer in 16-bit mode, instead of the 8-bit mode
used by the Arduino core library. This will give you two 16-bit PWM
channels, with a reduced frequency of 244 Hz (maximum). You will
probably have to configure the timer yourself, and will not benefit from
the easy to use analogWrite() function. For details, see the section
on Timer 1 in in the ATmega328P
datasheet.
Update: Here is an implementation of a 16-bit analogWrite(). It
only works on pins 9 and 10, as these are the only pins connected to the
16-bit timer.
/* Configure digital pins 9 and 10 as 16-bit PWM outputs. */
void setupPWM16() {
    DDRB |= _BV(PB1) | _BV(PB2);        /* set pins as outputs */
    TCCR1A = _BV(COM1A1) | _BV(COM1B1)  /* non-inverting PWM */
        | _BV(WGM11);                   /* mode 14: fast PWM, TOP=ICR1 */
    TCCR1B = _BV(WGM13) | _BV(WGM12)
        | _BV(CS10);                    /* no prescaling */
    ICR1 = 0xffff;                      /* TOP counter value */
}

/* 16-bit version of analogWrite(). Works only on pins 9 and 10. */
void analogWrite16(uint8_t pin, uint16_t val)
{
    switch (pin) {
        case  9: OCR1A = val; break;
        case 10: OCR1B = val; break;
    }
}

You may notice that the top of the counter sequence is configured
explicitly. You can change this to a smaller value to make the PWM
faster, at the cost of decreased resolution.
And here is an example sketch illustrating its use:
void setup() {
    setupPWM16();
}

/* Test: send very slow sawtooth waves. */
void loop() {
    static uint16_t i;
    analogWrite16(9, i);
    analogWrite16(10, 0xffff - i);
    i++;
    delay(1);
}

Wow thank you very much, this is exactly what I need. I want my PWM resultion to be the same as my Sensor Resolution. If I change your code to  would it be a 13-bit resultion? If so, what would the frequency be? I will be driving a DC motor with it so 244Hz will be a bit less I guess

@KoenR: No, the prescaler has no effect on the resolution, it's purpose is to slow down the counting. Setting the prescaler to 8 will give you a PWM frequency of 30.5 Hz. If you want 13 bit resolution, set ICR1 to 0x1fff, then your frequency will be 1953 Hz (F_CPU/(TOP+1)) with a prescaler at 1.

Thank you for the explanation. Edited my question so that it covers these mistakes. So other people can see it directly. Thank you!

Am I able to use this with a CAN-bus shield which CS is on port 9? If so, is it only changing this line of code: DDRB |= _BV(PB1) | _BV(PB2);

Remove _BV(PB1) and _BV(COM1A1) from setupPWM16(), then change change analogWrite16() so that it only works on pin 10.

Fantastic answer! But would this work with an ATmega32u4 - as seen on the Arduino Micro?

@FlorinAndrei: I do not know the 32u4, but according to the summary datasheet, it should work, as it has two 16-bit timers and “Four PWM Channels with Programmable Resolution from 2 to 16 Bits”.

@Edgar Bonet This is great, however I can't seem to fully turn off an LED. I'm using ICR1 = 0x03FF and at 0 I'm seeing a tiny pulse on the scope enough to light the led. Any ideas?

@davivid: Yes, you cannot have a zero duty cycle. analogWrite16(pin, val) gives a duty cycle of (val+1)/ICR1. As a workaround, Arduino's analogWrite() does if (val == 0) digitalWrite(pin, LOW); else if (val == 255) digitalWrite(pin, HIGH);. But then you cannot get a duty cycle of 1/ICR1...

@Edgar Bonet: Thanks for explaining that - the workaround works for me.

I'm trying to figure out if PWM resolution on an Atmega168P can be increased on three pins. From what I understand, the 16-bit timer only works with two pins. Is there maybe some way to use two full cycles of the 8-bit timer, using a variable that keeps track of if it is on cycle one or two? A 50% duty cycle would be on for one 8-bit cycle and off for the second.

@Dima: Probably, but that won't be simple.

With some calibration you could sum the outputs of two PWM channels with differing weighting resistors. At the extreme you could notionally use one output to provide 8 bits of resolution and scale the other to 1/256th the level and add them so the 2nd channel covers one bit of range and you (again notionally) get 16 bits of resolution. Without immense care and adjustment all you'd get would be a mess.
However by dividing the 2nd channel by 16 or 32 you could add several extra bits of PWM resolution. Just by adding 2 PWM channels analog filtered outputs you add an extra bit (as potential range is doubled for unchanged mV/bit).
Notionally (again) for every additional divide by 2  you get an extra bit of resolution, but this can only be carried out for maybe 4 or 5 or 6 extra bits, with increasing accuracy requirements of scaling resistors and more difficult calibration and proneness to errors.
Brief example.
If one PWM is scaled down to give say 0 - 255 mV in 1 mV step, then summing two PWMs with equal amplitude would give a 0 - 510 mV range in 1 mV steps.
If one PWM is scaled down by a factor of 32 then instead of adding 255 mV to the initial PWMs range it would add only 8 mV to the top end (0.256.32 = 8 mV, but resolution would be in 0.03125 (1/32nd) mV steps.
While this could perhaps be achieved purely with resistor summing and RC filtering, use of an op amp summer would greatly improve results.
Also PWM ripple could be filtered with a simple RC filter but use of one opamp as a buffer (or even just a single transistor as an emitter follower) would give you 3 or 5 poles of low pass filtering and much better chance of achieving extra PWM resolution. I have not inspected the "phase coherence" of the PWM outputs but expect that they move in relative lockstep so you don't get the smoothing advantage of adding two uncorrelated waveforms.
More comment can be made if needed. Ask if interested.

This is clever! Seems that the Mozzi sound synthesis library uses this trick for it's so called “HIFI” mode.

That is a great us of the PWM. But wouldn't this smooth out the waveform? I am asking this since you are using a RC filter. Haven't mentioned this in my question but I'm driving a DC motor with it . Thank you for the input!

@KoenR (fwiw: I don't see anything to be ashamed of.)  I don't know what frequency response/rate of change you want in your ADC output. Or why you want N bits or how big is enough. Motors will usually not be usefully controlled by more than 8 bits - depends on how precision an application you have. Motor acts as part of a smoothing  filter due to inductance. You need to say what sort of motor and how driven. And a circuit diagram is about essential. Unless motor is tiny you have a driver. A brushed motor fed PWM must have a a catch diode to pass motor current when PWM is off. Adding two ...

... PWMs here is entiely doable but circuit details need to be known.

Beware! In some cases, smoothing out PWM with a low pass RC is not desirable. E.g., if you plug the Arduino output into the gate of a MOSFET, the MOSFET will stay cold as long as it's driven by clean PWM. But if you smooth it out, the MOSFET will start dissipating much more heat. Sometimes that's not a good thing.

source: Stack Exchange

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

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

sort: votes


text:
Please help me read this Schematic Diagram
So, i'm trying to build an Obstacle Avoiding Robot by refering this site "Robot Obstacle Avoiding Car
On the website they have provided with very poor Circuit Diagram.
Please help me read the positions of capacitors.
I have completed connection of all other components.

Help would be appreciated

FYI that 9V depicted is not suitable for driving motors, those 9V bricks are made to power a low drain device for a long time.

Then, should i use two of them in series?

you are wrong, that is a very good schematic diagram ... the only very poor thing i see is the three wiring diagrams that you presented

You need a more capable battery. Those bricks are really only capable of low-current (and/or very short lifetimes). Consider another source, supplied separately to the Arduino and to the motors. And FYI, to increase the current capability of a source, you'd need to put them in parallel, not in series.

They are not poorly described.
All capacitors need to be put from the VCC to GND directly (this will not cause a shortcut).
The left 3 are related to the motor; as it uses a lot of current, it can take the current from the capacitors instead of flowing all the way to the power supply, causing problems of a voltage reduction that can cause other components to fail (temporarily).
The middle two are for the ultrasonic sensor as it also uses some current.
0.1 uF capacitors (the one for the ultrasonic sensor) is typically used for ICs and are called bypass capacitors. These needs to be placed as close as the VCC of the IC (in this case ultrasonic as possible).
And the right two for the power supply itself to remove noise/ripple.
For all capacitors, place them close to where the power is needed (for the motor/ultrasonic) and for the power supply close to the VCC input.
EDIT
Below I added the capacitors for the motor, sorry for using MS paint, having no better option right now. I assume the two red wires from the L293D other than going to the breadboard are the 9V lines (VDD).
Also don't put the capacitors in the same pin as the L293D IC pins, but I didn't want to obfuscate the picture. This might destroy your breadboard or IC pins as there is too less space for both.

Would you please elaborate. I'm new to designing circuit. I've uploaded the Circuit i build.

I edit the capacitors for the L293D, the other capacitors should be placed likewise (as close as the VCC as possible, going directly to GND).

Thanks a lot for showing where to place motor drive capacitors, one last time just check the cirtuit.

Personally I wouldn't put capacitors from the Arduino to the breadboard, but keep them on the breadboard (even if it's not so close to the Vin/VCC of the Arduino).  But if they are close together you could.
I also see a capacitor under the switch (and two from the Arduino), while only 2 in the schematics for the Arduino power.
And you miss one capacitor towards the sensor (the schematics show two, you  only placed one). You can place them  parallel. And in principle you should have 2 capacitors PER sensor.

Maybe it's a bit overdone with capacitors, but better a stable/reliable circuit than one that might fail in some circumstances.

I'm kinda confused. If you have an access to any computer, please fell free to edit the circuit and also simulate to check it's working.
[link]https://www.tinkercad.com/things/iqq6zaNE118-self-driving-robot/editel?sharecode=5ThdoqkBRCWekluTVaZD254A_KYWiiuXoKav8GekRyY=

I have added the capacitors double for Vin and Vcc 5V for the Arduino, maybe too much, but safe. I added/adapted the capacitors near the first sensor. The motor capacitors are ok. What I did not draw is the second and third sensor capacitors (copy them exactly like for the first sensor).

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


text:
Motors working with Ultrasonic Sensor and Servo as expected?
So, I tried making an Arduino Project(Controlling Motors by Remote and Ultrasonic Sensor would activate Servo when the distance is less than 50cm).
I am trying to build a project, A remote controlled car, which will pick up objects when it encouters an object within 50cm. The remote controlled car works fine, but, to pick up objects i am trying to make it work with ultrasonic sensor, but to no avail
First when I just build the circuit for Remote Controled Motors the circuit worked fine, but after adding an Ultrasonic Sensor and Servo the circuit is not working)
This is the code without Ultrasonic and Servo:
#include <IRremote.h>      //including the remote library

#define Next_button 16615543  // code received from next button
#define Prev_button 16619623  // code received from previous button
#define left_button 16591063  // code received from left button
#define right_button 16607383 // code received from right button
#define Stop_button 16580863   // code received from stop button

int receiver_pin = 12;      //output pin of IR receiver to pin 2 of arduino
//initializing the pins for leds
int left_motor1 = 2;      //pin 6 of arduino to pin 7 of l293d
int left_motor2 = 3;      //pin 7 of arduino to pin 2 of l293d
int right_motor1  =4;      //pin 5 of arduino to pin 10 of l293d
int right_motor2 = 5;      //pin 4 of arduino to pin 15 of l293d

IRrecv receiver(receiver_pin); //Arduino will take output of IR receiver from pin 2
decode_results output;

void setup() {
  Serial.begin(9600);
  receiver.enableIRIn(); // Start to take the output from IR receiver
  //initializing all the pins where we have connected the led's as output pins
  pinMode(left_motor1, OUTPUT);
  pinMode(left_motor2, OUTPUT);
  pinMode(right_motor1, OUTPUT);
  pinMode(right_motor2, OUTPUT);
}

void loop() {
  if (receiver.decode(&output)) {
    unsigned int value = output.value;
    switch(value) {
      case Next_button:
           digitalWrite(left_motor1,LOW);
           digitalWrite(left_motor2,HIGH);
           digitalWrite(right_motor1,HIGH);
           digitalWrite(right_motor2,LOW);
           break;
      case Prev_button:
           digitalWrite(left_motor1,HIGH);
           digitalWrite(left_motor2,LOW);
           digitalWrite(right_motor1,LOW);
           digitalWrite(right_motor2,HIGH);
           break;
      case left_button:
           digitalWrite(left_motor1,LOW);
           digitalWrite(left_motor2,HIGH);
           digitalWrite(right_motor1,HIGH);
           digitalWrite(right_motor2,HIGH);
           break;
      case right_button:
           digitalWrite(left_motor1,HIGH);
           digitalWrite(left_motor2,HIGH);
           digitalWrite(right_motor1,HIGH);
           digitalWrite(right_motor2,LOW);
           break;
      case Stop_button:
           digitalWrite(left_motor1,LOW);
           digitalWrite(left_motor2,LOW);
           digitalWrite(right_motor1,LOW);
           digitalWrite(right_motor2,LOW);
           break;
    }
    receiver.resume();
  }
}

This is the code with Ultrasonic and Servo:
#include <IRremote.h>      //including the remote library
#include <Servo.h>

#define Next_button 16615543  // code received from next button
#define Prev_button 16619623  // code received from previous button
#define left_button 16591063  // code received from left button
#define right_button 16607383 // code received from right button
#define Stop_button 16580863   // code received from stop button
#define trigPin 11
#define echoPin 10

int receiver_pin = 12;      //output pin of IR receiver to pin 2 of arduino
//initializing the pins for leds
int left_motor1 = 2;      //pin 6 of arduino to pin 7 of l293d
int left_motor2 = 3;      //pin 7 of arduino to pin 2 of l293d
int right_motor1  =4;      //pin 5 of arduino to pin 10 of l293d
int right_motor2 = 5;      //pin 4 of arduino to pin 15 of l293d
Servo servo;

IRrecv receiver(receiver_pin); //Arduino will take output of IR receiver from pin 2
decode_results output;

void setup() {
  Serial.begin(9600);
  receiver.enableIRIn(); // Start to take the output from IR receiver
  //initializing all the pins where we have connected the led's as output pins
  pinMode(left_motor1, OUTPUT);
  pinMode(left_motor2, OUTPUT);
  pinMode(right_motor1, OUTPUT);
  pinMode(right_motor2, OUTPUT);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  servo.attach(8);
}

void loop() {
  if (receiver.decode(&output)) {
    unsigned int value = output.value;
    switch(value) {
      case Next_button:
           digitalWrite(left_motor1,LOW);
           digitalWrite(left_motor2,HIGH);
           digitalWrite(right_motor1,HIGH);
           digitalWrite(right_motor2,LOW);
           break;
      case Prev_button:
           digitalWrite(left_motor1,HIGH);
           digitalWrite(left_motor2,LOW);
           digitalWrite(right_motor1,LOW);
           digitalWrite(right_motor2,HIGH);
           break;
      case left_button:
           digitalWrite(left_motor1,LOW);
           digitalWrite(left_motor2,HIGH);
           digitalWrite(right_motor1,HIGH);
           digitalWrite(right_motor2,HIGH);
           break;
      case right_button:
           digitalWrite(left_motor1,HIGH);
           digitalWrite(left_motor2,HIGH);
           digitalWrite(right_motor1,HIGH);
           digitalWrite(right_motor2,LOW);
           break;
      case Stop_button:
           digitalWrite(left_motor1,LOW);
           digitalWrite(left_motor2,LOW);
           digitalWrite(right_motor1,LOW);
           digitalWrite(right_motor2,LOW);
           break;
    }
    receiver.resume();
  }
  long duration, distance;
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = (duration / 2) / 29.1;
  if (distance < 50) {
    Serial.println("the distance is less than 5");
    servo.write(90);
  }
  else {
    servo.write(0);
  }
  if (distance > 60 || distance <= 0) {
    Serial.println("The distance is more than 60");
  }
  else {
    Serial.print(distance);
    Serial.println(" cm");
  }
}

Lose the big delay. Are you really trying to use a PP3 to power it all?

Yes, 9v. Should I use more volts or this is fine.

It's not the volts, it's the current. Those batteries are insanely weak. They are not suitable for driving motors.

"is not working" not a sufficient problem description. We cannot know, how it is not working. Have you tried to debug your code by using Serial prints? As Majenko already stated, the 500ms delay at the end of loop will really break down the performance of the code (since nothing can be done during these 500ms). Look into the BlinkWithoutDelay example, that comes with the Arduino IDE, to learn, how delays can be avoided.

As you mentioned, I used a Variable Power Supply and it actually increased the RPM of the motor. But, can you elaborate how to supply more amps.

As you suggested, I've removed the delay.  I'm a newbie i don't know about the errors.

what errors are you talking about?

Actually i don't know about it, i am a rookie when talking about arduino. The motors don't get Volts, when checked using Multimeter


text:
Problem HTTP POST request with Thingspeak
I am trying to post a tweet using thingspeak but it is not getting posted. Am I missing something in my POST request or something wrong in my code?
#include <SPI.h>
#include <Ethernet.h>

const byte mac [] = {0x00, 0xC2, 0xA2, 0xE6, 0x3D, 0x57};
const int ledPin = 3;

const char webServer [] = "api.thingspeak.com";
const char webFile [] = "/apps/thingtweet/1/statuses/update";
const char apiKey [] = "xxxxxxxxxxxxxxxx";

EthernetClient myClient;

String msg = "This is my tweet";

void setup() {
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);

  Serial.println("Connecting to Network");

  if (Ethernet.begin(mac) != 1) {
    Serial.println("Connection Failed");

    while (true) {
      digitalWrite(ledPin, HIGH);
      delay(500);
      digitalWrite(ledPin, LOW);
      delay(500);
    }
  } else {
    Serial.println("Connected to Network");
  }

  // connect to thingstweet server
  Serial.print("Connecting to ");
  Serial.println(webServer);

  if (myClient.connect(webServer, 80) != 1) {
    Serial.println("Failed to connect to Thingspeak");
  } else {
    Serial.println("Sucessfully connected to ThingsSpeak");
    myClient.stop();
  }

  myClient.print("POST ");
  myClient.print(webFile);
  myClient.println(" HTTP/1.0");
  myClient.print("Host: ");
  myClient.println(webServer);
  myClient.println("Connection: close");
  myClient.println("Content-Type: application/x-www-form-urlencoded");
  myClient.print("Content-Length: ");
  myClient.println(msg.length() + 32);
  myClient.println();

  //POST some data
  myClient.print("api_key=");
  myClient.print(apiKey);
  myClient.print("&status=");
  myClient.println(msg);

}

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

}

Raw POST request from reqbin website
POST /apps/thingtweet/1/statuses/update HTTP/1.1
Host: api.thingspeak.com
Content-Type: application/x-www-form-urlencoded
Content-Length: 48

api_key=xxxxxxxxxxxxxxxxS&status=new%20test%20msg

Raw response from Reqbin
HTTP/1.1 200 OK
Date: Thu, 14 May 2020 21:24:11 GMT
Content-Type: text/plain; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Status: 200 OK
X-Frame-Options: SAMEORIGIN
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: GET, POST, PUT, OPTIONS, DELETE, PATCH
Access-Control-Allow-Headers: origin, content-type, X-Requested-With
Access-Control-Max-Age: 1800
ETag: W/"6b86b273ff34fce19d6b804eff5a3f57"
Cache-Control: max-age=0, private, must-revalidate
Set-Cookie: request_method=POST; path=/
X-Request-Id: f9afc383-63d3-4c91-8f15-4d8e4a90f87b
X-Runtime: 0.172584
X-Powered-By: Phusion Passenger 4.0.57
Server: nginx/1.9.3 + Phusion Passenger 4.0.57

1

is the arduino able to connect to the internet?

yes the arduino is connected to the network. Also it is able to connect to the Thingspeak

It's possibly because your Content-Length shouldn't be msg.length() + 32 but rather msg.length() + 34 due to the extra CRLF from myClient.println(msg);; that CRLF isn't needed though. If fixing that doesn't work, you can also try sending the POST manually with a site like this: https://reqbin.com/req/yjok4snr. To verify that your request is well-formed and that the server responds as expected.

I have tried changing the content length but it didn't make any difference. Also by sending the POST request manually I am able to tweet. So I think the request is OK. But why doesn't it work with my arduino code?

When you tested manually, how exact did you get? Did you use the exact same headers, the exact same HTTP 1.0? Speaking of which, try changing that to HTTP 1.1, no reason to use 1.0, I think. Instead of fixing the changing the content length, get rid of the extra CRLF in your POST payload; make that print() instead of println(). And use the X-THINGSPEAKAPIKEY header in your request to specify your API key. Then update your question with the current sketch, if no combo of these works.

I used the exact same header except the HTTP version as the reqbin site didn't let me choose one or atleast I don't know how to specify that (may be in the header??). I have updated the original post with the raw POST request and response. Also when I change the api_key header to X-THINGSPEAKAPIKEY I get a HTTP/1.1 400 Bad Request.

@TisteAndii but thanks for telling me about reqbin and sending the response manually. I learnt something new

@Zaffresky Sure, you're welcome. The Bad Request response seems to originate from a HTTP 1.1 server, perhaps Thingspeak has disabled HTTP 1.0 support. That's why I'd suggest you try making both requests exactly the same; that is, make your Arduino code send the exact same hard-coded string as the one from reqbin that has been proven to work. Once you have that working on Arduino, then slowly substitute stuff back in, like your Connection header and then the calculated Content-Length, etc. Good luck.


text:
problem using one function to blink different leds
I wrote a function to blink an led using millis and want to blink multiple leds with the same function but with different delay intervals. When I call this function thrice to blink 3 different leds, all the leds blink with the shortest delay. As far my understanding is, functions can be reused if you want to perform same task but why doesn't it work in this case? It works incase I rename the function before calling it again.
Is it wrong to call single function more than once to perform same task but on different pins? How would you call a function without renaming it?
const int redLed = 10;
const int yellowLed = 11;
const int greenLed = 12;

void setup() {
  pinMode(redLed, OUTPUT);
  pinMode(yellowLed, OUTPUT);
  pinMode(greenLed, OUTPUT);
}

void loop() {
blinkLed(redLed, 1000);
blinkLed(yellowLed, 4000);
blinkLed(greenLed, 8000);
}

void blinkLed(int led, unsigned long timePeriod) {
  static unsigned long oldTime = 0;
  unsigned long newTime = millis();
  static boolean ledState = LOW;

  if (newTime - oldTime >= timePeriod) {
    oldTime = newTime;
    ledState = !ledState;
  }
  digitalWrite(led, ledState);
}

Edit: I have modified the function to not have shared variables but it just blinks redLed. why doesn't it work now? Here is the code:
const int redLed = 10;
const int yellowLed = 11;
const int greenLed = 12;

void setup() {
  pinMode(redLed, OUTPUT);
  pinMode(yellowLed, OUTPUT);
  pinMode(greenLed, OUTPUT);
}

void loop() {

  blinkLed(redLed, 1000);
  blinkLed(yellowLed, 4000);
  blinkLed(greenLed, 8000);
}

void blinkLed(int led, unsigned long timePeriod) {

  switch (led) {
    case 10:
      static unsigned long oldTime1 = 0;
      unsigned long newTime1 = millis();
      static boolean redState = LOW;

      if (newTime1 - oldTime1 >= timePeriod) {
        oldTime1 = newTime1;
        redState = !redState;
      }
      digitalWrite(led, redState);
          break;

    case 11:
      static unsigned long oldTime2 = 0;
      unsigned long newTime2 = millis();
      static boolean yellowState = LOW;

      if (newTime2 - oldTime2 >= timePeriod) {
        oldTime2 = newTime2;
        yellowState = !yellowState;
      }
      digitalWrite(led, yellowState);
          break;

    case 12:
      static unsigned long oldTime3 = 0;
      unsigned long newTime3 = millis();
      static boolean greenState = LOW;

      if (newTime3 - oldTime3 >= timePeriod) {
        oldTime3 = newTime3;
        greenState = !greenState;
      }
      digitalWrite(led, greenState);
      break;
  }
}

Yes, functions can be re-used if you want to perform the same task in different places or at different times. But your problem is that you only have one set of "time" variables.
You would be better off learning to create this as a class which can not only contain the "blink" function but also the variables that define the state for a specific instance of the blinking.
For example here is a small library I wrote ages ago as a demonstration.

I thought with each function call, a new copy of variables will be created and managed independently then previous function call and previous values of variables therein. I don't know anything about classes so will look it up

No, one function = one set of variables. You could pass references to other local variables, but that gets messy. Simpler to use a class.

You want to let the LEDs blink concurrently.
Your static variables oldTime, and ledState are shared between the three LEDs.
So there is ony ONE ledState in your program but you need that state for each one.
Same applies for oldTime.
Resolve the this issue and your LEDs will blink as expected.
btw. you don't need the ledState as you can read its current state.

the led pin is defined as OUTPUT,  so wouldn't I be reading what I am writing to the pin? Also how does the pin defined as output work as input at the same time?

@Zaffresky if you are readin an output pin, you are reading, what you have written to it. But thats exactly, what you need, since you simply want to toggle the pin

To resolve the shared variables issue I modified my function but there  are other problems now. Scratching my head now about how to fix it. May be the easiest way without creating classes (need to learn it first) is just copy function with different names and calling them.

@Zaffresky that is bruteforcing your idea into code. that is far from good coding habbits. Classes are easy if done primitively. Take a look at Majenko's Blinker Code. You really Need only to track three states (one for each LED) and those states consist of at most two variables. You can use a struct with those two variables if you feel that way. Just pass it as a pointer or reference to your blinkLed function.

Just putting other peoples' suggestions together:
void blinkLed(int led, unsigned long timePeriod) {
  static unsigned long oldTime[42];
  unsigned long newTime = millis();
  boolean ledState = digitalRead(led);

  if (newTime - oldTime[led] >= timePeriod) {
    oldTime[led] = newTime;
    ledState = !ledState;
  }
  digitalWrite(led, ledState);
}

Nah, sort of. it will work but still not a nice solution. The all known magic number 42 is really not what you want to do. You'd rather create a struct or class that encapsulates: pin, timePeriod, oldTime and ledState. The function will then take only the state object as its only argument.

Other people excluding Kwasmich*

@Abel why did you chose 42 for OldTime? And are you defining oldTime as an array?

Making a the singular value oldTime into an array is the easiest way to scale the code.  Ideally 42 would be replaced by the max numbered possible digital out pin per the arduino header or simply the max of the used port +1 aka 13.  Array because sacrificing mem for simplicity over implementing class or map.


text:
2 SPI devices conflict
I want to connect a W5500 ethernet Module and an SD card module to arduino Uno using SPI (with different CS pins of course). When connected separately they work fine but when connected in the same circuit the ethernet module doesn't get a correct ip address and always gets an address 255.255.255.255. To me the ethernet module is the likely culprit as the SD card module works without problem even when the ethernet module is also connected.
Tried using Ethernet & Ethernet2 libraries but no difference. Tried manually assigning the IP address but it won't work. I have even set the CS pins HIGH in the setup before calling SD.begin & Ethernet.begin() to avoid both components "listening" at the same time but it still doesn't work. How can I fix it?
Here is the sketch I am working with. Although it doesn't use SD module but as mentioned above if SD module is connected in the circuit, ethernet module doesn't get incorrect ip address
#include <SPI.h>
#include <Ethernet2.h>

//IPAddress ip(192, 168, 1, 22);

// MAC address just has to be unique. This should work
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

EthernetServer server(80);

void setup()
{

  pinMode(8, OUTPUT); // SD module CS
  digitalWrite(8, HIGH);
  pinMode(10, OUTPUT); // Ethernet module CS
  digitalWrite(10, HIGH);
  delay(1);

  Serial.begin(9600);
  Ethernet.begin(mac);
  server.begin();
  Serial.print("Server started on: ");
  Serial.println(Ethernet.localIP());
}

void loop()
{
  // listen for incoming clients
  EthernetClient client = server.available();
  if (client)
  {
    while (client.connected())
    {
      // send a standard http response header
      client.println("HTTP/1.1 200 OK");
      client.println("Content-Type: text/html");
      client.println();

      // send the body
      client.println("");
      client.println("
Arduino Server
");
      client.print("
A0=");
      client.print(analogRead(0));
      client.println("
");
      client.print("
millis=");
      client.print(millis());
      client.println("
");
      client.println("");
      client.stop();
    }
    delay(1);
  }
}

Another sketch with reference to both SD and Ethernet Libraries
#include <SPI.h>
#include <Ethernet.h>
#include <SD.h>

byte mac[] = { 0x00, 0xC3, 0xA2, 0xE6, 0x3D, 0x57 };
byte LED = 2;
char wServer[] = "media.wizards.com";
char wFile[] = "/images/magic/tcg/resources/rules/MagicCompRules_20140601.pdf";

EthernetClient myClient;

void setup() {
  //D53 on an Arduino Mega must be an output.
  pinMode(53, OUTPUT);

  pinMode(LED, OUTPUT);

  Serial.begin(9600);
  while (!Serial);

  Serial.print("Establishing network connection... ");

  if (Ethernet.begin(mac) == 0) {
    Serial.println("FAILED!");
    while (true) {
      digitalWrite(LED, HIGH);
      delay(500);
      digitalWrite(LED, LOW);
      delay(500);
    }
  }
  else {
    Serial.println("OK!");
  }
}

void loop() {

  Serial.print("Connecting to ");
  Serial.print(wServer);
  Serial.print("... ");

  if (myClient.connect(wServer, 80) == 1) {
    Serial.println("OK!");

    myClient.print("GET ");
    myClient.print(wFile);
    myClient.println(" HTTP/1.0");
    myClient.print("Host: ");
    myClient.println(wServer);
    myClient.println();

    if (SD.begin(8)) {
      if (SD.exists("MAGIC.PDF"))
        SD.remove("MAGIC.PDF");

      Serial.print("Saving response... ");
      digitalWrite(LED, HIGH);

      File dd = SD.open("MAGIC.PDF", FILE_WRITE);

      char lc;
      while (myClient.connected()) {
        if (myClient.available()) {
          char nc = myClient.read();
          if ((lc == 10) && (nc == 13)) {
            while (myClient.available() == 0);
            myClient.read();
            break;
          }
          else
            lc = nc;
        }
      }

      while (myClient.connected()) {
        if (myClient.available() > 0) {
          dd.write(myClient.read());
        }
      }

      dd.close();
      delay(500);
      Serial.println("OK");
      digitalWrite(LED, LOW);
    }
    else
      Serial.println("No SD card detected!");

    myClient.stop();
  }
  else
    Serial.println("FAILED!");

  delay(3600000);
  asm volatile(" jmp 0");

Where did you tell the SD library  and the Ethernet library which CS they should use?

In additional to @theSealion very valid question. This article should be able to help you to troubleshoot and narrow down the cause.

ethernet2.h is deprecated.

ethernet2 by default using pin 10 as cs (https://github.com/adafruit/Ethernet2/blob/master/src/utility/w5500.h#L133), however, your code has no reference to SD card library or initialisation of SD card.

I have experimented with a few different sketches but it's not working. I have uploaded another sketch which I tried but it doesn't work.

@theSealion the ethernet library by default uses pin 10 as cspin so no need to mention it. As I mention in my original post, by keeping both SD card module and ethernet module in the circuit causes an issue. It doesn't matter if the sketch has reference to SD library or not. Since in my circuit, the sd module has pin 8 as CSpin and that I pulled high to avoid any conflict but it doesn't help.

@Zaffresky than I would recommend to start looking at the hardware. Take a voltage meter and have a look at the CS and SPI lines when the µC is in reset state and when your sketch is running. Even better would be a oscilloscope to watch the signal.

I had the same problem with my SD card module.
I don't have too much knowledge about all details, but it is related that most SD card modules (the simple ones) do not have tri-state functionality, meaning they cannot cope with multiple SPI devices on the same bus.
Sadly, the Arduino has only one SPI connection, but there are solutions:

There exist tri-state buffers which you can use  (somewhere in the CD or 74HC range). See comment of hcheung: use e.g. an 74AHC125  MISO tri-state buffer.
However, another solution is to use e.g. an SD card shield, something like https://boutique.semageek.com/en/1445-sd-storage-shield-with-rtc-clock-for-arduino.html

I think you are referring to 74AHC125 to be used a MISO tri-state buffer.

@hcheung yes, thanks ... I will add it to the answer

The problem with SD cards is that the SD card doesn't strictly adhere to the SPI protocol standards.  The CS pin doesn't cause the SD card to be isolated from the bus as it should, and there are specific operations that you perform on a SD card through the SPI bus while the CS pin is held high.

Also the order of initialization is critical. You must start the SD card before any other SPI device to ensure that every device on the bus is SPI, since the SD card defaults to SDIO mode and that can interfere with the rest of the bus.

@Majenko am I right that a tri-state buffer like 74AHC125 will fix the CS pin problem?

It certainly helps matters, yes. When the SD is isolated from the bus then no matter what it does it can't interfere with the rest of the bus.

Personally I never share the SPI bus with anything else when using an SD card (but then I use PIC32 with multiple SPI busses). If needed you can always bit-bang SPI for other devices that don't need high speed.

@Majenko good to know thanks ... haven't used an SD card for long but found the problem when I started with Arduino, to be honest, never tried the buffer (since I was just trying out lots of stuff).

@Majenko Also one reason for trying to use STM32 is they have indeed more features (like more SPIs, and especially more SRAM).

@MichelKeijzers Meh... if you like ARM, sure... Give me MIPS any day though ;)

@Majenko can you give an example of MIPS microcontrollers? (or am I missing something)

@MichelKeijzers PIC32. It's all I use unless I have to use something else due to a customer requirement.

@Majenko somehow it's not really advertised or so ... I mean I checked Arduino, found it to be too limiting for what I wanted (learning microcontrollers), and the most 'obvious' links where STM32(F1). So I don't know how good/bad PIC32 (probably good as professionals use it). But I'm a bit doubtful to move (again) to a different architecture.

Heh. PIC32 has the advantage that it gets the best hardware/software support from me ;) chipKIT is the Arduino API variant for PIC32, though it is slightly lagging behind on some of the API facilities.

@Majenko I will check into it (because I'm curious).

@MichelKeijzers Thanks for the info but I wonder if the SD card shield also uses the SPI bus? If so then how will it be different than using the SD card module?

@Majenko I don't know anything about that tristate buffer but will read more about it. Also will need to order first the 74AHC125 ic to test it

@Majenko I tried initiating the SD card prior to start the ethernet but still it fails. I guess it more of a hardware issue and the tristate buffer thing will probably fix it. What really surprises me is that even if I pull the CSpin of the SD card high throughout the sketch, the ethernet module isn't able to get the correct ip so keeping it's CS pin high has no effect at all?


text:
Multiple sensors I2C stop working suddenly
I am using multiple temperature sensors using I2C. Some of the sensors are connected via TCA9548 multiplexer. When I run the sketch it runs fine for a few minutes but then it suddenly stops working while printing the results. I have tried changing the baud rate, trying two different arduinos but it happens on both arduinos. So I wonder if it's some kind of buffer overflow (serial prints) or there is any collision happening on the I2C bus. Now the only other way I can think of is to run each sensor separately and see if I can find the problematic sensor. Or are there better ways to fix the issue?
/* 9 temperature & Humidity Sensors
    1 x BME280 #1 (0x77)[Ch 0]
    1 x BME280 #2 (0x77) [Ch 1]
    1 x BME280 #3 (0x76)
    1 x SHT21 (0x40) [Ch 7]
    1 x Si7021 (0x40) [Ch 5]
    1 x HTU21D (0x40) [Ch 6]
    1 x HDC1080 (0x40) [Ch 4]
    1 x AHT10 (0x38)
    1 x HDC2080 (0x41)

*/

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <Sodaq_SHT2x.h>
#include "SparkFunHTU21D.h"
#include <HDC2080.h>
#include "ClosedCube_HDC1080.h"
#include <AHT10.h>
#include "Adafruit_Si7021.h"

Adafruit_BME280 bme1; // I2C
Adafruit_BME280 bme2; // I2C
Adafruit_BME280 bme3; // I2C
HTU21D HTU;
HDC2080 HDC2080(0x41);
ClosedCube_HDC1080 hdc1080;
AHT10 AHT(AHT10_ADDRESS_0X38);

Adafruit_Si7021 Si7021 = Adafruit_Si7021();
bool enableHeater = false;
uint8_t loopCnt = 0;

unsigned long delayTime;

#define MPLXADR 0x70 // Address of TCA9548A I2C Multiplexer
void multiplexer (uint8_t ch) { //ch is the channel on Multiplexer
  if (ch > 7) return;

  Wire.beginTransmission(MPLXADR);
  Wire.write(1 << ch);
  Wire.endTransmission();
}

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

  while (AHT.begin() != true)
  {
    Serial.println(F("AHT10 not connected or fail to load calibration coefficient")); //(F()) save string to flash & keeps dynamic memory free
    delay(5000);
  }
  Serial.println(F("AHT10 OK"));

  HDC2080.begin();

  // Begin with a device reset
  HDC2080.reset();

  // Set up the comfort zone
  HDC2080.setHighTemp(28);         // High temperature of 28C
  HDC2080.setLowTemp(22);          // Low temperature of 22C
  HDC2080.setHighHumidity(55);     // High humidity of 55%
  HDC2080.setLowHumidity(40);      // Low humidity of 40%

  // Configure Measurements
  HDC2080.setMeasurementMode(TEMP_AND_HUMID);  // Set measurements to temperature and humidity
  HDC2080.setRate(ONE_HZ);                     // Set measurement frequency to 1 Hz
  HDC2080.setTempRes(FOURTEEN_BIT);
  HDC2080.setHumidRes(FOURTEEN_BIT);

  //begin measuring
  HDC2080.triggerMeasurement();

  Serial.println();

  Serial.println(F("BME280 test"));

  //BME280 sensor 1
  //  multiplexer(0);
  //  if (! bme1.begin(0x77, &Wire)) {
  //    Serial.println("Could not find a valid BME280 sensor, check wiring!");
  //    while (1);
  //  }

  // weather monitoring
  //  Serial.println("-- Weather Station Scenario --");
  //  Serial.println("forced mode, 1x temperature / 1x humidity / 1x pressure oversampling,");
  //  Serial.println("filter off");
  //  bme1.setSampling(Adafruit_BME280::MODE_FORCED,
  //                   Adafruit_BME280::SAMPLING_X1, // temperature
  //                   Adafruit_BME280::SAMPLING_X1, // pressure
  //                   Adafruit_BME280::SAMPLING_X1, // humidity
  //                   Adafruit_BME280::FILTER_OFF   );

  //BME280 sensor 2
  multiplexer(1);
  if (! bme2.begin(0x77, &Wire)) {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    //while (1);
  }

  // weather monitoring
//  Serial.println("-- Weather Station Scenario --");
//  Serial.println("forced mode, 1x temperature / 1x humidity / 1x pressure oversampling,");
//  Serial.println("filter off");
  bme2.setSampling(Adafruit_BME280::MODE_FORCED,
                   Adafruit_BME280::SAMPLING_X1, // temperature
                   Adafruit_BME280::SAMPLING_X1, // pressure
                   Adafruit_BME280::SAMPLING_X1, // humidity
                   Adafruit_BME280::FILTER_OFF   );

  //BME280 sensor 3
//  if (! bme3.begin(0x76, &Wire)) {
//    Serial.println("Could not find a valid BME280 sensor, check wiring!");
//    //while (1);
//  }

  // weather monitoring
//  Serial.println("-- Weather Station Scenario --");
//  Serial.println("forced mode, 1x temperature / 1x humidity / 1x pressure oversampling,");
//  Serial.println("filter off");
//  bme3.setSampling(Adafruit_BME280::MODE_FORCED,
//                   Adafruit_BME280::SAMPLING_X1, // temperature
//                   Adafruit_BME280::SAMPLING_X1, // pressure
//                   Adafruit_BME280::SAMPLING_X1, // humidity
//                   Adafruit_BME280::FILTER_OFF   );
//
//  // suggested rate is 1/60Hz (1m)
//  delayTime = 10000; // in milliseconds

  Serial.println("Initiating HTU21D");
  multiplexer(6);
  HTU.begin();

  Serial.println("HDC1080 Arduino Test");

  // Default settings:
  //  - Heater off
  //  - 14 bit Temperature and Humidity Measurement Resolutions
  multiplexer(4);
  hdc1080.begin(0x40);

  Serial.println("Si7021 test!");

  multiplexer(5);
  if (!Si7021.begin()) {
    Serial.println("Did not find Si7021 sensor!");
    //while (true);
  }

}

void loop() {

  unsigned long newTime = millis();
  static unsigned long oldTime = 0;

  if (newTime - oldTime >= 60000) {
    oldTime = newTime;

    printValuesHDC2080();

    multiplexer(4);
    printValuesHDC1080();

//    bme3.takeForcedMeasurement(); // has no effect in normal mode
//    printValuesBME3();

    multiplexer(1);
    bme2.takeForcedMeasurement(); // has no effect in normal mode
    printValuesBME2();

    multiplexer(6);
    printValuesHTU();

    multiplexer(5);
    printValueSi7021();

    printValuesAHT();

    //  multiplexer(0);
    //  bme1.takeForcedMeasurement(); // has no effect in normal mode
    //  printValuesBME1();

    multiplexer(7);
    printValuesSHT21();

    Serial.println();
    Serial.println();
  }
}

//void printValuesBME1() {
//
//  Serial.println();
//  Serial.print("BME1 Readings");
//  Serial.write(9); // printing a tab using ASCII code
//  Serial.print("Temperature = ");
//  Serial.print(bme1.readTemperature());
//  Serial.println(" *C");
//  Serial.write(9); // printing a tab using ASCII code
//  Serial.print("Humidity = ");
//  Serial.print(bme1.readHumidity());
//  Serial.println(" %");
//}

void printValuesBME2() {

  Serial.print("BME2: ");
  Serial.write(9); // printing a tab using ASCII code
  Serial.print("T = ");
  Serial.print(bme2.readTemperature());
  Serial.write(9); // printing a tab using ASCII code
  Serial.print("H = ");
  Serial.println(bme2.readHumidity());
}

void printValuesBME3() {

  Serial.print("BME3: ");
  Serial.write(9); // printing a tab using ASCII code
  Serial.print("T = ");
  Serial.print(bme3.readTemperature());
  Serial.write(9); // printing a tab using ASCII code
  Serial.print("H = ");
  Serial.println(bme3.readHumidity());
}

void printValuesSHT21() {
  Serial.print("SHT21: ");
  Serial.write(9); // printing a tab using ASCII code
  Serial.print("T = ");
  Serial.print(SHT2x.GetTemperature());
  Serial.write(9); // printing a tab using ASCII code
  Serial.print("H = ");
  Serial.println(SHT2x.GetHumidity());
}

void printValuesHTU() {
  Serial.print("HTU: ");
  Serial.write(9); // printing a tab using ASCII code
  float humd = HTU.readHumidity();
  float temp = HTU.readTemperature();

  Serial.print("T = ");
  Serial.print(temp, 2);
  Serial.write(9); // printing a tab using ASCII code
  Serial.print("H = ");
  Serial.println(humd, 2);
}

void printValuesHDC2080() {
  Serial.print("HDC2080:");
  //Serial.write(9); // printing a tab using ASCII code
  Serial.print("T = "); Serial.print(HDC2080.readTemp());
  Serial.write(9); // printing a tab using ASCII code
  Serial.print("H = "); Serial.println(HDC2080.readHumidity());
}

void printValuesHDC1080() {
  Serial.print("HDC1080:");
  // Serial.write(9); // printing a tab using ASCII code
  Serial.print("T = ");
  Serial.print(hdc1080.readTemperature());
  Serial.write(9); // printing a tab using ASCII code
  Serial.print("H = ");
  Serial.println(hdc1080.readHumidity());
}

void printValuesAHT() {
  /* DEMO - 1, every temperature or humidity call will read 6 bytes over I2C, total 12 bytes */
  Serial.print(F("AHT10: "));
  Serial.write(9); // printing a tab using ASCII code
  Serial.print(F("T = ")); Serial.print(AHT.readTemperature()); //by default "AHT10_FORCE_READ_DATA"
  Serial.write(9); // printing a tab using ASCII code
  Serial.print(F("H = ")); Serial.println(AHT.readHumidity());    //by default "AHT10_FORCE_READ_DATA"
}

void printValueSi7021() {
  Serial.print(F("Si7021: "));
  // Serial.write(9); // printing a tab using ASCII code
  Serial.print("T = ");
  Serial.print(Si7021.readTemperature(), 2);
  Serial.write(9); // printing a tab using ASCII code
  Serial.print("H = ");
  Serial.println(Si7021.readHumidity(), 2);

  //
  //  // Toggle heater enabled state every 30 seconds
  //  // An ~1.8 degC temperature increase can be noted when heater is enabled
  //  if (++loopCnt == 30) {
  //    enableHeater = !enableHeater;
  //    Si7021.heater(enableHeater);
  //    // Serial.print("Heater Enabled State: ");
  //    if (Si7021.isHeaterEnabled()) {
  //      //  Serial.println("ENABLED");
  //    } else {
  //      // Serial.println("DISABLED");
  //
  //      loopCnt = 0;
}

Code with delay:
/* 9 temperature & Humidity Sensors
    1 x BME280 #1 (0x77)[Ch 0]
    1 x BME280 #2 (0x77) [Ch 1]
    1 x BME280 #3 (0x76)
    1 x SHT21 (0x40) [Ch 7]
    1 x Si7021 (0x40) [Ch 5]
    1 x HTU21D (0x40) [Ch 6]
    1 x HDC1080 (0x40) [Ch 4]
    1 x AHT10 (0x38)
    1 x HDC2080 (0x41)

*/

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <Sodaq_SHT2x.h>
#include "SparkFunHTU21D.h"
#include <HDC2080.h>
#include "ClosedCube_HDC1080.h"
#include <AHT10.h>
#include "Adafruit_Si7021.h"

Adafruit_BME280 bme1; // I2C
Adafruit_BME280 bme2; // I2C
Adafruit_BME280 bme3; // I2C
HTU21D HTU;
HDC2080 HDC2080(0x41);
ClosedCube_HDC1080 hdc1080;
AHT10 AHT(AHT10_ADDRESS_0X38);

Adafruit_Si7021 Si7021 = Adafruit_Si7021();
bool enableHeater = false;
uint8_t loopCnt = 0;

unsigned long delayTime;

#define MPLXADR 0x70 // Address of TCA9548A I2C Multiplexer
void multiplexer (uint8_t ch) { //ch is the channel on Multiplexer
  if (ch > 7) return;

  Wire.beginTransmission(MPLXADR);
  Wire.write(1 << ch);
  Wire.endTransmission();
}

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

  while (AHT.begin() != true)
  {
    Serial.println(F("AHT10 not connected or fail to load calibration coefficient")); //(F()) save string to flash & keeps dynamic memory free
    delay(5000);
  }
  Serial.println(F("AHT10 OK"));

  HDC2080.begin();

  // Begin with a device reset
  HDC2080.reset();

  // Set up the comfort zone
  HDC2080.setHighTemp(28);         // High temperature of 28C
  HDC2080.setLowTemp(22);          // Low temperature of 22C
  HDC2080.setHighHumidity(55);     // High humidity of 55%
  HDC2080.setLowHumidity(40);      // Low humidity of 40%

  // Configure Measurements
  HDC2080.setMeasurementMode(TEMP_AND_HUMID);  // Set measurements to temperature and humidity
  HDC2080.setRate(ONE_HZ);                     // Set measurement frequency to 1 Hz
  HDC2080.setTempRes(FOURTEEN_BIT);
  HDC2080.setHumidRes(FOURTEEN_BIT);

  //begin measuring
  HDC2080.triggerMeasurement();

  Serial.println();

  Serial.println(F("BME280 test"));

  //BME280 sensor 1
  //  multiplexer(0);
  //  if (! bme1.begin(0x77, &Wire)) {
  //    Serial.println("Could not find a valid BME280 sensor, check wiring!");
  //    while (1);
  //  }

  // weather monitoring
  //  Serial.println("-- Weather Station Scenario --");
  //  Serial.println("forced mode, 1x temperature / 1x humidity / 1x pressure oversampling,");
  //  Serial.println("filter off");
  //  bme1.setSampling(Adafruit_BME280::MODE_FORCED,
  //                   Adafruit_BME280::SAMPLING_X1, // temperature
  //                   Adafruit_BME280::SAMPLING_X1, // pressure
  //                   Adafruit_BME280::SAMPLING_X1, // humidity
  //                   Adafruit_BME280::FILTER_OFF   );

  //BME280 sensor 2
  multiplexer(1);
  if (! bme2.begin(0x77, &Wire)) {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    //while (1);
  }

  // weather monitoring
  //  Serial.println("-- Weather Station Scenario --");
  //  Serial.println("forced mode, 1x temperature / 1x humidity / 1x pressure oversampling,");
  //  Serial.println("filter off");
  bme2.setSampling(Adafruit_BME280::MODE_FORCED,
                   Adafruit_BME280::SAMPLING_X1, // temperature
                   Adafruit_BME280::SAMPLING_X1, // pressure
                   Adafruit_BME280::SAMPLING_X1, // humidity
                   Adafruit_BME280::FILTER_OFF   );

  //BME280 sensor 3
  //  if (! bme3.begin(0x76, &Wire)) {
  //    Serial.println("Could not find a valid BME280 sensor, check wiring!");
  //    //while (1);
  //  }

  // weather monitoring
  //  Serial.println("-- Weather Station Scenario --");
  //  Serial.println("forced mode, 1x temperature / 1x humidity / 1x pressure oversampling,");
  //  Serial.println("filter off");
  //  bme3.setSampling(Adafruit_BME280::MODE_FORCED,
  //                   Adafruit_BME280::SAMPLING_X1, // temperature
  //                   Adafruit_BME280::SAMPLING_X1, // pressure
  //                   Adafruit_BME280::SAMPLING_X1, // humidity
  //                   Adafruit_BME280::FILTER_OFF   );
  //
  //  // suggested rate is 1/60Hz (1m)
  //  delayTime = 10000; // in milliseconds

  Serial.println("Initiating HTU21D");
  multiplexer(6);
  HTU.begin();

  Serial.println("HDC1080 Arduino Test");

  // Default settings:
  //  - Heater off
  //  - 14 bit Temperature and Humidity Measurement Resolutions
  multiplexer(4);
  hdc1080.begin(0x40);

  Serial.println("Si7021 test!");

  multiplexer(5);
  if (!Si7021.begin()) {
    Serial.println("Did not find Si7021 sensor!");
    //while (true);
  }

}

void loop() {

  unsigned long newTime = millis();
  static unsigned long oldTime = 0;

  if (newTime - oldTime >= 60000) {
    oldTime = newTime;

    printValuesHDC2080();
    delay(50);

    multiplexer(4);
    printValuesHDC1080();
    delay(50);

    //    bme3.takeForcedMeasurement(); // has no effect in normal mode
    //    printValuesBME3();

    multiplexer(1);
    bme2.takeForcedMeasurement(); // has no effect in normal mode
    printValuesBME2();
    delay(50);

    multiplexer(6);
    printValuesHTU();
    delay(50);

    multiplexer(5);
    printValueSi7021();
    delay(50);

    printValuesAHT();
    delay(50);

    //  multiplexer(0);
    //  bme1.takeForcedMeasurement(); // has no effect in normal mode
    //  printValuesBME1();

    multiplexer(7);
    printValuesSHT21();
    delay(50);

    Serial.println();
    Serial.println();
  }
}

//void printValuesBME1() {
//
//  Serial.println();
//  Serial.print("BME1 Readings");
//  Serial.write(9); // printing a tab using ASCII code
//  Serial.print("Temperature = ");
//  Serial.print(bme1.readTemperature());
//  Serial.println(" *C");
//  Serial.write(9); // printing a tab using ASCII code
//  Serial.print("Humidity = ");
//  Serial.print(bme1.readHumidity());
//  Serial.println(" %");
//}

void printValuesBME2() {

  Serial.print("BME2: ");
  Serial.write(9); // printing a tab using ASCII code
  Serial.print("T = ");
  Serial.print(bme2.readTemperature());
  Serial.write(9); // printing a tab using ASCII code
  Serial.print("H = ");
  Serial.println(bme2.readHumidity());
}

void printValuesBME3() {

  Serial.print("BME3: ");
  Serial.write(9); // printing a tab using ASCII code
  Serial.print("T = ");
  Serial.print(bme3.readTemperature());
  Serial.write(9); // printing a tab using ASCII code
  Serial.print("H = ");
  Serial.println(bme3.readHumidity());
}

void printValuesSHT21() {
  Serial.print("SHT21: ");
  Serial.write(9); // printing a tab using ASCII code
  Serial.print("T = ");
  Serial.print(SHT2x.GetTemperature());
  Serial.write(9); // printing a tab using ASCII code
  Serial.print("H = ");
  Serial.println(SHT2x.GetHumidity());
}

void printValuesHTU() {
  Serial.print("HTU: ");
  Serial.write(9); // printing a tab using ASCII code
  float humd = HTU.readHumidity();
  float temp = HTU.readTemperature();

  Serial.print("T = ");
  Serial.print(temp, 2);
  Serial.write(9); // printing a tab using ASCII code
  Serial.print("H = ");
  Serial.println(humd, 2);
}

void printValuesHDC2080() {
  Serial.print("HDC2080:");
  //Serial.write(9); // printing a tab using ASCII code
  Serial.print("T = "); Serial.print(HDC2080.readTemp());
  Serial.write(9); // printing a tab using ASCII code
  Serial.print("H = "); Serial.println(HDC2080.readHumidity());
}

void printValuesHDC1080() {
  Serial.print("HDC1080:");
  // Serial.write(9); // printing a tab using ASCII code
  Serial.print("T = ");
  Serial.print(hdc1080.readTemperature());
  Serial.write(9); // printing a tab using ASCII code
  Serial.print("H = ");
  Serial.println(hdc1080.readHumidity());
}

void printValuesAHT() {
  /* DEMO - 1, every temperature or humidity call will read 6 bytes over I2C, total 12 bytes */
  Serial.print(F("AHT10: "));
  Serial.write(9); // printing a tab using ASCII code
  Serial.print(F("T = ")); Serial.print(AHT.readTemperature()); //by default "AHT10_FORCE_READ_DATA"
  Serial.write(9); // printing a tab using ASCII code
  Serial.print(F("H = ")); Serial.println(AHT.readHumidity());    //by default "AHT10_FORCE_READ_DATA"
}

void printValueSi7021() {
  Serial.print(F("Si7021: "));
  // Serial.write(9); // printing a tab using ASCII code
  Serial.print("T = ");
  Serial.print(Si7021.readTemperature(), 2);
  Serial.write(9); // printing a tab using ASCII code
  Serial.print("H = ");
  Serial.println(Si7021.readHumidity(), 2);

  //
  //  // Toggle heater enabled state every 30 seconds
  //  // An ~1.8 degC temperature increase can be noted when heater is enabled
  //  if (++loopCnt == 30) {
  //    enableHeater = !enableHeater;
  //    Si7021.heater(enableHeater);
  //    // Serial.print("Heater Enabled State: ");
  //    if (Si7021.isHeaterEnabled()) {
  //      //  Serial.println("ENABLED");
  //    } else {
  //      // Serial.println("DISABLED");
  //
  //      loopCnt = 0;
}

Can you say, where exactly it stops working? Also please check the levels on the I2C lines. If the I2C interface is stuck, at least one of the lines will be at constant LOW.

It's mostly random. The last two times it was after printing all the sensor values and in the middle of printing the value for HTU21D sensor.

@chrisl How can I check the levels on the I2C lines? Do you mean checking it with a voltmeter?

Yes, I mean with a voltmeter. If one of the lines is constant low (0V) the I2C bus is stuck for some reason. In that case try to introduce small delays of a few ms between the readings of different sensors. Trying to read too fast might cause the bus to get stuck

The CLK line was stuck at 3.4V. After resetting the sketch (working normally) the CLK line alternates between 3.4V & 2.1V

I eventually want to use ESP8266 so wouldn't adding a delay() interfere with other internal timers on it? I don't remember exactly which ones but I read somewhere that using delay() on ESP8266 might cause it to reset

I tried adding a 50 millisecond delay after reading and printing each sensor value but now it gets stuck even more rapidly. However, it now always gets stuck at reading Si7021 sensor. I have uploaded the updated code as well

Are you relying solely on the internal pullup resistors of the Arduino for the SPI bus? Or are there discrete pullups on your bus or within some of the sensor modules you're using?

For the sensors connected to the multiplexer I have used additional pull up resistors while those connected directly to the arduino bus don't have any pull up resistors


text:
OLED display on I2C causes esp8266 to reset

I have connected two temp sensors and an OLED display to a NodeMCU using I2C. When the program reaches the instruction to print the measurements on the display the program crashes and NodeMCU resets itself. In the serial monitor I see "rst cause 2". I did search about this online but couldn't find a similar issue involving an OLED. I wonder what is causing this reset and how to fix it?
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <Sodaq_SHT2x.h>
#include <Adafruit_SSD1306.h>

//defining OLED dimensions
#define WIDTH 128
#define HEIGHT 32
#define OLED_RESET -1

Adafruit_SSD1306 display(OLED_RESET);

Adafruit_BME280 bme1; // I2C

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

  Wire.begin();
  display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initiate OLED

  Serial.println(F("BME280 test"));

  //BME280 sensor 1
  if (! bme1.begin(0x77, &Wire)) {
    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    while (1);
  }

  //  weather monitoring
//  Serial.println("-- Weather Station Scenario --");
//  Serial.println("forced mode, 1x temperature / 1x humidity / 1x pressure oversampling,");
//  Serial.println("filter off");
  bme1.setSampling(Adafruit_BME280::MODE_FORCED,
                   Adafruit_BME280::SAMPLING_X1, // temperature
                   Adafruit_BME280::SAMPLING_X1, // pressure
                   Adafruit_BME280::SAMPLING_X1, // humidity
                   Adafruit_BME280::FILTER_OFF   );
}

void loop() {
  unsigned long newTime = millis();
  static unsigned long oldTime = 0;

  if (newTime - oldTime >= 10000) {
    oldTime = newTime;

    float temp1 = 0.0;
    float humid1 = 0.0;
    float temp2 = 0.0;
    float humid2 = 0.0;

    takeReadingsBME(temp1, humid1);
    printValuesBME(temp1, humid1);

    takeReadingsSHT(temp2, humid2);
    printValuesSHT(temp2, humid2);
    displayResults(temp1, temp2, humid1, humid2);
  }
}

void printValuesBME(float temp, float humid) {

  Serial.println();
  Serial.print("BME: ");
  Serial.write(9);
  Serial.print("T = ");
  Serial.print(temp);
  Serial.write(9);
  Serial.print("H = ");
  Serial.println(humid);
}

void printValuesSHT(float temp2, float humid2) {
  Serial.print("SHT21: ");
  Serial.write(9);
  Serial.print("T = ");
  Serial.print(temp2);
  Serial.write(9);
  Serial.print("H = ");
  Serial.println(humid2);
}

void displayResults(float temp1, float temp2, float humid1, float humid2) {
  display.clearDisplay();
  display.setTextColor(WHITE);
  display.setTextSize(1);
  display.setCursor(0, 0);
  display.print("Sensor Data");
  display.println();
  display.print("BME ");
  display.print("T = ");
  display.print(temp1,1);
  display.print(" H = ");
  display.println(humid1,1);
  //display.setCursor(0, 0);
  //  display.print("ST: ");
  //  display.print("T = ");
  //  display.print(SHT2x.GetTemperature(), 1);
  //  display.print(" H1 = ");
  //  display.println(SHT2x.GetHumidity(), 1);
  display.display();
}

void takeReadingsBME(float &temp1, float &humid1) {

  bme1.takeForcedMeasurement();
  temp1 = bme1.readTemperature();
  humid1 = bme1.readHumidity();
}

void takeReadingsSHT(float &temp2, float &humid2) {

  temp2 = SHT2x.GetTemperature();
  humid2 = SHT2x.GetHumidity();
}

Sounds like power problems.

I am powering the components and the NodeMCU via external power supply. It should not be an issue normally

Can you provide a diagram detailing how it is all wired up? Including the power supply?

Reset cause 2 is a reset triggered by the reset button, JFYI (https://docs.espressif.com/projects/esp-idf/en/latest/esp32/api-reference/system/system.html#_CPPv418esp_reset_reason_t)

@Majenko I have added the circuit diagram. I could not find exact power adapter component so I have used a generic 9V power supply. In reality I have a breadboard power supply that converts 9V DC to 3.3V.

@SimSon yes I also found that but the OLED doesn't have a reset button and I am not at all pushing the reset button on ESP8266

Add a large capacitor (10uF or greater) across the 3.3V and GND pins of the ESP8266 right by the module.


text:
How to add this old BASIC code snippet to work in Arduino C++ for FastLED?
I've been trying to implement this old code that randomly transitions to RGB color into my Arduino board that uses FastLED.
Static Col1, Col2, Col3 As Integer
Static C1, C2, C3 As Integer
If (Col1 = 0 Or Col1 = 250) And (Col2 = 0 Or Col2 = 250) And (Col3 = 0 Or Col3 = 250) Then
  C1 = Int(Rnd * 3)
  C2 = Int(Rnd * 3)
  C3 = Int(Rnd * 3)
End If
If C1 = 1 And Col1 <> 0 Then Col1 = Col1 - 10
If C2 = 1 And Col2 <> 0 Then Col2 = Col2 - 10
If C3 = 1 And Col3 <> 0 Then Col3 = Col3 - 10
If C1 = 2 And Col1 <> 250 Then Col1 = Col1 + 10
If C2 = 2 And Col2 <> 250 Then Col2 = Col2 + 10
If C3 = 2 And Col3 <> 250 Then Col3 = Col3 + 10
leds[x] = RGB(Col1, Col2, Col3)

Here is my Arduino setup:
#include <FastLED.h>

#define LED_COUNT 60
#define LED_OUT       13
#define BUTTON_IN     10
#define ANALOG_INPUT  A9
#define EXTRA_PIN_A    7
#define EXTRA_PIN_B   11

struct CRGB leds[LED_COUNT];

void setup() {
  Serial.begin(57600);
  LEDS.addLeds<WS2812B, LED_OUT, GRB>(leds, LED_COUNT);
  LEDS.show();
}

void loop() {
  //where to implement
}

I think this should work fine:
#include <FastLED.h>

#define LED_COUNT     96
#define LED_OUT       13
#define BUTTON_IN     10
#define ANALOG_INPUT  A9
#define EXTRA_PIN_A    7
#define EXTRA_PIN_B   11

struct CRGB leds[LED_COUNT];

void setup() {
  Serial.begin(57600);
  LEDS.addLeds<WS2812B, LED_OUT, GRB>(leds, LED_COUNT);
  LEDS.show();
}

void colorLoop() {

  static int Col1;
  static int Col2;
  static int Col3;

  static int C1;
  static int C2;
  static int C3;

if ((((Col1 == 0) || (Col1 == 250)) && (((Col2 == 0) || (Col2 == 250)) && ((Col3 == 0) || (Col3 == 250))))) {

// select a random number from 1 to 2 for the array
C1 = random(1, 3);
C2 = random(1, 3);
C3 = random(1, 3);
}

if (((C1 == 1) && (Col1 != 0))) {
    Col1 = (Col1 - 10);
}
if (((C2 == 1) && (Col2 != 0))) {
    Col2 = (Col2 - 10);
}
if (((C3 == 1) && (Col3 != 0))) {
    Col3 = (Col3 - 10);
}

if (((C1 == 2) && (Col1 != 250))) {
    Col1 = (Col1 + 10);
}
if (((C2 == 2) && (Col2 != 250))) {
    Col2 = (Col2 + 10);
}
if (((C3 == 2) && (Col3 != 250))) {
    Col3 = (Col3 + 10);
}

for (uint8_t i = 0; i < LED_COUNT; i++) {
   leds[i] = CRGB(Col1, Col2, Col3);
  }
delay(100);
LEDS.show();
}

void loop() {
  colorLoop();
}

Fairly simple. Understand what the basic code is trying to do and recreate that functionality in c.
In this case, it is looking for a set of conditions to trigger the generation of three random numbers which are then combined into a code for the run array.

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


text:
Cheapest and easiest Arduino board for 12 bit ADC, thinking of M0
I need an Arduino board for simple ADC, but 10 bits of resolution is sadly not enough. I am going to buy a board with 12 bits of resolution, but really couldnt decide on the exact model. It needs to be easily accessable and wont be used for anything else other then ADC. I have my eye on MO, but cant decide if i should buy the pro or the normal one, or just another Arduino board.
I take the data through USB port and the instrument will also be powered with the same USB cable.
* My only option is to use an Arduino*
I know i can use the Aref pin or do oversampling but i really am not intrested in those options. thanks for your input

Is there a reason for not just using whatever board you already own/use along with an external ADC?

@RobertoLoGiacco  well sadly, thats not an option, since the person who wants that project needs it in that way for some specific reasons

You can use Nucleo boards too. But I'm not sure how about it's with arduino ide support. But mbed is sometimes much better. Just libraries aren't available for specific hardware sometimes.

What speed ADC do you need?

@MichaelVincent it really doesnt matter at all, its really a simple data acquisition, even 2 samples per second is enough.

The problem with ADCs is that to get its full resolution you often need to "help it out" usually with software.  Dig into the specifications of what ever chip you end up with.  Find out the number of significant bits for a given sampling speed.  Usually the longer you allow a ADC to work it's magic the better it performs.  Then, you will likely want to average out as many samples as you can.  This, obviously, is for a signal that doesn't change (much).  Like the charge on a battery. If, on the other hand, you are sampling a fast signal.  Then you need to get a really good ADC to begin with.

How fast is the signal you are trying to digitise moving?  Is it virtually stable?  Regards,

The statement my only option is to use an Arduino is not unambiguous whatsoever.
If you meant "Compatible with Arduino IDE" than the Teensy 3.2, officially priced on the Arduino store at 17.90 EUR + VAT is the cheapest official Arduino board providing a 12 bit ADC.
If you meant "Branded as an Arduino" then the Arduino/Genuino M0 Zero, officially priced at 22.00 42.90 EUR + VAT is the cheapest board providing a 12 bit ADC.
This is the result of a quick search on the Arduino web site, which you could have checked yourself.
In my opinion the cheapest "Arduino based" solution would be an Arduino Pro Mini (officially discontinued) or a barebone ATmega328P along with an external 12 bit ADC. This opens up for many options, just use a parametric search on DigiKey, Octopart or any other website of your choice.
A quick search ended up with MAX1245ACAP priced at 1.30 USD + VAT, probably ending in a BOM cost for the entire solution below 10 USD + VAT, excluding the PCB.
UPDATE: as stated in the comments, the M0 is a cheaper version of the Zero.

i also checked the Arduino website but, what really got me confused was M0 and Zero - one from arduino.cc and other from arduino.org - offers the same ADC resolution but the pricing is quite different. Maybe i should have asked straight away "zero or M0" but doing some research on that didnt really pay off.

What meaning do you assign to the word “ubiquitous”?  Its dictionary meaning is  “Being everywhere at once: omnipresent” or  “Widespread; very prevalent”.

The M0 and Zero both use the same processor. The M0 is probably the cheaper one, as it doesn't have the separate programming and debugging chip that the Zero has. It's a nice feature, but I don't think it's working yet with the Arduino IDE. So they are kind of the same. So just get the cheapest one.

Use a Teensy 3.x. Those have 13 bit ADCs

well, allthough i appriciate the thought, it strictly has to be a arduiona board. and 12 is just enough.

Every time someone comes with a suggesting, another requirement pops up. Please add all your requirements in your question, and stop wasting our time. If it has to be Arduino, just go to the Arduino website. They only have a handful of products. Just check them all to see if they meet your magical list of requirements.

i really would hate to waste anyones time but i thought the first sentence of my question, "I need an Arduino board for simple ADC" should have been enough to make myself clear. Anyways thanks for your time

... But it has to be orange with a plaid silk screen ...

The Teensy is Arduino-compatible. I though that would be enough. Look into the Arduino Zero. I think that is the only option.


text:
Uploading .hex to ATTiny13 using Arduino
I would like to upload a .hex to ATTiny13V (or '13A) using Arduino Uno R3.
I think I know everything to do, but ATTiny13 ISP support and Arduino IDE is a bit search-and-find, and I have some grey-areas in my understanding of how this all works together.
I got here by:
-Finding an Instructable that did something I liked, and there's a ATTiny13V used, a .hex to upload, and C source if I want to modify the source.  Right now I do not need to modify the source, the available .hex is fine.
-I then looked for a way to have AVR programing from OS X.  This seems a little problem, many AVR programmer hardware work great under Windows but seem to have mixed results under OS X.  I saw Arduino could be used for this under OS X.
-I looked on local craigslist for Arduino, someone was selling a Uno R3 with some extras for a great price, and here we are.   And now I have a lot more projects I wish to complete!
I am using Arduino 1.6.10 (from the .cc not the .org).
I read on stackexchange and other places that smeezekitty's core13 works for the ATTiny13.
elabz.com/arduino-shrunk-how-to-use-attiny13-with-arduino-ide/
That's great, but: If I am not using any of the Arduino-specific commands, I don't think I need the bootloader, correct?  I think it is not really a bootloader but builds support for some of the Arduino-specific higher-level commands used by sketch files.
Do I even need the ATTiny13 core files if I hook the pins up properly between the '13 on a breadboard and the Arduino (as per here:  https://create.arduino.cc/projecthub/arjun/programming-attiny85-with-arduino-uno-afb829 ).
I really do not understand what the Arduino IDE/bootloader is doing for me as an abstraction layer.  Do I need the bootloader if I'm not using any of the higher-level Arduino-specific commands on the chip?  HOw about the core files for ATTinyanything vs specifically ATTiny13?
The hex file and C source I will be using are here:
http://www.instructables.com/id/Programmable-LED/
My nextstep will be to modify the source. The C source looks like it references some AVR-specific header files.  I see that the ArduinoIDE uses avrdude so maybe things will compile anyway?
I feel like I'm close but not 100% in my understanding of what I need to do, with the tools I have on hand.
Thanks for your help- I am not above a step-by-step.
Main question 1:  I have a .hex file, an Arduino and IDE 1.6.10, OS X, and breadboard and useful components.  What do I need to do to put the hex on this ATTiny13?
Main question 2: Jumping-off points for taking the C source I linked, tweaking it a bit, building a hex, and uploading that.  I am not against moving it to a sketch if I have to, but it would be good for me to learn how this works before I mode to the IDE.
I have a small software background, am comfortable taking that C source and making changes and compiling (assuming I can find the needed .h files), but this is my first time working with any multiprocessors.

Your computer cannot talk directly to the ATtiny. You need some piece of
interfacing hardware between them. This is called an ICSP (or ISP)
programmer. You also need software to drive the programmer, typically
avrdude.
If you do not have a programmer, you can buy one (I had success with
some very cheap USBASPs), or you can program an Arduino Uno to behave
like an ISP programmer. You do this by uploading into the Arduino a
program called ArduinoISP, like explained in the tutorial Using an
Arduino as an AVR ISP (In-System
Programmer). You will
typically use the Arduino IDE and the Arduino core for the Uno to
compile and load ArduinoISP into your Uno. Once this is done, you can
use the Arduino as a programmer and burn your .hex into your ATtiny.
If you want to compile your own programs for the ATtiny, you will need
the avr-gcc compiler and the avr-libc. These are bundled with the
Arduino IDE, so you already have them. You will need an Arduino core for
the ATtiny only if you want to use the Arduino APIs and libraries.
Otherwise you can write plain C programs with noting else than the
avr-libc and avr-gcc.
Edit: To compile a plain C program, you can type something like
this:
avr-gcc -mmcu=attiny13a -DF_CPU=1200000 -Os -Wall -Wextra flickled.c -o flickled.elf
avr-objcopy -O ihex flickled.elf flickled.hex

This assumes your source file is called flickled.c and your ATtiny
runs at 1.2 MHz.

This worked great, I've programmed both .hex and new sketches into the ATTiny13 using the Uno as ISP. Thank you!


text:
SD card fails to write every 5 or 6 minutes
My SD card initializes fine in the beginning. It finds the right file and opens it. However, after 5 or 6 minutes of data logging, the error "file not found" appears on my LCD. Why would this be the case? I need this to work consistently for at least an hour, this 5 to 6 minutes will not do.
Also, in my code the "sv" and "cpm" data is not yet initialized, due to another problem incorporating a sensor. I left these in there, and the data is just logged as 0 for those variables.
#include <SPI.h>
#include <MPL115A1Lib.h>  // Pressure Sensor MPL115A1
#include <DHT.h>  // Temperature and Humidity Sensor RTH03
#include <U8glib.h>  // LCD Display 128x64
#include <floatToString.h>  // Converts floats to strings
#include <GPS610F.h>  // GPS-610F Module
#include <RFZuluArduino.h>  // Zulu 2km RF Module
#include <SD.h> //SD data logger

//----- Defining Modules and Variables ------//
// Pressure Sensor
MPL115A1Lib PressSens;  // Defines Pressure Sensor for library
#define FT_TO_M(x) ((long)((x)*(0.3048)))
#define KPA_TO_INHG(x) ((x)*(0.295333727))
#define KPA_TO_MMHG(x) ((x)*(7.50061683))
#define KPA_TO_PSIA(x) ((x)*(0.145037738))
#define KPA_TO_KGCM2(x) ((x)*(0.0102))
#define INHG_TO_PSIA(x) ((x)*(0.49109778))
#define DEGC_TO_DEGF(x) ((x)*(9.0/5.0)+32.0)

float press_pKa = 0;
float temp_c = 0;
long alt_ft = 0;
char charPress[7];  // Stores pressure
char charTemp[6];  // Stores temperature in C
char charAlt[5];  // Stores altitude
// Temperature & Humidity Sensor
#define DHTPIN 48     // Defines signal pin connection
#define DHTTYPE DHT22   // Defines Sensor model # DHT22 (RTH03)
DHT dht(DHTPIN, DHTTYPE);  // Defines the Temp/Humd Sensor
float t = 0;  // temp
float h = 0;  // rel. humd.
float f = 0;  // temp in f
float hi = 0;  // heat index
char rh[6];  // Stores Relative Humidity
char tempC[6];  // Stores Temperature in °C
char tempF[7];  // Stores Temp in F
char heatIndex[7];  // Stores heat index
char degree[3] = {176, 67};  // Stores °C symbol
char degreeF[3] = {176, 70};  // Stores °F symbol
// LCD Display
U8GLIB_ST7920_128X64_4X u8g(41, 42, 43);  // Defines LCD pins (SPI: EN = 41, RW = 42, RS = 43)
// GPS Module
GPS610F gps(17, 16, 28, 26, 44, 27, 9600);  // Defines GPS pins (SDI, SDO1, SDO2, PIO, PPS, RST, baudRate)
String gpsData;
char charGPS[82] = "";
String strnmeaProto;
String strutcTime;
String strgpsStatus;
String strlatitude;
String strnsIndicator;
String strlongitude;
String strewIndicator;
String strspeedOverGnd;
String strcourseOverGnd;
String strutcDate;
String strmagVarDegrees;
String strmagVarDirection;
String strmodeIndicator;
String strcheckSum;
char nmeaProto[6] = "";
char utcTime[11] = "";
char gpsStatus[2] = "";
char latitude[11] = "";
char nsIndicator[2] = "";
char longitude[11] = "";
char ewIndicator[2] = "";
char speedOverGnd[6] = "";
char courseOverGnd[6] = "";
char utcDate[7] = "";
char magVarDegrees[6] = "";
char magVarDirection[2] = "";
char modeIndicator[2] = "";
char checkSum[3] = "";
char tempTime[9] = "";
char tempDate[9] = "";
char tempLat[12] = "";
char tempLong[13] = "";
// RF Module
RFZuluArduino rf(15, 14, 2, 3, 4, 5, 4800);  // Defines the RF module's pins (rx1, tx1, RTS, CTS, RST, PD, baudRate)
//Data Logger
const int chipsSelect = 10;
File Data;
String Header = "DATE(utc)  TIME(utc)  STATUS  MODE  LATITUDE(deg)  LONGITUDE(deg)  SPEED(km)  COURSE(deg)  Temperature(C)  Temperature(F)  Humidity(%RH)  Heat Index(F)  Pressure(kPA)  Altitude(m"; //CPM  uSV/hr";
int dcounter = 0;
//Geiger Counter
unsigned int gcount = 0;
unsigned int countStartTime = 0;
int countsPerMinute;
float coefficientOfConversion = 140.0 / 60000.0;
float sV = 0;
String str;  // temporary string
int draw_state = 0;
int tracker = 0;

void setup() {
  pinMode(53, OUTPUT);
  dht.begin();
  if (!SD.begin(10, 11, 12, 13)) {
    // see if the card is present and can be initialized:
    u8g.firstPage();
    do {
      drawCardError();
    }
    while (u8g.nextPage());
    while (1);  // don't do anything more:
  }
  Serial1.begin(9600);
  // start serial port for geiger counter
}

void loop() {
  delay(1000);
  //----- Get Sensor Data -----//
  // Temp/Humid
  h = dht.readHumidity();
  t = dht.readTemperature();
  f = dht.readTemperature(true);
  /*if (isnan(h) || isnan(t) || isnan(f)) {  // check for failed reading from sensor
    return;
    }*/
  hi = dht.computeHeatIndex(f, h);
  // Pressure Sensor
  press_pKa = PressSens.calculatePressurekPa();
  alt_ft = PressSens.calculateAltitudeFt(press_pKa);
  // GPS
  gpsData = gps.getData();
  strnmeaProto = gps.dataFields(0);
  strutcTime = gps.dataFields(1);
  strgpsStatus = gps.dataFields(2);
  strlatitude = gps.dataFields(3);
  strnsIndicator = gps.dataFields(4);
  strlongitude = gps.dataFields(5);
  strewIndicator = gps.dataFields(6);
  strspeedOverGnd = gps.dataFields(7);
  strcourseOverGnd = gps.dataFields(8);
  strutcDate = gps.dataFields(9);
  strmagVarDegrees = gps.dataFields(10);
  strmagVarDirection = gps.dataFields(11);
  strmodeIndicator = gps.dataFields(12);
  strcheckSum = gps.dataFields(13);

  //----- Convert to Transmit -----//
  // Temp/Humid
  floatToString(rh, h, 1);  // relative humidity
  floatToString(tempC, t, 1);  // temperature in C
  floatToString(tempF, f, 1);  // temp in F
  floatToString(heatIndex, hi, 1);  // heat index
  // Pressure Sensor
  str = String(FT_TO_M(alt_ft));  // convert altitude in ft to m
  str.toCharArray(charAlt, 5);  // covert string to char array
  floatToString(charPress, press_pKa, 2);
  // GPS Module
  gpsData.toCharArray(charGPS, 80);  // convert string to char array
  strnmeaProto.toCharArray(nmeaProto, 6);
  // time
  strutcTime.toCharArray(utcTime, 11);
  tempTime[0] = utcTime[0];
  tempTime[1] = utcTime[1];
  tempTime[2] = ':';
  tempTime[3] = utcTime[2];
  tempTime[4] = utcTime[3];
  tempTime[5] = ':';
  tempTime[6] = utcTime[4];
  tempTime[7] = utcTime[5];
  strgpsStatus.toCharArray(gpsStatus, 2);
  // latitude
  strlatitude.toCharArray(latitude, 11);
  strnsIndicator.toCharArray(nsIndicator, 2);
  tempLat[0] = latitude[0];
  tempLat[1] = latitude[1];
  tempLat[2] = 176;   // °
  tempLat[3] = latitude[2];
  tempLat[4] = latitude[3];
  tempLat[5] = latitude[4];
  tempLat[6] = latitude[5];
  tempLat[7] = latitude[6];
  tempLat[8] = 39;  // '
  tempLat[9] = ' ';
  tempLat[10] = nsIndicator[0];
  // longitude
  strlongitude.toCharArray(longitude, 11);
  strewIndicator.toCharArray(ewIndicator, 2);
  tempLong[0] = longitude[0];
  tempLong[1] = longitude[1];
  tempLong[2] = longitude[2];
  tempLong[3] = 176;   // °
  tempLong[4] = longitude[3];
  tempLong[5] = longitude[4];
  tempLong[6] = longitude[5];
  tempLong[7] = longitude[6];
  tempLong[8] = longitude[7];
  tempLong[9] = 39;  // '
  tempLong[10] = ' ';
  tempLong[11] = ewIndicator[0];
  strspeedOverGnd.toCharArray(speedOverGnd, 6);
  strcourseOverGnd.toCharArray(courseOverGnd, 6);
  // date
  strutcDate.toCharArray(utcDate, 7);
  tempDate[0] = utcDate[0];
  tempDate[1] = utcDate[1];
  tempDate[2] = '/';
  tempDate[3] = utcDate[2];
  tempDate[4] = utcDate[3];
  tempDate[5] = '/';
  tempDate[6] = utcDate[4];
  tempDate[7] = utcDate[5];
  strmagVarDegrees.toCharArray(magVarDegrees, 6);
  strmagVarDirection.toCharArray(magVarDirection, 2);
  strmodeIndicator.toCharArray(modeIndicator, 2);
  strcheckSum.toCharArray(checkSum, 3);
  // transmit the data
  rf.transmit(gpsData, tempC, rh, charPress);
  //-----Writes Data to SD Card-----//
  Data = SD.open("DATA", FILE_WRITE);
  if (!Data) {
    u8g.firstPage();
    do {
      drawFileError();
    }
    while (u8g.nextPage());
    while (1);  // don't do anything more:
  }
  dcounter++;
  if (dcounter == 1) {
    Data.println(Header);
  }
  Data.print(strutcDate + "     " + strutcTime + "   " + strgpsStatus + "      " + strmodeIndicator + "     " + strlatitude + "     " + strlongitude + "     " + strspeedOverGnd + "        " + strcourseOverGnd + "          ");
  Data.print(t);
  Data.print("          ");
  Data.print(f);
  Data.print("            ");
  Data.print(h);
  Data.print("         ");
  Data.print(hi);
  Data.print("            ");
  Data.print(press_pKa);
  Data.print("         " + str + "  ");
  Data.flush();
  Data.print(countsPerMinute);
  Data.print("  ");
  Data.println(sV, 5);
  Data.flush();
  //----- Output to LCD Display -----//
  u8g.firstPage();
  do {
    draw();
  }
  while (u8g.nextPage());
  tracker++;
  if (tracker <= 2) {
    draw_state = 0;
  } else if (tracker <= 5) {
    draw_state = 1;
  } else if (tracker <= 8) {
    draw_state = 2;
  } else {
    tracker = 3;
  }
}

//----- LCD Display Drawings -----//
void drawCardError() {
  u8g.setColorIndex(1);
  u8g.setFont(u8g_font_baby);
  u8g.drawStr(12, 32, "Card Failed, or not present");
}

void drawFileError() {
  u8g.setColorIndex(1);
  u8g.setFont(u8g_font_baby);
  u8g.drawStr(5, 32, "Error opening DATA");
}

void draw(void) {
  LCDprepare();
  switch (draw_state) {
    case 0:
      AECLlogo();
      break;
    case 1:
      SensorInfo();
      break;
    case 2:
      GpsInfo();
      break;
  }
}

i am having trouble formatting, someone please help me with this!

fixed, I have remvoed some of the ending code thought. They were just functions for the lcd

The section under //-----Writes Data to SD Card-----// should go in setup().

yes thank you, i realize that my program opens the file when it already opens causing a memory leak, that and also the string class is apparently a big issue

Try removing all the u8g stuff to check for SPI problems.

Manan, if you have actually figured out the real problem and fixed it, could you write an answer that will help the next person with this problem? (As recommended on the help page, at [meta](http://meta.stackexchange.com/questions/17463/can-i-answer-my-own-questions-even-if-i-knew-the-answer-before-asking, etc.). Or are you just saying that you fixed the formatting?

@Manan as you can see, David Cary's remark still applies. Today your question was bumped to the homepage again. Please, write an answer and mark it as accepted. You will gain reputation points, and this question will stop being bumped to the homepage every now and then...

Might be a flaky SD card, you get that sometimes. Try changing to another card and see if it helps.
SD card formatter tool might also be useful: https://www.sdcard.org/downloads/formatter_4/

Are you sure there are no rollovers / overflows? Keep in mind the limitations of FAT16, max volume size is 2GB, and only with the max sector size of 512B.
At minimum dcounter will overflow in 9 hours if you log every second.

OK, it looks like this question is going to be floating with not accepted answer for all of eternity since the poster clearly isn't responding to comments.
But if it works for a few minutes and then dies it's probably something silly like opening the same file every second and never closing that's the cause of the issues rather than a bad SD card or a counter that will overflow after 9 hours.

Answered by OP in the comments
"fixed, I have remvoed some of the ending code thought. They were just functions for the lcd"

I believe that comment was just saying they had solved their formatting problems with the question. However, their next comment: http://arduino.stackexchange.com/questions/4419/sd-card-fails-to-write-every-5-or-6-minntes#comment9656_4419 does make me think they found that a memory leak was the cause of the problem but unfortunately didn't bother to properly answer their own question.


text:
Leonardo-based tachometer?
I'm new here. I'm not a native speaker, so pardon my English.
I just received my Arduino Leonardo today. I tried some basic calculations and stuff like blinking and LCD interfacing. Its interesting.
I am now trying to make a tachometer with the Leonardo. I'm following this tutorial.
I guess the board they've used differs from the Arduino Leonardo (ie pin 3 is interrupt0 in the Leonardo but it is pin 2 in the Arduino Uno board used in the tutorial). I tried changing the pins on the program and reconnecting the circuit but it doesn't work.

This is the code from the tutorial:
/* Optical Tachometer
 *
 * Uses an IR LED and IR phototransistor to implement an optical tachometer.
 * The IR LED is connected to pin 13 and ran continually.
 * Pin 3 (interrupt 0) is connected across the IR detector.
 *
 * Code based on: www.instructables.com/id/Arduino-Based-Optical-Tachometer/
 * Coded by: arduinoprojects101.com
 */

int ledPin = 13; // IR LED connected to digital pin 13
volatile byte rpmcount;
unsigned int rpm;
unsigned long timeold;
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);

void rpm_fun() {
  //Each rotation, this interrupt function is run twice,
  //so take that into consideration for calculating RPM
  //Update count
  rpmcount++;
}

void setup() {
  lcd.begin(16, 2); // intialise the LCD
  //Interrupt 0 is digital pin 2, so that is where the IR detector is connected
  //Triggers on FALLING (change from HIGH to LOW)
  attachInterrupt(0, rpm_fun, FALLING);
  //Turn on IR LED
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, HIGH);
  rpmcount = 0;
  rpm = 0;
  timeold = 0;
}

void loop() {
  //Update RPM every second
  delay(1000);
  //Don't process interrupts during calculations
  detachInterrupt(0);
  //Note that this would be 60*1000/(millis() - timeold)*rpmcount if the interrupt
  //happened once per revolution instead of twice. Other multiples could be used
  //for multi-bladed propellers or fans
  rpm = 30*1000/(millis() - timeold)*rpmcount;
  timeold = millis();
  rpmcount = 0;
  //Print out result to LCD
  lcd.clear();
  lcd.print("RPM=");
  lcd.print(rpm);
  //Restart the interrupt processing
  attachInterrupt(0, rpm_fun, FALLING);
}

Can anyone help me to fix the project? Has anyone here tried this project before?
Thank you!

Try removing the phototransistor, get a jumbercable from ground and insert and remove it a few time at the point where the resistor and the photodiode were connected. If any rpm shows up on the lcd, you'd know it's that photodiode that is faulty, or just not near enough to the ir-diode. The code looks fine, and INT0 is indeed on pin D3 instead of D2.

Your circuit looks wrong to me (although I haven't worked much with phototransistors). Why do you not have a resistor for the LED? Is it one built for 5V? Also, as far as I know, phototransistors only conduct when there's light. It seems odd to add a pull up resistor so it always reads high...

What specifically did you do when you said you tried changing the pins in the program? have you tried running the program stock and changing the wiring to use pin 3? Also, can you be more specific how it is not working? is it always printing 0 RPM?

yeah it is always writing rpm = 0. I've changed the interrupt0 to pin 3 on leonardo. would you guys suggest some simple way to test attachInterrupt() with ir transistor, i have both 2 pinned ( ?, ? )and 3 pinned (+, out , -) ir transistors/sensors. thank you!

First, make sure that your LCD routines and wiring are working, by trying to display something on it.
Second, the code isn't correct - it will have some fluctuations from one measurement to another.
One way to do it is to start timing only after the first pulse has arrived, and stop timing only after the last pulse has passed.
Something like this:

Wait until a falling edge.
Time0 is millis().
Wait for N pulses to pass.
Time0 is millis() minus time0.

Now with time0 and N you can calculate your rpm.
Edit:
Here is the above code at work, running Arduino on a PIC24.

The input signal is 10Hz, 1 pulse per revolution, aka 600 rpm.
As you can see the rpm read-out is precisely 600rpm. I'm running the code at 8x oversampling.
As I indicated earlier, your code will introduce uncertainty, as much as one period for the pulses. So in a single pulse measurement, the rpm can be anywhere from 0.5x of the true value to 1.0x of the true value.


text:
WiFi101 vs WiFININA - reliability issues
I've got the same code running on 2 different boards:

MKR1010
Adafruit Feather M0

I'm using WiFiNINA on the former, and WiFi101 on the latter.
Other than that, the code that's exactly the same: every 10 seconds connects to WiFi, sends an HTTPS Request, and then sends a response back to the server (response is a bunch of metrics: memory, counter, time & day).
I am also using a WDT to reset the board if it hangs.
After a lot of refinement and experiments, the Adafruit board is able to run for days with no hangs (indicated by no WDT triggers), and no visible degradation (e.g. memory stays stable over time).
The MKR1010 board, on the other hand, resets several times per day.
What I've done?
I've been able to narrow down issues to the network stack (I think). I've randomly injected a bogus hostname to the WiFikSSLClient::connect method (e.g every n calls, where n is random,  I will switch the real hostname with something that will not resolve, simulating a longer latency).
In reviewing the WiFi101 codebase I've found a long, hardcoded, non-customizable timeout here.
...
while (_info[sock].state == SOCKET_STATE_CONNECTING && millis() - start < 20000) {
        m2m_wifi_handle_events(NULL);
    }
...

20 seconds is greater than the max WDT timeout (16 seconds). You can argue that for network operations, 20 seconds would be reasonable, but I'm expecting connections in my network to happen much faster, so I tweaked the library (WiFi101) to 10 seconds and the reliability increased significantly. Every once in a while I get a connection error, but that is fine. The system recovers nicely on the next attempt.
I have not been able to find similar timeouts in WiFiNINA (looks like a much more complex codebase too, but that is my first impression. I'm not an expert)
If I disable the WDT around the connect method, then the MKR1010 will hang after some time. If I leave it, it will recover through a WDT reset.
I'm making sure the firmware on both boards is up to date.
While the WDT solves the issue of ensuring the board recovers, I'd love to fix it properly.
Questions

Is this consistent with anyone's experience?
Are there alternatives to WiFiNINA for the MKR1010?
Is there something obvious I'm missing when configuring the WiFI stack (e.g. a timeout someplace else)?

I'm a bit lost here: you say you have a problem with the MKR1010/WiFiNINA combination, and changing a time-out in the WiFi1010 library helps?

Thanks @Juraj for the edits, good catches! ocrdu, sorry I wasn't clear enough. In a nutshell:

MKR1010 + WiFiNINA  -> not reliable
Adafruit Feather M0 + WiFi101 -> reliable (once I changed the library timeout to 10s)

Could this be the same problem as described here? https://github.com/arduino-libraries/WiFiNINA/issues/103