text:
Will Setting Interrupt Pin High Damage Bluetooth Module?
I want my HC05 Bluetooth Module to trigger an interrupt when it receives a signal. So I've followed suggestions from the Arduino Forum and connected the Bluetooth TXD pin to the Arduino RX Pin and the Interrupt Pin (2), which I set to high. It is set to detect a FALLING voltage, presumably when BT transfers data. When I connected it this way a funny thing happens. I can clearly see that the interrupt is being called because power consumptions goes way up when Android sends a message to BT module, meaning the device wakes up. However the serial port no longer appears to work on the Nano. I think I narrowed down the possible cause to me damaging the board by removing lineage regulator or damaging serial port somehow with the interrupt. Is the way I wired up the interrupt pin as described correct? Your help would really help me narrow down my problem.
#include <avr/sleep.h>

#define ledPin 7
#define intPin 3
int state = 0;
int stateData = 0;
int ultraPin = 10;
int trigPin = 11;    // Trigger
int echoPin = 12;    // Echo
long duration, cm;
unsigned char inches;
unsigned long timer;

void setup() {
  pinMode(ultraPin, OUTPUT);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(intPin, INPUT);
  digitalWrite(intPin, HIGH);
  attachInterrupt(digitalPinToInterrupt(intPin), interrupt, FALLING);
  digitalWrite(ultraPin, LOW);
  Serial.begin(9600); // Default communication rate of the Bluetooth module
  set_sleep_mode(SLEEP_MODE_PWR_DOWN);
  sleep_enable();
  sleep_cpu();
}

void interrupt(){
  Serial.println("interrupted");
  sleep_disable();
  Serial.write(50);
  delay(500);
  timer = millis();
  digitalWrite(ultraPin, HIGH);
  while (true){
      digitalWrite(trigPin, LOW);
      delayMicroseconds(2);
      digitalWrite(trigPin, HIGH);
      delayMicroseconds(10);
      digitalWrite(trigPin, LOW);
      pinMode(echoPin, INPUT);
      duration = pulseIn(echoPin, HIGH);
      cm = (duration / 2) / 29.1;   // Divide by 29.1 or multiply by 0.0343
      inches = (duration / 2) / 74; // Divide by 74 or multiply by 0.0135
      Serial.write(inches);
      delay(50);
      stateData = Serial.read();
      if (stateData != 49){
        // receipt from android
        unsigned long timeElapse = millis() - timer;
        if (timeElapse > 5000) {
          break; // exit and SLEEP
        }
      }
      else {
          // reset the timer
          timer = millis();
        }
      }
    sleep_enable();
    sleep_cpu();
}

void loop() {

}

setting pin to high works only in output mode

For an input digitalWrite HIGH will turn on the internal pull-up.

@jsotola not necessarily true: https://www.arduino.cc/reference/en/language/functions/digital-io/digitalwrite/

@ILike that us somewhat correct ... but enabling the pullup resistor is not the same as driving the pin high ... driving the pin high could destroy a sensor output, or the arduino pin, if the sensor drove the pin low ... the pullup resistor would not cause damage because the resulting current would be limited by the pullup resistor ... after all, pullup resistors are used with switches that short the pin to ground when pressed

I'm not sure, if you can rule out the hardware damage (you wrote, that you removed the linear voltage regulator, but didn't explain more there). But with that code you won't get what you want.
I see multiple issues, all boiling down to the same problem: You cannot do that inside of an ISR:

delay() relies on interrupts to happen during its execution. As of my knowledge this leads to delay() never ending, blocking your code. Also it is very bad design to have a long running ISR. So much is depending on interrupts to work and when you have something long running, you can just easily do that inside the main code, triggered by an interrupt flag variable.
millis() will not increment during the run of the ISR.
delayMicroseconds() will work, but you still should keep the ISR very short. Reading an ultrasonic sensor is a no-go.
Serial.write() will fill the libraries internal TX buffer, but the actual transmission of the data also relies on interrupts. You won't get your data that way.

Instead of doing all that inside the ISR, you should just let the Arduino wake up, then set a (single byte) flag variable. In your main code you need to check for that flag with an if statement. In that if statement, you are doing all what you need to do and at the end you are resetting the flag and going to sleep again.

I see, so the main issue is that I am using interrupt inside an interrupt routine, which doesn't work?

You are using code, which relies on interrupts, in an interrupt. You are not using interrupts inside of an interrupt, that is a phrase, that does not make sense. For example the function Serial.write() does not use an interrupt, it just places the data in the TX buffer. But the rest of Serial uses interrupts to actually send the data out


text:
How to wire a three-pin on-off-on switch for reading input?
I would like to read the output of an on-off-on switch with my Leonardo board, but I have very little knowledge of electronics and don't know how to wire it up.
This is the switch in question: E-Switch 200MSP4T1B1M1QE
The switch has three pins. Generic three-pin SPDT wiring diagrams I've found suggest that the two outer pins should be connected to separate lights and the middle pin should be connected to the power source. Those lights also have a ground connection.
I don't want to power anything in a literal sense, I only want to have the Leonardo read the output of the switch. The end goal is to have the two ON positions read as separate button presses (eventually using a joystick library, in case that changes how the switch needs to be wired).
My questions are:

Is the above wiring example correct for my use case?
Is the output of the switch considered digital or analog?
Is a wire from the switch to GND not required?

One final note - I'm not using a breadboard, but connecting the wires directly from the switch to the board.

you could use analog input and use only one pin ... https://www.instructables.com/id/Analog-Keypad-Backpack/ ... also google arduino resistor ladder

You talk about wiring a switch to control lights directly. Instead, you want to use your switch to send information to your Arduino.
You link to an SPDT (single pole, double throw) switch. When flipped one way, it connects the center pin to one of the outside pins, and when flipped the other way, it connects the center pin to the other outside pin.
If you want the Leonardo to read the state of the switch as 2 separate switches/button presses, wire the 2 outer pins of the switch to 2 separate digital inputs on the Arduino.
You need to force each input to either ground or +5V when it's not connected to anything, or it will "float" and you'll get semi-random high and low readings.
I suggest setting the Arduino input pins to INPUT_PULLUP mode. That connects the inputs internally through a resistor to +5V. If you don't connect anything to the pin, it reads as HIGH. When the button is pressed/switch is closed, it reads LOW. That might seem a little confusing, but it means you don't need external resistors.
You'd then attach those to pins to the two outer pins of your switch, and attach the center pin to ground (GND).
If you flip the switch one way, it would connect one outer pin to the center pin. That would connect that Arduino pin to ground, and the reading on the pin would drop from HIGH to LOW. Flip the switch the other way and it would connect the other pin to ground, at that other pin would drop from HIGH to LOW.
It is also possible to wire your switches using INPUT mode, not INPUT_PULLUP, and have them read LOW when the switch is open, and HIGH when closed, but to do that you'll need external pull-down resistors. (And wiring it will be a little painful without a breadboard or PC board.)
To answer your questions:

Is the above wiring example correct for my use case?

You don't show a wiring example. You talk about how to wire a switch to switch power to a pair of lights directly, without using a microcontroller. That's not relevant here.

Is the output of the switch considered digital or analog?

It would make sense to use it as a digital input, since you need it to give you 2 states, open and closed.

Is a wire from the switch to GND not required?

You need to connect the center pin to either ground +5V, as discussed above.

See the diagram in Edgar's answer. A picture is worth a thousand words.

This is exactly what I was looking for, thank you! I would say this is the better answer. Not that the diagrams were bad, necessarily, but for someone with little wiring/circuitry experience the diagrams only confused me more.

If you feel this (or Edgar's) answer answers your question you should accept it. (Accepting the first/best answer that answers your question is expected on Stack Exchange sites.)

I suggest this simple circuit:

simulate this circuit – Schematic created using CircuitLab
Set both inputs to INPUT_PULLUP. If the input reads LOW, that means it has been grounded by the switch.

Edit: Per Duncan’s request, here is the alternative circuit with the polarities inverted. With the switch’s common connected to Vcc, the inputs should be set to INPUT_PULLDOWN. However, most Arduinos do not support this mode, for lack of internal pull-downs. Then one has to use external pull-downs instead, and set the pins to INPUT.

simulate this circuit
With this circuit, a pin reads HIGH when it is connected to +5V by the switch.

I didn't notice Duncan C posted an answer just while I was preparing mine. Both answers are the same: one with words, the other with an image.

I haven't used CircuitLab very much. A diagram is soooo much clearer. (voted.) Could you also show the alternate circuit with the switch connected to +5V, with pull-down resistors? Some newbies find LOW  == switch on confusing.

@DuncanC: OK, edited as per your request.

Why not save an input and use the != and == to determine which way the switch is positioned. less code less hardware.

@Gil: I don't understand. Did you notice it's a 3-positions switch? Would you post an answer expanding on your idea?

Gil has a good point. With a SPDT switch, you could wire it to turn on one light as it turns the other one off. If you're just passing info to an Arduino, you could only wire one input, and infer that the state of the other input is the opposite of the first input.

@DuncanC: Not with the 3-position switch the OP linked to: position 1 (left, momentary): terminals 2 and 3 connected, position 2 (center): nothing connected, position 3 (right, momentary): terminals 2 and 1 connected. See the datasheet.

Oh, I didn't realize it was that type of switch. I stand corrected.

Simple No center off was indicated in the drawing and in two of three statements. If it were then two inputs would be needed. This was assumed because I did not properly read his statement: I would like to read the output of an on-off-on switch.  However if you look up his link it is a DPDT no center off stated hence maybe I was correct. The data sheet gives us a lot of choices. Maybe the question needs a bit of clarifying.

Alternative Circuit
For the on-off-on switch, the MSP-3 and MSP-4 operate as follows:

Figure 1 – Operation of MSP-3 and MSP-4 switches.

POS
Connection
MSP-3
MSP-4

1
Terminal 2 to Terminal 3
ON
(ON)

2
Terminal 2 to open circuit
OFF
OFF

3
Terminal 2 to Terminal 1
ON
(ON)

Here is an alternative way to connect the SPDT to the MCU which is useful when running out of pins because it only requires one input pin. It does however require more complicated software to interpret the input e.g., hysteresis and debounce could be implemented with thresholds such as:

> 90% Vcc for > 50 ms means high.
< 10% Vcc for > 50 ms means low.
> 45% Vcc and < 55% Vcc for > 50 ms means OFF.
anywhere in between means no change.

Figure 2 – Connecting SPDT switch to MCU.
Throw vs Stop vs Contact
In normal parlance, a throw describes a physical action that moves a mechanism to a new mechanical stop; and throws are distinct from stops and contacts. As such, a switch is a transducer that converts physical movements (throws) to an electrical signal via a system of mechanical stops and electrical contacts.
From Figure 1, the totals are 2 throws, 3 positions, 2 contacts and 1 pole.
However, matters have been confused by a minority of people erroneously metamorphosing the term “throw” to mean “mechanical stop” or “electrical contact.”  As you can see in this example—as is often the case—the number of throws equals the number of contacts, but that is not always the case. For example, if there were a centre contact for the centre stop, there would be three contacts, but still only two throws. Perhaps the fact that throws and contacts are often equal in number has led some people to conflate and confuse the separate entities. And perhaps that the number of stops can sometimes equal the number of contacts has led some people to conflate and confuse them too. For this kind of switch, the number of throws is always one less than the number of stops.
Matters are not helped by the E-Switch 200MSP4T1B1M1QE datasheet showing an incorrect schematic for the MSP-3, 4 and 5 that omits the centre mechanical stop that should be labelled OFF.
I’ve re-annotated the datasheet, Figure 3, and modified the following prose to comply with the common-sense approach of Figure 1, being mindful that a minority of people use “throw” to mean “contact,” and added the correct schematic for MSP-3, 4 and 5. (The original annotated version and prose was an attempt to use the datasheet’s own erroneous nomenclature and schematic.)

Figure 3 – Annotated datasheet.
MSP-1, 2 and 6 are actually single-throw switches despite what the datasheet implies which conflates its description of its SPST with its SPDT switches (which caused some confusion in the comments about the intent and variety of the switch).
The switch required for the above example is the MSP-3 on-off-on. Or to simulate momentary button presses, the MSP-4 (on)-off-(on). Both of these are single-pole double-throw switches (SPDT), not because they have 2 electrical contacts, but because they have 2 physical throws.
In the context of the erroneous datasheet, throws and contacts are erroneously synonymous. In normal parlance, neither throws nor positions are electrical contacts/terminals/pins (though the datasheet has conflated them as well). However, each mechanical stop does have an associated electrical connection/disconnection that should be explained in the datasheet. Unfortunately, in this case, the table in the datasheet has conflated SPST with SPDT and used the term “NONE” to indicate that a position doesn’t exist for the SPST types (MSP-1, MSP-2, and MSP-6). For MSP-3, 4, and 5, notice how POS 2 doesn’t have an associated contact/terminal/pin in the green schematic, Figure 3.
From experience, the only way to be sure is to buzz out the switch with a multimeter (continuity test). So, keep Figure 1 in your mind and a multimeter in your hand, and you won’t go far wrong.
Conclusions

Throws are physical.
Stops are mechanical.
Contacts are electrical.
Claims such as, “My contact is a throw.” are delusional.
Conclusions can be lyrical.

Phantom Scroll-By Downvoter
This answer has a attracted a phantom downvote with no comment expressing why this is warranted.
Does the phantom think:

the alternative circuit is wrong?
the thresholds are wrong?
the errant use of the English language and dodgy schematics in the datasheet are acceptable?

Bear in mind that the terms “throw,” “stop,” and “contact” (their meanings and usage) are taught by schoolteachers to millions of school children every year; and used by billions of English speakers every day. Is the global education system (which isn’t perfect) wrong on this particular point? On what grounds and exceptional circumstances is a datasheet allowed to use such terms in an inappropriate manner?

Comments are not for extended discussion; this conversation has been moved to chat.

source: Stack Exchange

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

sort: votes


text:
Wireless playstation 2 remote not connecting up to arduino
I am trying to connect my wireless playstation 2 remote up to my arduino but I am facing one problem. Whenever I restart my program (by clicking the red button) the PS2 remote's dongle blinks at the exact same times as the blink light on the arduino blinks. But as soon as the arduino's light stops blinking, the RX light on the PS2 dongle (which was blinking), stops blinking. I saw a guide out there on potential ways of fixing this and one type of way of fixing it according to the documentation for the PS2 libary (which no longer exists on a website) was by doing some type of pull-up resistor (I am not 100% too sure what this is). I have checked the wiring and its fine. This was the website that I followed that shows the step by step instructions on how to program the controller with the arduino and how to wire it: https://create.arduino.cc/projecthub/electropeak/how-to-interface-ps2-wireless-controller-w-arduino-a0a813. Here is the schematic that I followed for the concept with the pull-up resistor:

I have just tried removing the clock pin from pin 13 (which is already connected up to the clock pin of the PS2 controller).This got rid of the blinking of the dongle blinking directly at the same time as the arduino when restarting the program. The reason why I did this was because it seemed to get rid of the RX blinking issue. Here is a few images that might solve the confusion with the problem.

This is how my dongle is wired up to my arduino :

This is the PS2 dongle. The RX light is what keeps blinking synchronous to the arduino pin 13 light (This is the light that blinks each time you re-compile or restart the program).

This is the LED that I am referring to when I mention the LED on pin 13 of the arduino.
So when pin 13 on the arduino is blinking the RX light on the PS2 dongle is blinking synchronous to it.
The reason that I removed the clock pin from pin 13 on the arduino was because I knew that the pin 13's blinking LED connects up to pin 13 itself (which is wired up to the clock pin on the arduino), this did nothing.
What I am trying to aim to get is that the PS2 dongle

Is for it to be like this and for it to just stay on and NOT blink :
One final thing I forget to mention was that when the LED finished blinking (when restarting). the RX LED on the dongle went off.

You didn't really explain what the problem is, I think. From your text I have to think, that you don't like the receiver stop blinking. Maybe because you really like that blinking. But I don't think, that this is really the issue. Please explain more. Why did you remove the clock pin? SPI needs the clock. You won't get any data through without the clock connected. Of course you can use pullup resistors on the data wires (MISO/MOSI), though I cannot say, if that will help you.

@chrisl To be fair, I do agree with you that I did not explain it well, fair enough. I will send some pictures that show my problems.

@chrisl Ok, I have now updated it.

That gives more context (though the images are very blurry), but still the problem is not clear to me. You say, that you want the RX LED on the dongle to stay on. You didn't state, why you want this. I don't know how the dongle works, thus I don't know, what the RX LED means. From your description, that it blinks sychronous with the clock line (LED on pin 13 of the Arduino) I guess, that it shows receiving data from the Arduino. It cannot stay on, when you don't send data all the time and why would you want that?

You should work on how to focus your camera.  Those images are pretty bad.  I can't make out anything in any of them.  Try to get some in-focus pictures.

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


text:
Passing a time_t array as a function parameter
I'm trying to log reconnections and disconnections of a network. For that I've created 2 time_t arrays to store such occurances:
const int logSize = 10;
time_t conLog[logSize];
time_t disconLog[logSize];

Now, down the road, I have some manipulation and time calculation to do, and for that I wish to pass those log as a variable.
For example - zeroing its values:
void initLog(time_t log[], time_t init_val = 0)
{
        int sizeLog = sizeof(log) / sizeof(log[0]);
        Serial.print("size: ");
        Serial.println(sizeLog);
        for (int i = 0; i < sizeLog; i++)
        {
                log[i] = init_val;
        }
}

in order using it in a simple way : initLog(conLog);
But unfortunately this is wrong.
I've tried to replace time_t log[] with time_t &log - but still no luck.
What do I do wrong ?

you must pass the size as an additional parameter. the size of the array entering the function is unknown at runtime

@Juraj - Meaning that it is ref OK but its size can't be calculated ?

pointer or reference is the beginning address only

@Juraj that I know....

so how would the size be calculated? there is no information about the end address or length. the way you calculate the size works for a specific array when the compiler knows the definition of the array. but array of any length can be passed to this function

@Juraj well I thought there is some kind of a null termination sign. It works - thank you!

for char array that is a convention. for array of pointers you could use a null pointer as mark. here you could choose some time_t value as end mark, but generally all have a meaning.

When you pass an array to a function it "collapses" the array into just a pointer. All the receiving function knows is the type of the contents of the array (time_t) and where it starts in memory - it knows nothing about the size of the array.
The sizeof() call just gives you the size of that pointer, not the size of the memory it points to.
sizeof() is not actually a function, it's a compile-time construct. It can't know anything about runtime values, only what is there at compile time.
Instead you must pass the length of the array with the array as a separate parameter, which can only be calculated in the same scope as where the array is defined, and then only by using the original name of the array.  It is typical to create a macro to do this for you at the time you make the array:
time_t conLog[logSize];
#define CONLOG_SIZE (sizeof(conLog) / sizeof(conLog[0]))

Then pass that to your function:
initLog(conLog, CONLOG_SIZE);

Alternatively, since you already have the size in a constant in this case, you could just use that:
initLog(conLog, logSize);

Good answer, except... If you have a constant logSize that you use to create conLog, why write code to calculate it? Just use logSize directly.

@DuncanC In this instance that is true, but it is seldom the case.

Why? For arrays who's size is defined at compile time, using a compile-time constant to express that size is a good, clean way to do it.

@DuncanC Yes. You know that. I know that. Very few Arduino users know that. You have to remember: these are Arduino users, not programmers.

Some of us are both...

But most aren't. That is why you answer questions and don't ask questions. Just remember to tailor your answers to the level of the audience. If in doubt read up on Wittgenstein's ladder, and "lies to children".

I like your edit, proposing the best option. Why are people downvoting this answer? It is the correct answer.

...Jealousy...?


text:
Cannot read from DS3231
I'm having issues with a DS3231 RTC connected to an ESP8266. I can write to it to set the time (Wire.write returns 1), but anytime I try to read from it, Wire.requestFrom always returns 0.
I've tested my circuit with another DS3231 and it works correctly. So I guess it's faulty hardware and I can throw it to the bin. Or is there something I can do with it?
Update:
In fact, endTransmission returns 2, which if I understand well means the address is not found, so this is not a read issue. I guess that means it's dead.

Wire.write() only places data in the TX buffer. Please check the return value od Wire.endTransmission(), which is doing the actual communication. Have you checked with the I2C Scanner sketch, if the Arduino sees the DS on the Wire bus

@chrisl I hadn't thought of that, thx. See my edits.

Have you tried the I2C scanner sketch? Are you using pullup resistors on the lines?

Yes, I tried it and it finds nothing. I'm using the integrated pullups on the esp8266 (huzzah board). Also, the circuit works correctly if just drop another one in place.


text:
Wave file will not play with Teensy 3.5
I am attempting to play a wav file from an SD card using a Teensy 3.5. I am using this buzzer and I have the following code currently:
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>

// GUItool: begin automatically generated code
AudioPlaySdWav           playSdWav1;     //xy=557,157
AudioOutputPWM           pwm1;           //xy=889,184
AudioConnection          patchCord1(playSdWav1, 0, pwm1, 0);
AudioConnection          patchCord2(playSdWav1, 1, pwm1, 0);
// GUItool: end automatically generated code

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

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println("Play");
  playSdWav1.play("sound.wav");
  delay(100);
  while (playSdWav1.isPlaying()) {
    delay (100);
  }
}

I don't know which pin is supposed to be outputting the PWM signal. I tried searching "patchCord1" to see what the parameters for it are, but was unsuccessful. The code was generated by The Audio System Design Tool.
As for the hardware configuration, I am attempting to wire the I/O pin to various PWM pins (to check for output) with no success. I have GND to Analog Ground and VCC to 3.3V (250 mA max). This is according to this diagram.
Which PIN is the Teensy supposed to output the pulses to?
Edit:
I can get the buzzer to work by using manual PWM (analogWrite), so I know that it functions.

I will edit the question to add a little bit of specifics. But, my question is first, which pin is supposed to be connected to I/O. And second, am I doing this right at all?

The documentation implies you have to combine pins 3 and 4.
Here is a circuit diagram:
https://www.pjrc.com/teensy/gui/img/pwmdualcircuit.jpg

Source:
https://www.pjrc.com/teensy/gui/?info=AudioOutputPWM

After wiring it this way, I still receive no sound. But, I am noticing that the serial monitor is constantly entering "Play." But, it seems it shouldn't do that until the sound has completed? The sound is 5 seconds and it's doing about 10 per second.


text:
BJT - BC547 not working with LED strip
I'm connecting an LED strip that takes 12V input to an Arduino Uno R3's 5V VCC using a B547 transistor.
Here's my circuit:
Base -> 1K ohm resistor -> DO13
Collector -> -ve of LED strip
Emitter -> GND
VCC 5V -> +ve of LED strip

Nothing happens when I try to turn on the LED strip. However if I remove the 1K resistor and turn on the LED, Arduino's built in LED gets dimmer but the LED strip does not turn on.

What am I doing wrong?
TIA!

What kind of LED strip? You can't run a typical 12V LED strip from 5V. Not even slightly.

@Majenko, thanks for the reply. I'm giving 12V current to the Arduino using an adapter. I just got the LED strip to shine dimly. Would it work if I lower the base resistance of the transistor or if I change the VCC to VIN instead of 5V?

Please show a photograph of your actual setup.

@Qumber do not pass the LED supply current through the arduino ... there is a chance that the arduino will act as an expensive fuse

there's a nice circuit diagram tool that will help us diagnose your problem better. Generally though, to switch 12 volts with the Arduino, I would connect 12 v to collector pin, base to arduino IO pin, and emitter to ground. Also you should check if your transistor can handle the power requirement of the LED strip or else it will burn out

I'll definitely make a diagram and share in a bit. :)

BC547 is good for 100 mA only

You have a 12 Volt LED strip and power it with 5V. That could be the reason why the lights shine dimmy.  The transistor is not made for driving big loads. It's collector power dissipation is specified with 500 mW. I would recommend to use a MOSFET and use the 12 Volt Powersupply at the Strips V+ directly.

Connecting the + of the leds strip to VIN will give the strip 12V. Definitely don't connect the 12V adapter to Vcc, or you'll blow up the Arduino. Also, don't remove the 1k resistor, or you'll damage the Arduino's output pin. You can try lowering the value, but don't go below 220 Ohm. Though, unless your led strip is very short, the BC547 isn't going to cut it.

Thank you. I'll replace BC547 with a MOSFET and will try giving the strip its 12 volts from an external source instead of Arduino.

Ok. First off, if you have a 12V LED strip then you have to power it from 12V. Powering the Arduino from 12V and then powering the LED strip from the 5V pin of the Arduino is not powering the LED strip from 12V, it's powering the Arduino from 12V and the LED strip from 5V.
The LED strip's anode (+) must be connected to the + of the 12V supply or, if it's only a very short LED strip then you can use VIN on the Arduino.
LED strips typically have a number of LEDs (eg 3) in series with a resistor to make one "segment", and many "segments" in parallel. This gives a total forward voltage of typically 9V or more - so you must provide at least that to get the LEDs to light.
Secondly the BC547 is not a good transistor to use for switching an LED strip.  It has a maximum continuous collector current of 100mA. That means that you can only have a maximum of 100mA going through your LED strip before the transistor blows.
For reference, 100mA is the equivalent of 5 "normal" (5mm, of the kind you'd use in a breadboard) LEDs at full current and brightness. A typical LED strip (depending on length) can use many hundreds or thousands of mA.
Really you should be using an N-channel MOSFET that is rated for at least as much current as your LED strip requires to run. For safety, and to reduce heat dissipation, you ideally want it to be many times more powerful than the LED strip needs.
A common choice is the IRF530, which is rated at 10A with a switching voltage (the "threshold" voltage) that is low enough for a 5V Arduino to control (there are more suitable ones, but these seem to be the "go-to" component for many Arduino users - they're adequate for most uses).

simulate this circuit – Schematic created using CircuitLab

Thank you so much for the thorough answer. I do understand (a bit) the schematics now. I'll get my hands on the MOSFET, and will try it out as soon as I get home. :)

I gave the strip 12V directly and switched BC547 with a TIP120 and it did work. I'll try a small 12V LED powering up from VIN as well. Thanks for the help. This was my first ever project. :)


text:
How to turn the digital pin to analog pin?
I am using a 10 IR sensor array and they use analog pins. I am using a motor shield for the Uno. So I cannot use the Mega. I have only five analog pins I need 8. How can I do it?

The Mega can take shields made for the Uno.

you have 6 analog input pins A0, A1, A2, A3, A4, A5. some Uno clones with SMD ATmega328p have A6, A7 accessible (maybe Robotdyn)

which sensors are you using? ... how are the sensors connected?

You might like to use a analog multiplexer.

Use an I2C or SPI connected ADC chip.

You can use an external A/D converter, there are a lot of varieties in a lot of price ranges for the Arduino. Check your favorite online source. That will require two of your existing analog pins for the I2C interface but you will gain back many more depending on your choice. If you choose to use SPI that will take 4 pins.


text:
I am getting an error while trying to set up the U8g2 library
I am just trying to set up the U8g2 library to use an OLED. I read through the documentation and tried copying and pasting the code block example for the constructor, but switched out their information for my OLED's information. After trying to verify, the IDE returned this error:
exit status 1
expected ')' before ',' token
#include <SPI.h>
#include <U8g2lib.h>

//Constructor
U8G2_SSD1306_128X64_NONAME_1_SW_I2C(U8G2_R0,A5,A4);```

I saw a similar post about this problem from four years ago, but the only suggestion on there was to capitalize the "A" in the analog pins. I tried this and nothing changed. Any help would be much appreciated!

are there the correct number of arguments in the constructor?

According to the website, it takes in the rotation, clock, and data. It also has [, reset] listed, but I don't have a pin for that. https://github.com/olikraus/u8g2/wiki/u8g2setupcpp

i think that you are missing the object name U8G2_SSD1306_128X64_NONAME_1_SW_I2C abc123(U8G2_R0,A5,A4);

I figured out what I was doing wrong. I was copying the name from the Constructor Reference and immediately inputting the arguments in parentheses. I needed to put u8g2 after the constructor name and then put the arguments. Thanks!
The corrected code is as follows:
#include <Arduino.h>
#include <SPI.h>
#include <U8g2lib.h>

//Constructor
U8G2_SSD1306_128X64_NONAME_1_SW_I2C u8g2(U8G2_R0,A5,A4);

It doesn't have to be "u8g2".  You could name your instance Fred or Jim or Bob for all the compiler cares.  But you do have to give it a name.


text:
8266 analogRead(A0) always 1024
dear member.
I have 4 ESP-12 averything OK but one chip behave weird.
always return 1024 on analogRead(A0);
once use ADC_MODE(ADC_VCC) and reflash using ADC_MODE(ADC_TOUT); and never back to normal, is my Chip Error..?
FM 4MB
ArduinoIDE 1.8.13
BR 115200
PS 80MHz
int iVal = 0;
void setup() {
  Serial.begin(115200);
  delay(999);
  pinMode(A0,INPUT) ;
  pinMode(LED_BUILTIN, OUTPUT);
}

// the loop routine runs over and over again forever:
void loop() {
  iVal=analogRead(A0);
  Serial.println(iVal);

  if (iVal > 900) digitalWrite(LED_BUILTIN,HIGH);
  else   digitalWrite(LED_BUILTIN,LOW);
  delay(720);
}

ADC_MODE(ADC_TOUT); still return 1024 on analogRead(A0); while other 3 Chip just fine

If 4 devices are working correctly, but 1 device not, with the very same program, there seems to be a hardware difference. Check for short circuits, open wires, bad soldering, and so on. You might even have a defective device.

Sounds to me like the ADC has been overpowered and the ESD protection diode has failed short.

@Majenko so, should i let it go? you are right. once, i was powering switch accident between vcc and ground about 2 minute. is it problem?
and how to accept your comment as solved?

First be sure your voltage on the analog input is less then 1V and greater then zero, that is the range for the input. If nothing connected no guarantee what you will get. Just guessing, no circuit or definition.

I have voltage devider, also multimeter test trying to measure 0,6 volt still return 1024. also 0,8 Volt input and measuring after Voltage devider get 0,2Volt still return 1024.

I assume you are saying you get 0.6V reading on the pin with a multimeter, if so consider the unit toast. Probably good for digital usage but for A/D you need another board.  The only real test is to try another board or add an external A/D.

agree with you @Gil, i was order ather board, let this one go, or use without ADC. seem my board ADC has been overpowered.. because weird on testing: ADC pin floating(no conection) measure with voltmeter always 2,8Volt

Actually you did a good job and most of the work.  These things are very hard to diagnose unless it is on the lab bench in front of you.


text:
How are the different sleep modes used for esp8266?
I am currently trying to power my esp8266 with a battery, but I want to decrease the power consumption (current mostly). I understand there are different sleep modes, but I do not understand what can I use for each sleep mode. I want to know what functions are still enabled during each sleep mode.
Example: Can I use ADC pins in modem sleep?
My biggest question:
I am sending beacon frames to my phone, I want to know if I can use one of these sleep modes while sending my beacons at the same time? Do I need my CPU or do I need my Clock to send frames?


text:
Make the Arduino read data from the PC
I will be brief. There is as windows PC running a program. This program has live updating data on it. Without modifying the PC or adding any programs to the PC, is it possible to program an Arduino to read specific data from this program. In other words the Arduino would be connected to the PC via a USB port and it would need to actively read specific data from this program without having to modify the PC in any way, software or otherwise. I do have access to the PC and can learn almost anything I need to about the program during the development of this system, however in practice, I need the Arduino to simply be plugged into this PC and begin reading its data. Is this possible?  I am not asking for a tutorial however if you could point me in the right direction that would be great.
Thanks

No.  That's not possible.  The Arduino can only receive serial data from the PC over the USB.  Unless there is some program sending the information out on the serial port then Arduino has no access to it.

why would anyone want to use a PC that is so unsecure that it does not even need to be hacked to spill its data

Add a camera to an Arduino, point it at the screen, and have it take a picture. Then use OCR to convert portions of the image to text. Oh, and upgrade your Arduino to a Raspberry Pi so it's physically capable of such actions.

Study the USB stack of your Windows machine. Search for vulnerabilities. Once you find a security hole, program an exploit that lets the Arduino breach into it.

Thanks for the info

@Majenko♦ has given me an idea ... program the arduino to emulate a serial port and a keyboard ... when plugged into the PC, the arduino sends the necessary keystrokes to dump the data to the PC serial port ... of course the difficulty lies in getting the running program data to the serial port on the PC side ... maybe copy and paste

Haha that's not a bad idea

As the comments already stated: No, not possible. For multiple reasons:

USB is a master/slave protocol. The slave (here the Arduino) cannot do anything without the master. It can just expose it's data endpoints and hold data ready to read at these endpoints for the master or wait for data from the master on these endpoints. When the application on the PC is not programmed to speak over USB, you cannot get the data over USB.

Even directly on the PC you cannot simply extract data from a different program. That would be a very huge security risk. Even more, when just initiated via an USB device. There are USB devices, which use certain behaviors of some OS's (like auto execution of specific types) to install a virus on the PC. But even then you cannot "just read" the data. It would be way more elaborate and not possible with a simple Arduino, thus off topic here. (And you might frown upon hacking your own PC this way)

From our point of view (means leaving the hacking off limits), I would aggree with Majenko in the comments. Using the visual output is the most viable and easy solution, though your results might vary.
For that you would need a camera pointing at the screen (check if you get a good image. It might be distorted due to slow refreshing...) and use a Raspberry Pi or similar to connect it. On the Pi you can then take pictures of the screen and use an OCR tool, which will read the text from the image. Then you need to extract and structure the relevant information. (Maybe it will be easier to create subimages in your program and let the OCR tool run over these to distiguish between the different data parts). Results will hardly depend on the quality of the image. If you can live with an additional program running the PC, you could instead make the images of the screen as screenshots, which will be way better quality. Though at that point you can also put the rest of the logic on the PC and just remove the Pi.
This way will still be hard to do for a beginner, but possible.

Thanks for the response

OCR seems really cumbersome, it is way easier to just write a pc program that connects over the network to your arduino or even send the files over your custom serial protocol.

@Ananashoi Though that still doesn't include how to get the data from the program. Often such programs don't have a "stream all data to this location" option. Sometimes they can export a fixed data set, though that export again needs to be triggered. That part really depends on the program and we don't know anything about it currently.


text:
how to ignore a sensor being tripped the first time and start recording millis on the 2nd time it is tripped
I am building a timing system that has a start, split and finish beams with this I am using a start gate that will drop when the race starts. when it drops it will trip the 1st sensor starting to count the millis which I am using to calculate the time. I am using IR sensors to that give me the 3 times based on the millis and then I do a calculation in excel that will give me the split and finish time.
Where I am running into issues is that after the person goes through the 3 timer sensors I have to close the start gate which trips the first sensor which messes up my times for the next person.
So I need to adjust my sketch so it takes this into consideration when it starts counting the millis. Basically I am thinking it needs a line of code to have the 1st sensor == LOW once and do nothing and then on the 2nd time that same sensor is == LOW it records the millis from that point.
Below is the sketch I am working on.
//timer
unsigned long start, reaction, push, elapsed;

void setup()
{
  Serial.begin(115200);
  pinMode(2, INPUT); // start switch
  pinMode(3, INPUT); // split sensor
  pinMode(4, INPUT); // finish sensor
}

void loop(){

if (digitalRead(2) == LOW)
  {

    start = millis();

  }

  if (digitalRead(3) == HIGH)
  {

    reaction = millis();
 //   delay(200); // for debounce

  }

     if (digitalRead(4)==HIGH)
      {

       push=millis();
       delay(500); // for debounce

    Serial.print(start);
    Serial.print(",");
    Serial.print(reaction);
    Serial.print(",");
    Serial.print(push);
    Serial.println();

  }

}

Are you sure it really messes up the timing of the next person? When you reset the start gates, you code sets start to the current time. But then you you actually start the next race, you code overwrites start with the correct value. As long as you reset the gate after the last sensor is triggers (which actually prints out the times), you're fine, as far as I can see.

So what is happening is if when testing it out (just using my hand to break the beams) if I do it quickly it seems like I get a good result. but if I put the finish sensor far away from the split it gives me after calculations a number on the 1st time that is WAY too high when it should be the opposite.

So for example I get a start milli of 27083 split of 28657 finish of 29214. when I do the math to get m/s it turns out to be 1.574 from start to the split and .557 from the split to the finish...... I am not sure if this is a problem with my code or if it is a problem with my math?

Those millisecond values don't look odd to me, assuming the car is accelerating. I think you are calculating s/m not m/s. You should divide the distance (which I assume is 1m) by the number of seconds (which is 0.1574 and 0.557). Then you get an average of 0.64m/s in the first section. And an average of 1.8m/s in the second section.

The start time will default to zero, so you could change it to:
if (digitalRead(2) == LOW && start == 0)
  {

    start = millis();

  }

You could also declare start as a static in the loop: static long start = millis();. That way it gets called only the first time, and will remember the var in the rest of the loop()

with changing the sketch line to "if (digitalRead(2) == LOW && start == 0)" it seems that the first millis is always the same value as the first time it was tripped but the other sensors record what looks to be correct numbers.

I am thinking it needs a line of code to have the 1st sensor == LOW once and do nothing - that's what my suggestion does. If you want it to "reset" then you need more code. I'm not quite sure what your parameters are. How do you know you are starting a new race?


text:
Why do we declare constant lat and lon value
static const double LONDON_LAT = 51.508131, LONDON_LON = -0.128002;
What does this mean?
https://github.com/mikalhart/TinyGPSPlus/blob/master/examples/FullExample/FullExample.ino
The above link contains the full example program of that line.
This line is from tinygps++ library for extracting the coordinates and displaying in a table format. I'm using arduino uno, GSM module and GPS module to extract the coordinates and transmit it as message. Can anyone explain what dies this constant value mean and why do we use this?

Unlike in movies, I hardly think London will ever move.

This constant value is there at tinygps++ full example program and I don't know about this constant value? Do you know any exact answer? Also what type of algorithm is used here for the entire program. I'm new to arduino and so I just wish to have a knowledge of it. Is there any specific algorithm being used to extract the exact gps coordinates using gps module and arduino?

These are the GPS coordinates of London. If you want to know the exact location google the coordinates. In your comment you have more questions about an example program, but you never included the program in your question, nor did you link to it. How should we answer your question? We don't know, what sketch you are talking about, so we cannot know, how this one line ties into the rest of the program

We declare those because the program in which they are declared wants to use that information in some way. Without knowing what the program is we can't say why it might want to know that information. Maybe it wants to work out how far from London you are.

https://github.com/mikalhart/TinyGPSPlus/blob/master/examples/FullExample/FullExample.ino

This link contains the full program. Sorry to attach the link, since the program to too lengthy.

I'm currently working on a project, where the my location coordinates is to be sended as message using GSM module. The GPS coordinates are extracted using gps module. These are connected to arduino uno board. Tinygps and tinygps++ library is being used for this project. This program is an full example program which is default in tinygps++ library

Please add all this information and questions to the text of your original question, not in the comments. They are temporary and please should not need to read the full comment stream to get the needed information.

If you want us to give you a detailed explanation of every single line of code of the program you are linking to, you are in the wrong place. This site is for specific, well-targeted questions. If you do did study that program and have a specific question, then ask, and include the relevant bits in the question itself. See How do I ask a good question?.

I was actually asking for a particular line, which was mentioned 1st. static const double LONDON_LAT = 51.508131, LONDON_LON = -0.128002;

@Kwasmich lol ... that is example code ... it is written using proper programming convention... it needs to be clear so that most people would immediately know what to do to modify the code for their needs ... using descriptive names of variables makes the code easier to read, and the code requires less comments ... if the constants were used directly then the OP would probably be asking what is this 51.508131?

@tharrunkumar imagine that you are writing a program that calculates the circumference and the area of a circle from an input of a radius parameter .... which would be clearer to read? ... c = r * 2 * 3.14159 a = r ^ 2 * 3.1459 ... or ... pi = 3.14159 circ = 2 * radius * pi area = radius ^ 2 * pi

Static variables are allocated storage only once in a program lifetime
The const keyword specifies that a variable's value is constant and tells the compiler to prevent the programmer from modifying it and you can't change const variable's value
and i guess you know double is a data type that can save floating point numbers
that line declare two variables with names LONDON_LAT and LONDON_LON and both of them are in one line
and because london's latitiude and longtitude doesn't change the const keyword is used
also i guess because those variables are constants you can use #define visit https://www.arduino.cc/reference/en/language/structure/further-syntax/define/

It's a good idea to declare variables the strictest possible way. So if you don't intend to change the value of LONDON_LAT at runtime, declare it as const.
This allows the compiler to alert you if your code tries to modify it, and it often allows the compiler to optimize the code.


text:
Noise in Analog Read Serial from an instrumentation amplifier(ina122p)
I am trying to read the values from a simple EMG circuit (with an INA122P) using the analogRead() and plotting in the plotter using an Arduino nano v3. I am powering the ina1222p from the 5v pin of the Arduino. But no matter what I do, the signal comes out very noisy most of the time(i can rarely make out the EMG). The bandpass filter is also not really helping. I am using regular solid core wire and alligator clips to connect to the electrodes.
Can someone please tell me what I am doing wrong? or tell me how to make a simple EMG circuit that uses the Arduino's analogRead().
I am also getting ac sine waves when my laptop is plugged to power, so I tried removing the power. The distinguishable sine wave wasn't really showing up, but it was still just as noisy...
I am a beginner to both Arduinos and designing Analog circuits.

I found this design from here: https://greenhecktech.wordpress.com/2016/09/19/improving-the-emg-amplifier/

If you could provide a schematic that would really help! One thing you might quickly be able to try is running from a powerbank. You also want to make sure you decouple the power rails of the INA122P with (preferably both) a 10nF and a 100nF capacitor.

@Ananas_hoi a powerbank could have an electrically noisy buck converter ... try to run from a battery directly

You are right. Furthermore, soldering the connections would be desirable over a using a breadboard. It might also help to keep the connections short and isolate wires from noise with some simple aluminium foil shielding.
Since it's a dual input amp, consider looking at this: https://toshiba.semicon-storage.com/us/semiconductor/knowledge/faq/linear_opamp/what-is-the-purpose-of-using-a-differential-amplifier.html
Without schematics I cannot help any further.

"noisy most of the time" - good news: if it's not all the time, that's a sign it can be fixed.
"bandpass filter is also not really helping" - INA122P circuit likely has something wrong.  check any resistors involved. Edit: if this was about U2.2, see below as that doesn't look like a band pass...
"regular solid core wire and alligator clips to connect to the electrodes" -
basically 0 shielding with mini-rabbit ears at each end and a big loop area between the wires.
Eventually you will want something better than gator clips.
My main recommendation is that as far as wire goes, if you form twisted pairs they tend to be pretty darn good at rejecting noise at least for that part of the wire.  You will want to twist a signal along with its reference (such as a +V and a ground).
Some explanation of the circuit:
U2.1 is creating a 2.5V source that it uses as the reference 'ground' for U1.  Reason for this is to treat 0 as "-2.5" and 5 as "2.5" as op amp math is generally done on a +V, -V basis.  (Personally, I prefer to use voltage regulators to make power buses instead of this. As a result, I give a stink eye to circuits that use the op amp method and claim something about reducing part count.)
U2.2 is a capacitor shy of an active band pass.  It's a high pass filter that is helping preserve and even promote some of the high frequency noise you are picking up. So yes, you may wish to modify or even ditch it until you have high frequency noise under control.
If possible, you may also wish to look into operating at a higher voltage.  This can help improve your signal to noise ratio.  If your signal is essentially +/-2.5V, 250mV of noise would be 10:1, but if you can run at +/-5 V, that same 250mV noise contribution gets dwarfed 20:1.

i'll try using a higher voltage as you suggested. I have a question...why does this circuit use an opamp to provide a reference voltage?, i've seen other circuits use just the resistor network(r2, r3) to do that... what benifits does the opamp provide?

op amp or voltage regulator can provide current without voltage drop.  The resistor voltage divider voltage changes as you draw current because another "resistor" path is added to ground, making the equivalent resistance change.

Ah, I got it, thanks~


text:
Multi MFRC522 Slave AND only mifare read
Multiple MFRC522 Connections (https://learn.sparkfun.com/tutorials/serial-peripheral-interface-spi)
I only get from each slave with an ID card; I want to print a defined barcode on the slave address. Briefly; The MOSI line does not matter! Is the 2nd case daisy chain method in this link suitable for me? would like to ask you, dear friends, how should I go about it?
<Regards

what is ID card?

There is only one daisy chained example shown in the article. ;-) Do you know, that the slaves that are chained, must be able to transport the incomming (MOSI) data to the outgoing port (MISO). This is not the case for all slave devices. I do not think the MFRC522 allows this mode. Why not use the multi slave setup from the example before the daisy chain example? Then you will also be able to select the slave you want to read from.

Tomorrow, I will install 7 mfrc522.  SS pin (SDA) will not be enough.  Is it necessary to use the 74HC238?  I guess I should also connect pull-up (10k) to SDA and SCK wires .. I read the problem of impedance .. I will have a particular question;  Where do I get the name or code of the slave device.  Thanks for your answer

evet. geç oldu cevabım özür dilerim. Normal Seçici SS leri ayrı ayrı kullanarak sorunu çözdüm. Burada max. kaç adet bağlanır bilmiyorum. Ama; 5 adet şimdilik işimi görür gibi.


text:
ESP-01 wakes up from deep sleep and then hangs
I have found a number of other posts from people with the same problem but I can't find an answer.
I have a small batch of ESP-01 boards, sold by Inland, and I wish to use deep sleep mode on them.
I soldered a small copper wire from pin 8 (i.e. GPIO 16) to RST.  On one board I soldered it directly, on another I soldered pin 8 and RST to two sides of a 2 pin header so I could use  jumper in case I wanted to disconnet GPIO 16 from RST.
I am flashing the following simple code (using Arduino IDE 1.8.12), which is about the simplest test of the deep sleep mode that I can think of.
void setup()
{
   Serial.begin(74880);
   Serial.setTimeout(2000);

   while(!Serial) { }

   Serial.println(
     "I'm awake, but I'm going into deep sleep mode for 15 seconds");

   ESP.deepSleep(15e6);
}

void loop() {
}

On starting the serial monitor shows
ets Jan  8 2013,rst cause:2, boot mode:(3,6)

load 0x4010f000, len 3664, room 16
tail 0
chksum 0xee
csum 0xee
v39c79d9b
~ld
I'm awake, but I'm going into deep sleep mode for 15 seconds

After 15 seconds the serial monitor shows
ets Jan  8 2013,rst cause:2, boot mode:(3,6)

and nothing else. After that the thing hangs and nothing further happens.
So,  it appears that the setup runs, the serial monitor prints the message, the mc goes into deep sleep, after 15 seconds it wakes up by a reset, but doesn't go through set up again, hence doesn't print the message or go back sleep.
Here are some comments.    The problem has nothing to do with Wifi, MQTT etc, I have tried many fancy sketches using all of these, I have same problem no matter what, the above sketched is my distillation to the simplest demonstration of the deep sleep problem.
I have flashed the program with Arduino IDE, Platform IO, and esptool.py from a command line.  It doesn't make a difference.
There may be a problem with my soldering job, but I'm pretty good at soldering and SMD rework, and I have repeated the job on a number of these ESP-01 modules, inspected and tested with multimeter, etc.  all with the same outcome.
I don't see a problem with my code or IDE, I have a batch of Lolin Nodemcu boards, and this sketch works perfectly on all of those.  In that case I simply connect GPIO 16 to RST with a jumper wire, the program prints the message, sleeps for 15s, wakes up, prints it again, goes back to sleep for 15s more, etc. etc.
Are these just bad boards?  I have read some things that say the flash chips might be lousy, and if I replace those it might help? I'm tempted to trash these boards and buy some D1 mini's, but I've seen a number of posts from people who say they've had the same problem with D1 minis.   If the board is the problem, are there any recommendations for manufacturers or vendors that sell better quality?

Do you happened to have anything connect to reset pin, for example, from the USB-TTL serial adaptor? 2) Try to use CH_PD instead of RESET pin to see if it works? For CH_PD, it will depends on whether you have ESP-01 or ESP-01S (which already has a pull resistor on CH_PD).

while(!Serial) { } does nothing on esp. why do you have Serial.setTimeout(2000);? let the esp start completely before going to sleep. I guess it is still in process of autoconnecting to last remembered AP.

@hcheung The board is an ESP-01, not an ESP-01S. I'm programming it with a simple USB-TTL flasher also sold by Inland, plugged into the USB port of my Macbook.   When the board is plugged into the flasher the RST pin is pulled up to 3v3 by a 12K resistor.   So I should try connecting GPIO 16 or CH_PD instead of RST and see what happens?

@Juraj Good question! I"m not sure, I copied the code since I'm not quite sure what I'm doing. I commented out the lines with while(!Serial)... and Serial.setTimout.... and the result didn't change. As I mentioned, I can run the exact same sketch on several ESP8266 Nodemcu boards and it works fine, so I figured the problem wasn't with the software.

I need to amend one thing:  I said "after 15 seconds it wakes up by a reset, but ....". This isn't totally clear.   As an experiment, I ran the sketch on a nodemcu board (where it works perfectly), but I did NOT connect GPIO 16 to RST with the jumper.   The result is exactly the same it goes to sleep, then after 15 seconds prints ets Jan  8 2013,rst cause:2, boot mode:(3,6), and nothing else, and then hangs.  In other words the ESP-01 board is behaving exactly as if GPIO 16 is NOT connected to RST.

on esp-01 io 16 is not connected to reset

@juraj I'm not sure what you mean.  Do you mean that GPIO 16 is not connected by default to reset on the ESP-01 board, or do you mean that it shouldn't be connected? It clearly is not connected by default.   According to the ESP8266 data sheet GPIO 16 needs to be connected to reset in order to enable wake up from deep sleep. My objective is to get the chip to wake up from deep sleep.

it is not connected. you can wire it if you can solder to the chip's leg. it must be connected to reset out from deep-sleep. it is a workaround for an error in the basic bootloader of the esp8266. this bootloader can't be updated and it hangs on internal wake-up.

@juraj That makes sense that it's a workaround for an error. You would think when the chip was first being designed that it could have been made to wake up from deep sleep without having to make an external connection.

Not necessarily an answer, but something to look at: check the Manufacturer ID of the Flash on your board.  My suspicion is that when some Flash chips come out of suspend, they're in lower drive mode than on initial power-up.  At least one person fixed his 'zombie mode' by replacing the Flash with a different vendor.  Nobody else has attempted it yet.
I have an Inland ESP-01S that's reporting MID = 0x5E (supposedly Zbit) and it comes out of Deep Sleep repeatedly.  Here's all of the Manufacturer IDs I know of or have seen:
Winbond EF
GigaDevice C8
Puya 85
Bright Moon 53
BergMicro E0
XMC 20
XTX 0B
Eon 1C
Shanghai Fundan A1
Macronix C2
Hua Hong Zhixin 68
ISSI 9D
Paragon E0 (same as Berg - oopsie or clone?)
Zbit 5E
Zetta BA
esptool.py --port /dev/ttyUSB0 flash_id   (linux)
esptool.py -p COMx flash_id    (Windoze)
Note: the cheap D1 Mini boards with no-name ESP-12F modules flooding eBay, Aliexpress and other places report XTX Flash, and they have a 5.6K pull-up on EXT_RSTB which will shorten the RST pulse from GPIO16, as well as making it hard to hit the level to be detected as a LOW due to the series 470 ohm resistor.  We're unsure whether it's the Flash or the low value pull-up (typically 10 or 12K on other boards/modules) that's causing issues with those boards.  Normally if RST isn't seen as LOW after Deep Sleep then you'll get an "ets_main.c" message at boot before it hangs.
I have a clone D1 Mini Pro that has a Flash that reports MID = EF (Winbond), although the marking on the Flash is nothing I can find on Winbond's site, only on places selling cheap Flash.  Luckily the D1 Mini Pro also exits Deep Sleep successfully.

I have come to the conclusion that these boards are bad.    I wrote a simple sketch that turns an LED on for 3 seconds, then goes into deep sleep for 12 seconds, then wakes up.   I have a batch of 3 Lolin ESP8266 nodemcu boards and the sketch works fine on all of them.   The LED goes on for 3s, then goes off for 12s, then goes back on, etc. Furthermore using an ammeter I measure a current draw of around 80 mA while the LED is on, and around 4 mA while it's off, repeatedly.
However --- I have another batch of five ESP-01 boards.   I soldered a fine copper wire to GPIO 16 and to the reset pin, used the same code, same set up, power supply, LED, etc.
The light goes on for 3s then goes off for 12s,  then comes back on and stays on and then there is no further change.  Furthermore, the current draw during the first 3s is around 80 mA, but when the light comes back on and the controller hangs, the current draw is around 40mA.
Incidentally, I tested the nodemcu boards,the ones that work fine, with this sketch but disconnecting the jumper from GPIO 16 or RST, and it behaves exactly the same as the ESP-01 boards, including the 40mA current draw in  the zombie state.   So it would appear that the problem on the ESP-01 boards is that the GPIO 16 pin is just not connected to RST.  However I have soldered all five of these things multiple times, and I have become pretty darned proficient at soldering that little pin, and I am 99.999999% sure that I have the wire soldered to the pin, with no bridges, didn't fry anything, etc.

I was wrong: I have an Inland ESP-01.  The package was marked ESP-01S...  Yep, I got screwed.  There's no pull-up resistor on EN, GPIO0 or GPIO2, and GPIO15 is shorted to GND on the board which is generally a Bad Idea with a GPIO.  Looks like a 12K resistor to 3V3 and possibly a .1uF cap on RST.  It works OK with Deep Sleep as long as it's in that USB converter board, I'd have to attach the program mode resistors to get it to run free-floating.  Here's a photo of what Inland is selling marked as "ESP-01S": https://i.imgur.com/2OFr8r9.jpg  Yeah, NOT!  Don't buy it if you're expecting ESP-01S.


text:
Output voltage range between 0-5v
I am using arduino Uno/Mega.
I am trying to output a range of 0-5v volts using PWM.
Is it possible to do it?
It’s would be nice to see some code or instructions, as far I have seen, they used external Module to get that voltage range, maybe I am wrong or I didn’t understand them well.
Thanks!

If you want a steady stable voltage at that level then no it isn't possible without external circuitry.  If you just want PWM that averages at that level then check out the doc page for analogWrite on the arduino.cc website.  It's basic stuff.  Definitely not secret or hard to find.

just send it through a 2-stage low pass RC filter, then send the output to a unity gain opamp buffer, then send that through a series-pass voltage follower transistor if needed.

Short answer: No.
Arduino Unos and Megas have PWM (Pulse Width Modulation) output, which rapidly turn the output on and off with a varying "duty cycle" (The ratio of on time to off time.) That is not the same thing as an analog output voltage.
If you have a constant load you can build a low pass filter that will smooth the output to a slightly dirty DC output based on the PWM output.
You're better off using an external DAC (Digital to Analog Converter.) You send that a digital value and it converts it to a clean, filtered analog output. Most modern DACs are fast enough to output complex waveforms like music.
Edit:
The Arduino zero apparently has a built-in DAC with up to 10-bit resolution. you could use that to output a low current DC voltage. However the zero is a 3.3V device.

The Arduino is a digital device; each output pin is either HIGH (+5v) or LOW (0v = GND), not in between.
For certain types of devices (motors, LEDs) there is a technique you mentioned called PWM, pulse width modulation, which turns the output on and off rapidly. It's still just a square wave alternating between 0 and 5v but it's doing it really fast. So for an LED for example, your eye will make you think it's at half-brightness even though it is flashing on and off very quickly.
To do this you need to use a pin that has "analog" ability and use the "analogWrite" command.


text:
Why must I reload ArduinoCreateAgent-1.1-windows-installer-chrome every time I restart my computer?
What am I missing that this is happening?
Used to use a laptop (with Create Agent installed on hard drive) which never had this problem.
Now using a Windows 10 desktop and the On-line Create Agent.
Unless I reload the Arduino Create Agent, I always get the 'No Plug-In Connection' error message, please see screen capture.  Device manager recognizes the Arduino Uno and assigns COM3 to the USB connection, please see screen capture.

what do you mean by reload the Arduino Create Agent ... do you mean that you have to refresh the webpage?

@jsotola, Agent is the locally installed part of the Web IDE. the installation sets it to start automatically at logon. it looks like this failed

Yes, I mean that I have to refresh the Arduino Create Editor each time the computer is rebooted.  Logging onto the computer or into the Arduino WEB IDE does not automatically refresh the Create Agent.  What would cause this to fail the refresh? How can I correct this issue? I am pretty computer savvy but this one is escaping me!

Thank you to all who have suggested corrective action for my posted communication problem.  After trying all of the suggestions, I threw up my hands and deleted all evidence of Arduino Create Editor.  Next I installed the Arduino Create Editor as a fresh/new install.  Magically, all of my communication issues with the Arduino Uno have been corrected.  Apparently, something in the communication code was corrupted during my first attempt install on my desktop PC.


text:
Sketch is not being received by Arduino even though Arduino Editor acts like it is finished?
In my attached screen capture the Arduino Editor appears to be performing the upload, however it never finishes. Completes three steps, the last being the sketch up-load and then states that it is busy.  Sorry that I can't submit a short video. Please suggest ideas to solve this issue.  Maybe this is related to my first question?

there is no attempt to upload. it looks like Verify command, not Upload

Thank you to all who have suggested corrective action for my posted communication problem. After trying all of the suggestions, I threw up my hands and deleted all evidence of Arduino Create Editor. Next I installed the Arduino Create Editor as a fresh/new install. Magically, all of my communication issues with the Arduino Uno have been corrected. Apparently, something in the communication code was corrupted during my first attempt install on my desktop PC.

I would suggest you start with a simple blink example sketch and be sure it works. I believe it will. Your picture is almost impossible to read but i caught you have multiple libraries and several other problems. Look at the errors and resolve them one at a time. Until you do it will never load, that is the way it was designed. Be SURE there is only one file with the .ino extension unless it is also part of your sketch.

the screenshot shows successful compilation. so what about is this 'answer'?

I would suggest downloading the Arduino IDE and try that, it works great on linux mint. As far as the Amazon thing you might contact them for help. From what I can see it does not do the upload. The reason for the suggestion is to eliminate as many unknowns as possible.

the Amazon thing is the official Arduino Web IDE by Arduino. it is hosted on Amazon cloud


text:
How to count number of bytes appearing in the Arduino serial?
I need to count the number of bytes appearing in the serial (UART bus) bus, how to count bytes in Arduino with Arduino Serial functions? is this possible?
Application -
RS485 communication with multiple boards without slave ID
slave boards will send data to the master board when,
1st 10 bytes = masters send a 10byte message to all slaves
slaves listening to the bus always until it is the turn to send the data
when byte count is 10, slave 1 sends data 5 bytes to master
when byte count is 15 (10+5), slave 2 sends data 5 bytes to master
when byte count is 20 (15+5), slave 3 sends data 5 bytes to master
max count is 25 known value

if (Serial.available() > 0) { incoming[byteCount] = Serial.read(); byteCount++; } where byteCount counts the number of bytes received and incoming[..]  stores the received bytes, or something like that? Looks like a protocol that's not very fault-tolerant.

@StarCat I am trying to achieve maximum data throughput. 1st master initiates the bus 10-byte message, all slaves listing to the bus, then slaves sending data when its turn comes. so I can reduce waste time on request response time, I have 20 slaves. maybe each slave send some checksum at last of each slaves data packet where the master can decode once data received

Counting is easy, the hard part is knowing when to reset the count.  Assume you will sometimes get out of sync.

@Chris Stratton what did you mean? reset count? i can reset each slave ones the data is sent right? other slaves will wait until there turn

You need to have a reliable, recoverable way to know when to start counting.   Assume the system will occasionally become mis-synchronized for one reason or another, you need to have a design which is self correcting and can get all of the nodes back on board and counting the next cycle together.

Serial.available() returns the number of bytes available for reading in the buffer.
int nBytes=Serial.available();
if (nBytes > x) {
............
............
............
}

Welcome to Arduino:SE.  Just an observation: answers posted here should be written in English.


text:
send configuration commands with arduino
I am using ublox zed F9P multi GNSS module. I have to program it for its configuration messages. Like I have to run a specific configuration of my receiver with the help of Arduino. I know arduino parse the GNSS sentences but can anyone tell me how to write code for ublox configuration commands such that that command can change setting of the receiver upon burning it in Arduino. Also, that code should retain in the receiver even if arduino is disconnected (closing arduino IDE console). Please help

you write the code using the Arduino IDE

yes code will be written in arduino IDE.

You would send the commands over the same serial channel that you read the data from.

can you give some example of sending these hex bites into Arduino? It will help me

Here you find a standard library from arduino.
https://www.arduino.cc/reference/en/libraries/sparkfun-ublox-arduino-library/
You can find the documentation here:
https://github.com/sparkfun/SparkFun_Ublox_Arduino_Library


text:
Can I use arduino pro micro rx tx as digital pins
I'm using arduino pro micro Atmega32u4 5v 16Mhz
I want to use it to make a HID Keyboard and Mouse but I ran out of pins so I was wondering if I can use the RX and TX pins as digital input pins. Will it work? Will it affect the communication of the arduino  to the computer?

Should be fine. Communication is done natively in USB with the ATmega32u4, TX and RX (D0, D1) are free for other tasks.

RX/TX pins on Micro are Serial1

Not a problem on the Pro Micro. You tag also mentions Pro Mini. On those it could be a problem. If your code doesn't use Serial, then there is no problem there. But there could still be a problem during uploading the code. If for example a button is connected to either pin, and this button is pressed, it could block uploading, and could even cause a short if the other side of the button is directly connected to Vcc or GND.

Using TX and RX on a 32U4 does not affect PC communication. It uses a competent different communication channel.
You can use those pins for digital operation with no problems, you just won't be able to use Serial1 for communication with serial peripherals.

Welcome to ASE.

Communication between the PC and the Arduino Pro Micro happens through the USB, unlike the Arduino Uno and Mega, which use the RX and TX lines.
In your case, the USB pins of the Micro are used to communicate with the PC. Hence, the RX and TX pins are available for digital input and output operations.


text:
ESP32 softAP SSID not const
I would like to be able to set the wifi SSID in the setup(), so I can customize it based on the MAC address or something similar. (avoiding to ESP's with the same code having the same SSID). However since it requires a const it does not seem to be possible, or am I missing something?
I'm using platformIO if that matters...

const parameter says the function will not change the string. it doesn't require it to be const

dont't use platformIO if that matters... :)

@DataFiddler why is that? I love PlatformIO in vscode, it does wonders for me!

Sorry @Ananas_hoi, just a (funny?) response to I'm using platformIO if that matters... I don't know PlatformIO enough, but I'm pretty sure the if condition will not apply.

A const parameter to a function doesn't define what can be passed. It is, instead, a "promise" by the function that it will not modify the data you pass it.
In C when you pass a "string" (which is actually an array of characters) to a function you don't actually pass the string (as in the content). You really just pass a pointer to the location in memory where the string is stored.
It is perfectly possible for a function to then make modifications to that passed "string", which will be modifying the original data in memory. That is not really desirable in many situations.
So by flagging the parameter as const you tell the compiler "From this moment onwards the data pointed to by this variable must not be changed". All attempts to write to the memory using that variable will be blocked by the compiler.
There's no actual difference between, say, a char * and a const char * other than how the compiler treats attempts to write to them.
When you pass a char * to a function that is expecting a const char * the pointer is "upgraded" to a constant so that no attempts to change the data will be allowed.
The converse is not allowed though - you can't (or shouldn't) try and convert a const char * to a char * as on some systems ("Princeton" architecture systems with a single monolithic memory address space) the pointer could be pointing to data stored in flash, and an attempt to write to that will obviously fail.
The function you are calling to set the SSID is merely promising that it won't attempt to change the data you pass it. It doesn't matter if it's a constant or not - both will be treated as a constant and not be changed.

The library WifiManager might work for you, it’s got a captive portal to configure your wifi connection on the fly. It’s got quite some configuration options to shape it to your will if I am not mistaken, I hope it serves you well.


text:
ATTINY85 and POT
I need to read a potentiometer value from an ATTINY85.
I have big fat 10K POT but for this use case I need it to be very small so I used a salvaged 2.4K one, the kind that is soldered directly onto a PCB.
I am using tinkercad to prototype my project and I am facing a very weird problem. Everytime I read from the POT Pin, I get the value of 512 (using the debugger)
Here is a screenshot of my prototype:

The goal is to power the circuit and the lamp (does not matter what is there, consider it just a load) with a 9V battery, use a 5V regulator to power the ATTINY85 and use an NPN transistor to turn the lamp/load on or off.
For information, the whole regulator and transistor setup is tested and works like a charm.
Here is the code I wrote for the this case:
void setup()
{
  pinMode(PB0, INPUT);
}

int potValue = 0;

void loop()
{
  potValue = analogRead(PB0);
  delay(100);
}

Not real fancy right?
Now no matter what use for the POT, and I tried 2.4K, 10K and up to 100K, the value read by the ATTINY is always 512.
Do you see something wrong in this setup?
Could it be a bug in tinkercad? (I'd be surprised though)
I could try and share this circuit within tinkercad if someone would be willing to have a look...
EDIT: I just tried with PB2 as suggested but not the value is always 58:

Since you never display the reading from the pot, how do you know what it is?   Try printing it.

Port PB0 is not an ADC pin on the ATTiny85. Choose PB2, PB3, PB4 or PB5.

I know the value of the pot reading because tinkercad has a debugger

I'll try another pin straight away

I see you have a wire bridging the ground on one side of your breadboard to the other side. Don't you also need to bridge the +5V rail between sides of the breadboard? (in addition to using an analog pin.)

@DuncanC no as the input from the top rail is 9v and I use the 5v regulator to power the lower rail and the ATTINY85. Ground is common however

Note that you would need a resistor on the base of the NPN transistor.

Why do you think you need a smaller value pot? The resistance of the pot makes almost no difference to the readings the Arduino makes. It only has an effect when you go to very large (>1MΩ) values. By reducing to a smaller number all you're doing is wasting power.

When I way that I need a smaller POT I meant that the physical object needs to be smaller than the 10K one I have as I need to have an end result as small as possible, no relationship to the POT resistance at all, sorry for the confusion

Here it does not make a difference, but the PXn notation is no the same as a pin number, which gets used by Arduino functions. PB1 will be defined as 1, because it is the second bit in the registers for Port B (start counting from 0). So on a bigger microcontroller PC1 will also be 1. Pin numbers are different and on the Attiny85 just happen to be the same (because of the low pin number)

Did you see the comment of Edgar Bonet? You need a resistor at the base of the transistor. You must limit the current through the base in order not to destroy the transistor or the ATTINY.  If I had to switch a load with an ATTINY I would use a MOSFET because they have a very high  input impedance (resistance) on the gate (base) pin. So the ATTINY pin won't be stressed. ;-)

I indeed saw the comment and actually used a resistor in my real life circuit. However I read that the resistor is mainly used to control the output value. So I kind of fail to understand how/why it is that could destroy either part. FYI I used a 1k resistor, no clue if that's enough. I looked through the documentation on my transistor but did not managed to find the info

@GeorgesLegros The transistor is like a diode between the base and the emitter. That means, that the current through it rises exponentially with the voltage. It can esaily exceed the max current of 20mA (and also the absolute maximum of 40mA) and thus destroy the digitial output hardware of that pin. A resistor reduces that current, so that is does not get blown. With 20mA max and 5V you could use 5V/20mA=250 Ohm to be safe, even, when the transistor would be shorted. Raise the value as you like, be careful with lower values.

Thanks for the explanation, it makes more sense now. In my circuit I am switching a 9v input with the transistor, does that mean I should then have a minimum value of 450 Ohm for that resistor? In other words, should I base that calculation on the ATTINY and thus the pin or on the current I am switching?

Port PB0 is not an ADC (analog input) pin on the ATTiny85.
Available pins of the ATTiny85 (from the Atmel ATtiny 25, 45, 85 datasheet):
Choose PB2, PB3, PB4 or PB5 if you need an analog input.
Additional information: When built in TinkerCAD, using PB2 as an analog input does not seem to work correctly and produces a fixed value. Using PB3 did work correctly however. This might be a bug in TinkerCAD.

Just tried and I get another weird fixed value: 58...

I edited the question so I could upload a picture of the new setup using PB2 and the debugger output

Just for fun, I built the same circuit (but simplified) in TinkerCAD and strangely enough I could not get it to work with PB2, but PB3 did work. I guess this is a bug in TinkerCAD. I haven't used it before until today but I'm pretty sure I've built it correctly.

Indeed, it works like a charm with PB3! Thanks! Can you add this comment to your answer so I can accept it (I guess it is clearer for future references)

I've added the comment to my answer.

I tried PB5 on tinkercad and it just getting "random" values event if I don't touch the POT. I shall send an email to the support just to let them know. However, do you confirm that it "should" work ok PB2? I'll do some tests on my breadboard to validate. Problem is that the real use case is actually making use of PB3 already...

PB5 is probably preconfigured as a RESET pin so I'm not sure it's wise to use it for anything other than that. I am not too familiar with the Analog part of the ATtiny's but I do know that (just like other AVRs) there's only a single A/D converter that the 4 analog inputs are connected to via an analog multiplexer and it should not make a difference what input pin is used (as long as it is not used for anything else).

That image can be a bit confusing if you don't know what to look for. Look at the pins that have ADC0, ADC1, ADC2, ADC3 next to them. As is Analog to Digital Converter <number>.

Just made another test and it seems like PB4 is also creating a problem as I get the same randomness as I was having with PB5 (RESET). I opened a support ticket with Tinkercad, looking forward to the answer, will keep you posted.


text:
Why should I connect the l289n motor driver wires to specific arduino pins only?
So, I am new with arduino and am to build a robot using motors, for that I have bought l298n H bridge motor driver. I have watched various site and videos ,to make sure not to make a mistake but, in every video and sites
I have found their connecting the motor direction controller to

IN1 -> Arduino Pin 8 (digital) and IN2 -> Arduino Pin 7 (digital)
Till then it was fine ... Now the fishy thing for me is
IN3 -> Arduino Pin 5 (PWM) and IN4 -> Arduino Pin 4 (Digital)
Why connect to a Digital and a PWM?
For E1 and E2 I am sure that the wires should be connected to the PWM (~) pins for arduino, to control speed of the motor..
But, Should not I be able to connect IN3 and IN4 both to rest of the digital pins 12, 13 or 2,4 Just Like IN1 and IN2 is connected to 7 and 8.
But the IN3 and IN4 is connected to a PWM and a Digital pin.
Conclusion,
So can I use all the unused non PWM digital pins to connect the motor direction control?
Thanks for your precious time..!

PWM is a digital output ... it is pulsed ... the pulse timing is variable

I know that but , can we use a non PWM pin for it?

Because , we don't need PWM to just change the polarity of the motor, so , as per my logic, we should be able to use non PWM pins for motor direction changing purpose, So , am I right or wrong?

I think that you are missing important information ... the pins on the arduino are PWM only when you use analog out ... they are same as the other pins if you use digital out ... the reason to use PWM on the motor driver is not direction, but speed

what are the signal polarities for forward and what are they for reverse?

Here we are talking about Direction , not Speed , don't get confused @jsotola so , we can use only digital pins to do that and keep our rest pins reserved for other options.

i am not confused ... the motor driver uses two input pins ... the two pins have to be set to opposite values to run the motor ... if you use PWM on one of the pins and only digital on the other pin, then you can control direction and speed at the same time

Pwm is just a digital out with extra fancy on off controls.  You can use any digital out if you do not need those extra features.
To just signal a single H bridge (1 motor of your l289n) for forward, reverse, stop, one only needs two digital outs.
I recommend you get the hang of your h bridge first - signaling it on a bread board with vcc (usually 5v but can be 3.3) and ground rather than the arduino.  Then once you understand the motor directions that result from your wiring, write the code accordingly.  This tends to result in:

fewer fried arduinos
code with functions and signals named after their intent (rather than having to mix forward and reverse)

I know, my connection would be , Common Ground for 9v battery and arduino, Then , power the motor driver GND and +12 volt terminals, connect arduino VIN pin to the +5v output of the driver and bingo!  It shouldn't burn my board.

If you mean one of those square 9V battery like in a smoke detector then I think you will be disappointed.  They’re not much good for motors.  Try a handful of AA or AAA would be much better.  9V pp3 batteries can’t produce much current at one time.

Also don’t connect Vin to 5V.  Vin needs at least 7V.  If you have regulated 5V then put it on the 5V pin.

Will Duracell 9v batteries work? And also, the 5 volt is going to be regulated from the 9 volt battery by a resistor.

yes the 9v will run the arduino over vin.  It will produce 5V for you.  Both your arduino and l298n have proper regulators for producing 5V so you shouldnt have to do anything but hook the 9V to them (correctly) to produce 5V.


text:
"No I2C devices found" Arduino Nano Every
I was able to set up a Arduino Nano with an I2C board very easily, but the Arduino Nano Every is giving me a much harder time (my project required low profile).
Just to test, I stripped some wires, and looped them into the board, I'm not sure I want to solder on the pins as they may be too tall. Anyways, just trying to get a proof of concept going right now.
Here's how it's connected:

based on this pin diagram: https://i2.wp.com/rosmianto.com/wp-content/uploads/2019/05/Untitled-Diagram-4.png?fit=1506%2C1974&ssl=1
The screen lights up so I know the 5v and Ground connections work, but when I scan for I2C devices with i2c_scanner, it sees no devices.
18:20:56.254 -> Scanning...
18:20:56.289 -> No I2C devices found
18:20:56.289 ->
18:21:01.265 -> Scanning...
18:21:01.265 -> No I2C devices found
18:21:01.300 ->

Looping the wires through the board and not soldering them is probably your problem.  That's not going to make a very good connection.  You may get power and ground that way, but digital signals like I2C comms are going to see a LOT of noise.

Ah, okay, I'll solder it then and see if that helps

@Delta_G Yup that was it!

stick toothpicks into the holes to tighten up the connections

@Delta_G, make that an answer so we can mark it as such.

Looping the wires through the board and not soldering them is probably your problem. That's not going to make a very good connection. You may get power and ground that way, but digital signals like I2C comms are going to see a LOT of noise.


text:
Branchless programing on arduino?
So I've been looking into branchless programming to speed up code and I'm curious as to how exactly Arduino (or rather atmega328) actually reads machine instructions. Does it have a memory cache or does it read every instruction from the flash memory?
From my understanding of branchless programming it speeds up the computation because the CPU does not have to jump inside the instructions and can read it sequentially, hence does not need to load in new instructions in case it has to jump to a location that's not loaded.
My question is, does this apply to the atmega328? If it reads every instruction straight from flash without using a cache then it shouldn't matter much if it has to jump in the instructions, right?

no cache ... no loading of instructions during execution ... you would save a bit of time on each eliminated jump instruction ... so, if you are running an oscilloscope sketch, then run inline code from begining to end

Even inline is just a suggestion though right, and the compiler can do as it pleases? You should also compile with optimization level -O3 for speed instead of -Os for size.

@Beacon of Wierd, post this on https://www.avrfreaks.net/ too to see what they say, and give us a link here to it. I'd like to know, and they have a lot more low-level experts and advanced AVR users over there I imagine.

Branchless doesn't make a lot of sense to me for AVRs. I'd suggest learning to read the assembly code generated by the compiler (avr-objdump -S <filename>.elf). Then compare different versions of your algorithms to each other. I like to use wdt_reset() to add a marker before a certain section I'm interested in. Then in the assembly code look for the wdr instruction.

There is no cache, so you don't need to worry about that. All instructions are fetched direct from flash and executed straight away.
There is, though, a 2-stage pipeline. That means that in one clock cycle an instruction is fetched from flash, and in the next clock cycle it's executed - and while that is being executed the next instruction is being fetched ready.
That means that when a branch occurs, since the AVR uses a very very simplistic approach to branch prediction (i.e., it assumes the branch will not be taken and just loads the next instruction regardless), it has to discard the contents of the pipeline and start from scratch.
That's only a one clock penalty while it loads the newly-branched-to instruction, but it's still a penalty.
Cache is only needed when the CPU core runs faster than the memory can be accessed. Since the AVR only runs at up to 20MHz that is considerably slower than the flash can be accessed, so adding cache would be completely pointless. Other faster MCUs do use caching, such as the 200MHz PIC32MZ, since otherwise "wait states" would have to be introduced to slow the reading from flash down.


text:
Error occurs when compiling ESP32 self-update firmware code
when i write this code in esp8266, it's work fine. but when i tried that code in esp32 with some changes,it shows error on compile time:

board which i use : DOIT ESP32 DevKit v1

error is:
In file included from C:\Users\Gabbar Singh\Documents\Arduino\ESP32_OTA\ESP32_OTA.ino:5:0:
C:\Users\Gabbar Singh\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\HTTPUpdate\src/HTTPUpdate.h:47:6: error: multiple definition of 'enum HTTPUpdateResult'
 enum HTTPUpdateResult {
      ^
In file included from C:\Users\Gabbar Singh\Documents\Arduino\ESP32_OTA\ESP32_OTA.ino:3:0:
C:\Users\Gabbar Singh\Documents\Arduino\libraries\ESP32httpUpdate\src/ESP32httpUpdate.h:59:6: note: previous definition here
 enum HTTPUpdateResult {
      ^
Multiple libraries were found for "WiFi.h"
 Used:C:\Users\GabbarSingh\AppData\Local\Arduino15\packages\esp32\hardware\esp32\1.0.4\libraries\WiFi
 Not used: C:\Program Files (x86)\Arduino\libraries\WiFi

and the last error is : exit status 1
Error compiling for board DOIT ESP32 DEVKIT V1.
Code:

#include <Update.h>
#include <WiFi.h>
#include <ESP32httpUpdate.h>
#include <WiFiClient.h>
#include <HTTPUpdate.h>
#include <HTTPClient.h>

#define LED_BUILTIN 2

const String FirmwareVer = {"1.4"};

#define URL_fw_Version "http://vadaliya2007.000webhostapp.com/atte/ota/version.txt"
#define URL_fw_Bin "http://vadaliya2007.000webhostapp.com/atte/ota/firmware.bin"
HTTPClient http;

const char* ssid = "Honor8X";
const char* password = "1414141414";

void FirmwareUpdate()
{
  http.begin(URL_fw_Version, "5b fb d1 d4 49 d3 0f a9 c6 40 03 34 ba e0 24 05 aa d2 e2 01"); // check version URL
  delay(100);
  int httpCode = http.GET();            // get data from version file
  delay(100);
  String payload;
  if (httpCode == HTTP_CODE_OK)         // if version received
  {
    payload = http.getString();  // save received version
    Serial.println(payload );
  }
  else
  {
    Serial.print("error in downloading version file:");
    Serial.println(httpCode);

  }

  http.end();
  if (httpCode == HTTP_CODE_OK)         // if version received
  {
    if (payload.equals(FirmwareVer) )
    {
      Serial.println("Device already on latest firmware version");
    }
    else
    {
      Serial.println("New firmware detected");
      WiFiClient client;

      // The line below is optional. It can be used to blink the LED on the board during flashing
      // The LED will be on during download of one buffer of data from the network. The LED will
      // be off during writing that buffer to flash
      // On a good connection the LED should flash regularly. On a bad connection the LED will be
      // on much longer than it will be off. Other pins than LED_BUILTIN may be used. The second
      // value is used to put the LED on. If the LED is on with HIGH, that value should be passed
      //ESPhttpUpdate.setLedPin(LED_BUILTIN, LOW);

      t_httpUpdate_return ret = ESPhttpUpdate.update(URL_fw_Bin, "", "5b fb d1 d4 49 d3 0f a9 c6 40 03 34 ba e0 24 05 aa d2 e2 01");

      switch (ret) {
        case HTTP_UPDATE_FAILED:
          Serial.printf("HTTP_UPDATE_FAILD Error (%d): %s\n", ESPhttpUpdate.getLastError(), ESPhttpUpdate.getLastErrorString().c_str());
          break;

        case HTTP_UPDATE_NO_UPDATES:
          Serial.println("HTTP_UPDATE_NO_UPDATES");
          break;

        case HTTP_UPDATE_OK:
          Serial.println("HTTP_UPDATE_OK");
          break;
      }
    }
  }
}

unsigned long previousMillis = 0;        // will store last time LED was updated
const long interval = 30000;

void repeatedCall() {
  unsigned long currentMillis = millis();
  if ((currentMillis - previousMillis) >= interval)
  {
    // save the last time you blinked the LED
    previousMillis = currentMillis;
    FirmwareUpdate();
  }
}

void setup()
{
  Serial.begin(115200);
  Serial.println("");
  Serial.println("Start");
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED)
  {
    Serial.print("O");
    delay(500);
  }
  Serial.println("Connected to WiFi");
  pinMode(LED_BUILTIN, OUTPUT);
}
void loop()
{
  digitalWrite(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
  delay(100);                       // wait for a second
  digitalWrite(LED_BUILTIN, LOW);    // turn the LED off by making the voltage LOW
  delay(100);                       // wait for a second
  repeatedCall();
}

what is your question?

i got an error when i compile this code

that is not a question ... it is a description of a problem

how to solve this error...

Please tell us how you compile this, and show us the exact error message. Remember to [edit] your question, do not add information in the comments, they will be ignored.

ohh..i'm sorry...i'm new to this.. i compile this code in arduino ide

the error is i used two libraries esp32httpupdate and httpupdate, which both have same function so i remove the other one(httpupdate)... and now problem is solved.


text:
Help me for interfacing Arduino with AMTP32M VOICE IC
i'm trying to get control an Aplus chip aMTP32M (stores audio samples) with Arduino . this amtp32m ic provide CPU SERIAL MODE its come with DATA and CLOCK pin.i try Spi mode with Amtp32m ic but its not working.
Please help me for this.
Link for  for DATASHEET of AMTP32M IC -http://www.aplusinc.com.tw/proimages/Mtp%20Vioce%20Ic/aMTP32M/aMTP32M/Datasheet/aMTPxxM-Datasheet_V1.1_20141216.pdf

Finely i try the below code for serial mode. it's worked perfectly...
type def union
  {
unsigned char BYTE;
struct
{
    unsigned        BIT0:1;
    unsigned        BIT1:1;
    unsigned        BIT2:1;
    unsigned        BIT3:1;
    unsigned        BIT4:1;
    unsigned        BIT5:1;
    unsigned        BIT6:1;
    unsigned        BIT7:1;
};
}ByteToBit;

void Play(unsigned char Val)
{
  ByteToBit SectionNo;

  SectionNo.BYTE = Val;

CLOCK = 1;
DATA  = 0;
CLOCK = 0;

DATA  = SectionNo.BIT0;
CLOCK = 1;
CLOCK = 0;
DATA  = SectionNo.BIT1;
CLOCK = 1;
CLOCK = 0;
DATA  = SectionNo.BIT2;
CLOCK = 1;
CLOCK = 0;
DATA  = SectionNo.BIT3;
CLOCK = 1;
CLOCK = 0;
DATA  = SectionNo.BIT4;
CLOCK = 1;
CLOCK = 0;
DATA  = SectionNo.BIT5;
CLOCK = 1;
CLOCK = 0;
DATA  = SectionNo.BIT6;
CLOCK = 1;
CLOCK = 0;
DATA  = SectionNo.BIT7;
CLOCK = 1;
CLOCK = 0;

DATA  = 0;
CLOCK = 1;
DATA  = 1;

return ;
}

 void main(void)
 {
    unsigned char SectionNo;

CLOCK = 1;
DATA  = 1;

SectionNo = 0x00;
while(1)
{
    Play(SectionNo);
    Delay_1mS();        // Wait for BUSY set up time...
    while(BUSY);        // Voice playing...
    SectionNo++;
}

return ;
}

according to this :

it's more similar to I2C than SPI. anyway, it's just 2 wire custom serial interface. you can use any 2 GPIOs for this purpose.
for sending a byte, you have to:

initialize 2 GPIOS (CLK_IO and DAT_IO) to output, high.
set DAT_IO low
wait at least 1us (according to datasheet ver 1.1, page 18) then set CLK_IO low.
place the D0 bit value on the DAT_IO
toggle the CLK_IO (set it high, wait at leas 1us, set it low)
do steps 4 and 5 for all the remaining bits.
at the end set CLK_IO high
wait for at least 1us and set the DAT_IO high.

thank you for your replay.i will try your suggestions.

According to datasheet page 25, it would be much easier to use the Parallel mode than the Serial mode.

hcheung..Yes parallel mode is much easier .but it's give only 32 sections for audio storage. in serial mode  it give 255 sections for audio storage.