text:
MAX7219 7-segment 8-digit display in wrong order
I have daisy-chained three MAX7219 7-segment 8-digit displays and wired it according to this diagram:

but no matter what library I use, the middle segment is in the wrong order when I display it.
So the numbers "123456789123456789"
would display as"12345678 76543219 89"
What could be wrong?

you probably want to understand how the three modules are internally connected so you are sure if you need to connect the serial pins yourself. while I don't know what your problems are with certainty, I can assure you with absolute certainty that your code is 100 percent correct. no need to waste your time debugging it.

If you had three separate boards that you had chained together I would be surprised if one of them was wrong, but looking at the picture it looks like one board and I would think it was more likely that one display was incorrect.
I can't see your code, so I can't say if there is a bug in it or not.  It is possible that you have done something unusual, you might want to post a MINIMAL example to let people give it the once over.
As far as I know there aren't any "configuration settings" on a Max7219 to cause the affect you are seeing.  The fact that the 3rd display is correct implies that the tracks on the PCB are correct and its the IC that's got its wiring backwards, but that's a daft idea.
You might be able to work out if a track is wrong, or such like, but it would be so much easier to fix in software.  When you write to the display add an extra function that traps calls to the middle segment and flips the digits round (so tmp == digit[7]; digit[8] == digit[0]; digit[0] = tmp; // You know what I mean).


text:
HC-05 emit data without pairing
Is it possible to emit data from an arduino connected to a hc-05 Bluetooth module without pairing it to another device?
i.e. imagine that I want to send a Bluetooth signal as if it was a information spot. Then whoever who gets the signal can read it.

No. The HC-05 has to be paired. It runs on Bluetooth 2.x which requires pairing.  What you want is BLE (or Bluetooth 4.x) which has various "beacon" facilities.

source: Stack Exchange

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

sort: votes


text:
Arduino I2C communication between Raspberry Pi
We are trying to communicate between multiple Arduino's (in this example a Nano and a Mega) and a Raspberry Pi. The Raspberry pi is defined as master and the Arduino's as slaves. We would also like that the Arduino's communicate between each other. For example: The Mega requests from the Nano and at some point, the Mega also communicates with the Raspberry Pi. This is the short version of what we are trying to accomplish but we ran into the problem that the i2c communication failed between the Nano and Mega upon the request from the Mega to the Nano.
Schematic

Problem
After some time the i2c bus 'fills' up...

Code Nano
(We send RFID data to Mega)
#include <Wire.h>
#include "SPI.h"
#include "MFRC522.h"

#define SS_PIN 10
#define RST_PIN 9
#define SP_PIN 8

MFRC522 rfid(SS_PIN, RST_PIN);

MFRC522::MIFARE_Key key;

void setup() {
  Serial.begin(9600);
  SPI.begin();
  rfid.PCD_Init();

  Wire.begin(0x10);
  Wire.onRequest(requestEvent);
}

void loop() {

}

void requestEvent() {
  if (!rfid.PICC_IsNewCardPresent() || !rfid.PICC_ReadCardSerial())
    return;

  // Serial.print(F("PICC type: "));
  MFRC522::PICC_Type piccType = rfid.PICC_GetType(rfid.uid.sak);
  // Serial.println(rfid.PICC_GetTypeName(piccType));

  // Check is the PICC of Classic MIFARE type
  if (piccType != MFRC522::PICC_TYPE_MIFARE_MINI &&
      piccType != MFRC522::PICC_TYPE_MIFARE_1K &&
      piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
    Serial.println(F("Your tag is not of type MIFARE Classic."));
    return;
  }

  String strID = "";
  for (byte i = 0; i < 4; i++) {
    strID +=
      (rfid.uid.uidByte[i] < 0x10 ? "0" : "") +
      String(rfid.uid.uidByte[i], HEX) +
      (i != 3 ? ":" : "");
  }
  strID.toUpperCase();
  //81:AE:1D:29
  Serial.print("Send to Mega: ");
  Serial.println(strID);

  Wire.write(strID.c_str());

  rfid.PICC_HaltA();
  rfid.PCD_StopCrypto1();

}

Code Mega
#include <Wire.h>

void setup() {
  Wire.begin(0x03);
}

void loop() {
  Wire.requestFrom(0x10, 11);

  String uid = "";

  while (Wire.available()) {
    char c = "";
    c = Wire.read();
    uid += c;
  }

  if (uid.indexOf(':') != 2) {
    return;
  }

  Serial.println(uid);

  delay(500);
}

We would like to communicate between the Arduino's when the Raspberry Pi is master.

Pi and arduino works at different logic level bro. Also you gotta check if pull up resistors are needed in the SDA lines of I2C bus. I suspect internal pullups of UNO are not really useful. Use 2.2K pull-ups externally.

Thanks! Also you gotta check if pull up resistors are needed in the SDA lines of I2C bus. I placed a 1K pull-up between 3.3V and SDA and also a 1K pull-up between 3.3V and SCL according to this article: link. Thank you! Is the 1K between 3.3V and SCL needed?

Yea i guess you need pull up in both SDA and SCL.

Its a long time since I used a Pi, but isn't it a 3.3V device and the Arduinos are 5V devices.  I think you may need a logic level shifter (not a resistor divider).  I suspect that's the reason I2Cdetect isn't working and without that working, nothing else will.

Thanks for the suggestion, we'll try and let you know if it worked!

The level shifter isn't necessary I think (I'm not quite sure). But just to be sure; we'll put them in, thanks!

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


text:
How to include userid, pass to WifiClient connect() api
These are my remote server credentials that I want to connect from my local device.
Server  m12.cloudserver.com
User    <myname>
Password    <mypassword>
Port    19999
_ or
api_key 5678909876-009-00d

I want to use the WiFiClient client() API as shown, but where or how do I include the User credentials ? so that I can make a successful connection to the remote server from my device connected over Wifi.
Cut and paste from my Arduino code.
const int httpPort = 19999;
if (!client.connect("m12.cloudserver.com", httpPort)) {
 Serial.println("connection failed");
 return;
}

Read the API docs.

WifiClient provides low level tcp connection. Your server seems to be implementing a REST API interface. Thus you need to construct HTTP headers (GET, POST, etc.) manually as a string. Then you can add your credentials. Before doing so, try to use your server, I mean call api's with the program named Postman. Postman runs on Chrome browser. Postman can compose such headers for you. Then you can insert them into your arduino code.


text:
Arduino Nano /Uno USB is not getting recognized
I have multiple Unos and Nano and recently due to some bad configuration the USBs are not getting recognised on my Mac Air Laptop. These were working models for almost 1-2 years. I used it to control motors and something must have happened and it stopped.
But strangely the small boot up LEDs on the Nano/Uno light up when connected so it seems that the connection from the laptop USB to the device is good - but the driver ports are not showing up on the Arduino IDE.
How do I go about resolving that it is not just a software issue and is a hardware issue ?
I reinstalled the CH340G driver.img and yet the device when plugged in - does not show the USB port on the IDE ?
Any thoughts or ideas on how to resolve this.
The Uno/Nano are Chinese Clones and have CH340 chipset on them.
Is there some firmware that may have gone wrong and can be reset ? or new boot loader that can be burnt to bring them back to life.
I want to be able to see the Tools-> Port -> /dev/cu.usbserial1410
and also be able to see /dev/cu.usbserial on the command xterm prompt .

1-2 years is a good lifetime for a CH340G...

Assuming that the atmega328p still works fine, you can still use the Nano. I have solved this a few times by just using a FTDI breakout board (remember to set it to 5V, though 3V3 upload works on a Nano), and connecting RX to TX, TX to RX. Press reset before each upload.

Thanks for the answer - I have a cloned Uno and a Nano. I guess I have to use a different breakout ?
My Uno/Nano has a 340G chipset, not FTDI.

Unos (real or cloned) use a 2nd processor on the board to manage USB communication with your computer. Since that processor or its firmware on your board is not working, @user2497 is suggesting you bypass it with another one on a breakout board or built into a cable. That breakout board or cable will almost certainly use an FTDI chip, regardless of what chip on the clone board has. You'd connect the breakout board or cable directly to the ATmega328p's RX and TX pins, just as its (now non-functional) 2nd processor is.

I have a PL2303 ( I think it's similar to FTDI) and installed the driver and was able to see the driver on Arduino IDE.
PL2303 .   Arduino

PL2303 Tx ->    Arduino Rx

PL2303 Rx ->    Arduino Tx

PL2303 GND -> Arduino GND

I did not connect the 3V3 of the PL2303 and left if open.
What is the Tools-> Board and Tools-> Programmer to use on the IDE ?

I reset the Arduino button  just when I clicked the Upload on the IDE, and it's just uploading .. or timeout with the stk_recv error !

@ShashiKiran Just use the default, and select the right serial port. You press reset just before the upload? The timeout is normal if you don’t press reset in time.

@user2497 - Thanks, So I am not connecting the PL2303's 3v3 to the Arduino's 3.3v - Is that right.
I tried about 3 of the Arduino's so far - and the "Uploading" stays put for a long time ! after I have clicked on the Reset Button of the Uno. !
On a side note - all the 3 Uno's boot-led- near pin 13 lights up when powered by a 5V USB. ( that is before I even try to upload the code )

@ShashiKiran Use 5V, use a levelshifter if you have one.

@user2497- You mean provide Uno's 5V -> to 5V ( or 3.3 using the level shifter) of the PL2303 breakout board.
Is the break out board not getting power from the USB port of my Mac. A really small red light lights up on the PL2303 when I plug in to my Mac USB Port.

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


text:
Error 'exec: "python": executable file not found in $PATH Error compiling for board AI Thinker ESP32-CAM.' in Arduino IDE 1.8.12
I am trying to upload a sketch to the ESP32-CAM board using Arduino IDE 1.8.12 and I get an error message:
exec: "python": executable file not found in $PATH
Error compiling for board AI Thinker ESP32-CAM.

My OS is Ubuntu 18.04.4.LTS.
When I type python in the console, it does open python:
$ python
Python 2.7.17 (default, Nov  7 2019, 10:07:09)
[GCC 7.4.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
KeyboardInterrupt
>>>

Also python is in one of the directories referenced by PATH:
$ which python
/usr/bin/python
$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin

I added an additional URL referring to the ESP32 boards on the Espressif website:
Arduino IDE > File > Preferences > Settings > Additional Boards Manager URLs: > https://dl.espressif.com/dl/package_esp32_index.json

Then I added the libraries for all ESP32 boards:
Arduino IDE > Tools > Board > Boards Manager > esp32 version 1.0.4

(I tried with version 1.0.3 and it didn't change anything...)
I selected my board in the interface:
Arduino IDE > Tools > Board > AI Tinker ESP32-CAM

I granted all permissions to the USB port:
sudo chmod a+rwx /dev/ttyUSB0
ls -la /dev/ttyUSB0
crwxrwxrwx 1 root dialout 188, 0 Mar  4 21:25 /dev/ttyUSB0

My sketch is really simple:
void setup() {
}

void loop() {
}

I get the same error for any example sketch and for any ESP32 board.
Any idea how this could be fixed ?

All right so I was able to fix the problem. The Arduino IDE I was using had been installed from the Ubuntu Software Center. I uninstalled it.
Then I reinstalled the Arduino IDE by downloading it from the www.arduino.cc website and doing a manual install in /opt. Now it works awesome.

Good, that you solved the problem. You can mark your answer as correct, so that other can see, that this problem is solved.

This was an issue with the old Arduino IDE snap on Ubuntu. You can easily fix this by installing the new arduino snap:
snap install arduino

Then add your user to the dailout group:
sudo usermod -a -G dialout $USER

After this, reboot your device and open Arduino IDE.
Installing additional libraries
The Arduino IDE snap runs inside of a sandbox for security and stability reasons. This means it cannot access the Python libraries on your device. The snap bundles Python 3 and the serial library. If you need any other Python dependencies, you can install them inside of the sandbox using the arduino.pip command.
arduino.pip install <package-name>

Note: do not use sudo for this command

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


text:
Bluetooth connection to HC-05 paired but not connected (in Linux)
I have an Arduino Uno connected to an HC-05 Bluetooth sender/receiver chip. I am trying to create a Bluetooth connection between my Acer laptop running under Ubuntu 14.04 LTS and the HC-05 chip.
Ubuntu detects the HC-05 chip, as can be seen below.
phodor@ubuntu: hcitool scan
Scanning ...
    11:22:33:44:55:66   HC-05

I am able to create a pair between my laptop Bluetooth device and the HC-05 chip. However, I am unable to create a connection with that pair from the Ubuntu interface. The "Connection" button cannot be clicked on, as you can see on the figure below.
I tried creating a connection using the terminal, but after that the terminal still did not detect any connection.
phodor@ubuntu: sudo hcitool cc 11:22:33:44:55:66
[sudo] password for phodor:
phodor@ubuntu: hcitool con
Connections:

I also checked that my computer Bluetooth device was working.
phodor@ubuntu: hcitool dev
Devices:
    hci0    AA:BB:CC:DD:EE:FF

Any idea why the connection cannot be created ? Any idea on how to do it using the Ubuntu interface or the terminal ?

You can find the answer in the Bluetooth connection to HC-05 paired but not connected
Step;
1.Once you have paired the HC-05 as you've described, bind the device by entering;
sudo rfcomm bind 0 "MAC address" 1

2.To trigger the connection & display the data using minicom, run;
sudo minicom -D /dev/rfcomm0

You'll notice that port /dev/rfcomm0 will be available from the arduino IDE as well.
3.To exit minicom, press ctrl+A and then X.

you can try this website for more information
http://wiki.micropython.org/official-accessories/Bluetooth-module-HC05

Link-only answers are frowned upon at Stack Exchange. The answer should at least summarize what we would find if we followed the link. Plus, the link might go down. Please expand your answer.


text:
Difference between /dev/ttyACM0 and /dev/ttyS0 (Arduino IDE ports under Linux)
I use the Arduino IDE to upload sketches to my Arduino Uno. My OS is Linux Ubuntu 14.04 LTS. The Arduino IDE has two ports by default for communication with the Arduino Uno:
/dev/ttyACM0
/dev/ttyS0

What is the difference between these two ports ?
What does "ACM0" and "S0" mean ?
Are there configuration files somewhere in the OS folder structure that describe the parameters of these ports ?

I know that when I select /dev/ttyACM0, I am able to send data to my Arduino Uno. However it does not work when I select /dev/ttyS0.
I just want to better understand what these ports are exactly.

/dev/ttyACM0 is a USB communication device (CDC) of sub-type "abstract control model" (ACM). That is what the Arduino is.
/dev/ttyS0 is a hardware serial port - the (typically) 9-pin D connector on the back of your computer.
If you want to use /dev/ttyS0 (why would you?!) you will require a special cable that converts the RS-232 voltage signals from the 9-pin D connector into the right TTL level signals for the Ardiuno and wire it in to the right pins on the board.

Thank you for your clarification. Can You help how to upgrade firmware on Sim800 using Sim 800 Serious tool for Linux as it mentioned `Usage: mtkdownload  ROM_VIVA
: /dev/ttyS0,/dev/ttyS1,/dev/ttyS2..
means  COM1,COM2,COM3,COM4,USB2COM
ROM_VIVA is updating rom file
 Y,N
means  format FAT or not format Fat
Example: mtkdownload 100 ROM_VIVA Y
and When I use ./mtkdownload /dev/ttyACM0 ./ROM_VIVA ` It just print same above.

Some high-level languages (e.g. matlab) treat all serial ports as the  /dev/ttyS# selecter.  To interface with an Arduino with MATLAB you have to rename /dev/ttyACM0 as /dev/ttyS#.
This may also be an option in the Arduino IDE, and that is why those options exist.

why would you rename it when a symlink could do the trick ?


text:
Building an AtMega328p from Transistors
I'm a little new to circuitry, and the Arduino in itself!
From what I know, I think that it might be possible to actually build one (the processor itself, of course) from transistors. This isn't a practical question, of course, but it would be an excellent learning opportunity.
Would it be actually possible to go through with such a project (Even without EEPROM)?
If so, how would it be completed?
Thank you!

Transistors - :). Gates - yes but just too much work. FPGA - yes. Check estimated number of transistors https://www.embeddedrelated.com/showthread/comp.arch.embedded/14362-1.php

Start easy and e.g. build a 4-bit adder. The go for a 4-bit ALU. I.e. start small, and keep extending it.

I'd highly recommend you take a look at Ben Eater's video series about building an 8-bit computer on breadboards: https://www.youtube.com/playlist?list=PLowKtXNTBypGqImE405J2565dvjafglHU
He doesn't build it from transistors, and it isn't an AVR CPU, but he explains in detail the function of each IC he uses for this project, including possible circuits to duplicate the IC's functionality with transistors. With this approach he keeps the whole thing relatively compact, and still manages to visualise every detail of the CPU's inner workings using plenty of LEDs and a single-step clock mode.

Yes, it is possible - after all, the Arduino is essentially just a bunch of incredibly tiny transistors. Early computers, before ICs were invented, were built from transistors. Before that it was valves. Before that it was relays. All just, at the end of the day, switches.
Would it be a practical project? Not really, although someone has done it (not for the AVR CPU, but the concept is the same): http://www.megaprocessor.com/
How would you start? Well, first off you'd create the basic building blocks of a CPU, which is logic gates. There are two basic ones that can be combined together to make any other gate: the NAND gate and the NOR gate. You'd pick one of those and put lots of them together to make the basic sections of the CPU. Then those blocks connect together to form the CPU. More logic gates go together to make the IO functionality, memory, interfaces, etc.
Basically:

Transistors combine to make NAND gates (or NOR gates if you prefer that form)
NAND (or NOR) gates combine to make complex gates.
Complex gates combine to make logic functions
Logic functions combine to make logic blocks (like the ALU)
Logic blocks combine to make the CPU

Wow! Thanks! This is really helpful! This looks really, really hard, but I still might try it... Thank you!

If I really were doing this by hand, I would not make complex gates out of NANDs (nor NORs), as it would be more efficient to make them directly out of transistors. As an example, NOT(A AND B OR C) can be made with 6 transistors in CMOS (and only 3 in NMOS or PMOS). Many more transistors would be needed if one would be restricted to use only universal gates.

@EdgarBonet That's the same as what you end up with after optimization of your discrete gate circuits.

But then, going through an all-NAND design seems like useless extra work.

@EdgarBonet Which is why it's an essential step in the project. The whole project is useless extra work. And if you have to ask the question that the OP asked then you obviously have no understanding of logic gates etc so starting simple with NAND is a basic requirement.

I do not think you could build an ATmega328P out of discrete parts: you
would need floating-gate transistors for implementing the flash, and
these do not seem to be available as discretes.
If you forgo the flash (or replace it with RAM or ROM), then it should
in principle be possible. This processor, however, is probably not a
good choice for such a project. From the discussion linked to by
Mikael Patel, it seems you would need something like 80 K
transistors for the core alone, and much more if you include the RAM and
the peripherals. It would be a daunting task to assemble all this by
hand. For comparison, the Megaprocessor1 as about
42 K transistors total (core + RAM + LED drivers).
If you want to pursue such a project, I recommend you target a simpler
CPU. The MOS 6502 may be a good choice. This CPU, which was very
popular in the late 70s and early 80s, has “only” 3,510 transistors and
is well documented. See for example the resources at visual6502.org.
They have an amazing online transistor-level simulator built from
the actual layout of the chip.
1Thanks Majenko for the link

The ATmega128 have 800000 transistors. (+-200000 transistors)
So If you want to take some transistors and breadboards and build an ATmega128p
first count the money for transistors (if 1 transistor costs 0.01€ then 800000 x 0.01 = 8000€ and the breadboards is much more expensive than transistors!)

Try to build out the entire thing inside a simulator instead of buying 10s of thousands of transistors and several other components....less messy and gets the job done at almost no expense

Please suggest a few simulators in your answer, otherwise it may get flagged as a comment / not an answer.

There's too many, check out: https://en.m.wikipedia.org/wiki/List_of_free_electronics_circuit_simulators and https://en.m.wikipedia.org/wiki/Electronic_circuit_simulation and https://en.m.wikipedia.org/wiki/Comparison_of_EDA_software

https://www.electroschematics.com/2249/pcb-design-software/

Even an entire plant with all equipment and processes running live can be simulated: https://en.m.wikipedia.org/wiki/Plant_Simulation

https://en.wikipedia.org/wiki/Robotics_simulator

There's a startup/website called labster that has all sorts of simulators for students. Facebook's metaverse and Nvidia's omniverse will soon incorporate such virtual labs and twin factories.

Why not? Atmel did it.  But if you mean by soldering up discretes...
In the mid 70s the Zilog Z80 had 8,500 transistors; a couple of years later, the Intel 8088 had 29000(source: Wikipedia). Neither of those had on-chip memory. The AtMega 328p has 2K of RAM and 1K of EEPROM on chip, so factor in for those and their drivers. At 20 MHz it will probably be fun 1) keeping signals where they belong; and 2) keeping the wire runs short enough and suitably arranged that capacitance doesn't slow and distort the signals to unusability.

Would it be actually possible to go through with such a project (Even without EEPROM)?

yes.

If so, how would it be completed?

the easiest would be to find or write a soft-core for AVR on a fpga. Get the logic blocks for that softcore , and then implement those logic blocks with transistors.
Before you set out actually doing it, however, check if you have enough of space or bank account (for the electric bills).

While it is possible, you will have to spend a lot of money and a lot of time. I think about thousends of dollars and months of work. Even when accomplished you will have learned more about electronics than about the ATmega328P. In order to accomplish, you will also have to ask Atmel to hand you over the schematics to get the inner working right. I highly doubt they will aggree since it is not Open Hardware.
I highly discourage you to do that. Instead I suggest you start with an Arduino UNO and discover the capabilities and then go a step further and use a bare ATmege328P.

Although you cannot get the schematic of the real Atmel’s AVR, there are a few AVR clones available at http://opencores.org/


text:
how to find find out capacitance using time constant?
i'm trying to find out the capacitance value using the time constant of the RC ciruit. so i followed the technique on the below link.
http://www.gammon.com.au/forum/?id=12075
Now, it's working fine.. but still i need wider range so i want to know the full core logic of that program like how the capacitance formula has been derived out in those program?
thanks in advance...

What about using RC Oscillator and just measure the frequency?

The key concept is this line:

... we find the point where the voltage reaches 63.2% ...

The time constant τ is how long it takes for a capacitor to charge up to 63.2% of the supply voltage. That is governed by both the capacitance (C) and the resistance (R). τ=RC. That is one of the basic formulae you should know as an Electronic Engineer.
If you know R (which you do because you chose it at 10KΩ) and you know τ (which you do because you measured it) then you can calculate C (τ/R).
Since τ, C and R are tied together like that it is possible to change the balance of C and R and keep τ the same. For instance, a 10KΩ resistor and a 47nF capacitor would give the same τ as a 1KΩ resistor and a 470nF capacitor. Also the same τ as a 100kΩ resistor and a 4.7nF capacitor.
You can easily change the range without having to change your time measurement system by changing the resistor to give a different scale.


text:
switch pump on with transistor, mosfet, or relay
I would like to control a pump.
The pump rating is 12 volt 60watts.
The pump mfg says to use a 12 volt power supply of 5 - 12 amps but AT LEAST 5 amps. This pump has a pressure turn off at 116 psi and the mfg states that the pump will not make maximum pressure with less than 5 amps.
So the question becomes, to be able to switch this pump on and off based on some sensor reading what would be considered best practice:
transistor, MOSFET, or relay?

Transistor - Big voltage drop between C-E @ 5A (depends on type but it will be about 2V). Power dissipitation is voltage drop times current so about 24Watts. You must be careful with inductive load - induced high voltage must be supressed. Usual way is using anti-parallel fast diode over load.
Mosfet - Voltage drop can be really small, so it might be possible to use it without heatsink. Big Gate capacity needs strong driver to charge and discharge. If not, slow switching causes huge losses (again voltage drop times current). For inductive load it's same as for transistor.
Relay - It must be selected carefully as switch-off causes electric arc (= burning contacts) and because of DC current it's burning for much longer time than AC.

If you're going to use a transistor make sure you use it as a high side switch

@Hayman Could you please explain reasons for this? Now it's like "because someone said so"

In most cases you can just use it either side. However as it is a reasonably sized pump I'd probably remove the power from the device rather than the ground from the device (just personal preference/intuition). That's only because of this specific circumstance however. Also a couple of other things, you can get low Vce(sat) transistors even at higher currents. A Mosfet with a drain current of 5A is going to likely need more voltage on the gate than an arduino can supply. The best choice here is a relay used with a low side NPN transsistor

I know I'm being a bit wordy now, sorry about that. Here's a good article about possible issues with low side switching

I'm not 100% sure, but could a flyback diode help with the relay situation?

The problem with a MOSFET is that at 5A you might find that the arduino output pin can't deliver enough voltage to the gate of the MOSFET to get it to fully turn on.
For the transistor, it is possible to use a transistor however it is probably best to construct it as a high side switch as opposed to a low side switch. This is to deal with potential problems that may arise with disconnecting the ground from the pump whilst running.
This is a good article which explains why low side switching can be bad
The best possible solution in this circumstance would be to use a relay connected to a NPN transistor which switches the low side of the relay. This isolates the delicate arduino electronics from the pump.

How about using a solid state relay?

@Kodak the cost of a solid state relay for the required current/control voltage is significantly more expensive


text:
How would one make a 3-wire GPS?
I want to collect GPS data with a cellular-enabled micro-controller to help me find my drone if it gets lost. My drone has GPS, so I tried to connect to it. Many GPS break-out boards have the following connections:

GND
5V/3.3V
TX
RX

Some of the time there are more, but these seem to be the essential ones. But, I'm studying a GPS module that uses only 3 wires. Take a look:

The red and black ones are power and ground. Must the remaining wire be TX?
I've been trying every way I can think of to tap into this GPS on my quad. I spliced into the 3 wires, but I only connected ground and what I suspect to be TX to my micro.

Also, at this point, I'm just curious.
I've studied the GPS a bit more and I can now see it has a compass and some other motion device. So it's not just a GPS board.
It also had it's own micro controller managing all of these devices.  I think the serial data on the wires I've tapped has been reformatted for the flight controller. It's gibberish in the arduino app.
At this point I'm ready give up and just put a second GPS on the thing!
But before I give up I wanted to ask if there are any other methods I can try to listen to the GPS.
Thanks!

Well, the "RX" pin on the GPS modules usually is pretty useless; it allows, maybe, to change the baud rate, but the GPS usually just spits out the data on the other line. So if you don't have any info just try to listen on it at different baud rates (start with 9600 and 115200, then try the other standard values). If you don't get anything, then maybe they are using a custom protocol (the ublox there is serial, but there is a uC between). So, have a look where you bought it if they tell you the protocol, then search for any identifier on the board and look on the internet

For anything like this you really do need a logic analyzer. That can tell you much about what the protocol is and allows you to decode the RS-232 coding (if that is what it is) or other protocol. You don't need to spend a lot of money - I bought a bunch of cheap chinese "USBee AX PRO" off eBay - couple of pounds each - and use the open source sigrok and pulseview with them. They absolutely rock.

If you only need the GPS data you could solder a wire direction to pin 20 of the metal-caned sub-board (Blox Neo 6M)

@Majenko I got zero results on ebay for "USBee AX PRO". I got a CY7C68013A board, but I had to replace the EEPROM to make it work as a Logic Analyzer.

@Gerben Maybe it was DealExtreme I got them from?  Ah yes, this is the one: http://www.dx.com/p/logic-analyzer-w-dupont-lines-and-usb-cable-for-scm-black-148945#.VvLELWGLTRY


text:
Can't program bareduino. "avrdude: stk500_recv(): programmer is not responding"
I've built a bareduino. The blink sketch that it came preprogrammed with worked. I was also able to program the ATmega328 by putting it into a arduino uno.
What I can't do is upload a sketch directly. I've tried both of the methods described here: https://www.virtuabotix.com/bareduino328-programming-guide/
I've used FTDI before and I know that my drivers work. I've tried suggestions from many forums and after 3 hours I'm running out of options.
The issue seems to be the reset pin. But the fixes here have not worked. I must admit I'm confused about how to un-ground the reset pin. I tried unplugging the power. When I tried to upload with FTDI I had a capacitor... so shouldn't that fix this error?
Verbose Error Code:
Sketch uses 7,920 bytes (24%) of program storage space. Maximum is 32,256 bytes.
Global variables use 383 bytes (18%) of dynamic memory, leaving 1,665 bytes for local variables. Maximum is 2,048 bytes.
/Applications/Arduino.app/Contents/Java/hardware/tools/avr/bin/avrdude -C/Applications/Arduino.app/Contents/Java/hardware/tools/avr/etc/avrdude.conf -v -patmega328p -carduino -P/dev/cu.usbmodem1d11 -b115200 -D -Uflash:w:/var/folders/r9/t7hwvgjx1kz18v8j60_kp_vh0000gn/T/build7068227750495702499.tmp/webclient.cpp.hex:i

avrdude: Version 6.0.1, compiled on Apr 14 2015 at 16:30:25
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "/Applications/Arduino.app/Contents/Java/hardware/tools/avr/etc/avrdude.conf"
         User configuration file is "/Users/futurebird/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/cu.usbmodem1d11
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00

avrdude done.  Thank you.

Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

What are your fuses set to? Where is this capacitor? It should be between RTS on the FTDI cable and Reset, and Reset should have a 10k pull-up resistor to +5V. Which bootloader is on the chip?

It's like this: https://virtuabotix-virtuabotixllc.netdna-ssl.com/core/wp-content/uploads/2012/03/arduinoserialpinout_small.jpg
It has a uno bootloader

What are the fuses set to? If you don't know you can find out with my Signature detector sketch.

Also try manually resetting the bareduino with a grounded wire shortly before or after you begin the upload. If that works, then the fault is with the the auto-reset circuit.


text:
Reading multiple NTC temperature sensors with Arduino
Hej..I am building a project with four NTC 10k ohm temperature sensor with Arduino. It is easy to measure only one NTC temperature sensor. There  is many examples for NTC measurement for example code written with Steinhart-Hart Equation or reading  ADC Thermistor with Lookup Table.
I found one example with Steinhart-Hart Formula.  I am not so good at coding  with Arduino but I Manage and build to write code for only one NTC sensor and read it with Nokia LCD 5110.  The question is how to do code for Multiple NTC sensors?
/* NTC temperature mesurment 13-08-2017
 *
 *  Using Nokia LCD 5110
 */

#include "LCD5110_Graph.h"
LCD5110 myGLCD(8, 9, 10, 12, 11);  // Setup Nokia 5110 Screen SCLK/CLK=5, DIN/MOSI/DATA=6, DC/CS=7, RST=8 Chip Select/CE/SCE=9,
extern uint8_t SmallFont[];
extern uint8_t MediumNumbers[];

int tempPin = 0;   // A0 analog input
int Vout, charTc ;
float R1 = 10000; //otpornost na sobnoj temperaturi 10K ili 10000 oma
float R2, Tk, Tc;
float Ac = 1.009249522e-03, Bc = 2.378405444e-04, Cc = 2.019202697e-07;
char charBuffer[10];

void setup(){
myGLCD.InitLCD(); //initialize LCD with default contrast of 70
myGLCD.setContrast(68);
myGLCD.setFont(SmallFont); // Set default font size. tinyFont 4x6, smallFont 6x8, mediumNumber 12x16, bigNumbers 14x24
myGLCD.clrScr();

myGLCD.print("Temp test",CENTER,0);
myGLCD.print("Check",CENTER,12);
myGLCD.print("Please Wait",CENTER,24);

myGLCD.update();
delay(5000);
myGLCD.clrScr();
}

void loop() {
  Vout = analogRead(tempPin);
  R2 = R1 * (1023.0 / (float)Vout - 1.0); // konvertovanje iz analogne u digitalnu
  Tk = (1.0 / (Ac + Bc*log(R2) + Cc*log(R2)*log(R2)*log(R2))); // Temperature in Klven
  Tc = Tk - 273.15; //temperature converted to celcious

charTc=dtostrf(Tc, 3, 2, charBuffer);

  myGLCD.clrScr();
  //myGLCD.print("Discharging",CENTER,0);
  //myGLCD.print("Temperature:",CENTER,0);
  myGLCD.print("Temp1:",0,0);
  //myGLCD.print( charTc,CENTER,20 );
  myGLCD.print( charTc,36,0 );
  myGLCD.print("Temp2:",0,10);
  myGLCD.print("Temp3:",0,20);
  myGLCD.print("Temp4:",0,30);
  myGLCD.update();
  delay(2000);
  myGLCD.clrScr();
}

The row int tempPin = 0; // A0 analog input specify which analog input that should be used as input for reading the NTC value. Then you can expand the code with the analog inputs that is needed.

Thanks for you reply. Yes i know that Arduino has 8 ADC input. But my desire is how to do interval time execution for many ADC input. Is it best way to write timer interrupt? for every analog input to Execute every 2 seconds if the reading is changed of adc?

The row int tempPin = 0; // A0 analog input specify which analog input that should be used as input for reading the NTC value.
Then you can expand the code with the analog inputs that is needed.

Arduino UNO has 6 Analog pins ..
Sequentially Read ADC every 2 seconds either by calling the Respective ADC functions inside a TIMER_INTERRRUPT_VECTOR() or if high Accuracy is not Required you can restrict your main loop() to be small and write all ADCs inside it.
Also make sure that you sample your ADC if writing inside loop to make sure that its accurate.

Yes..both the ways it can be done ,writing in loop is simple but it's always better to make your loop () run at shortest time..if planning to modify the code in future .one more option is to create individual tasks and make all ADCs run independently but little complicated

As I understand, you have multiple analog sensors you want to read. So your code should look something like this:
// assuming sensors are on A0, A1, A2, Ax

sensorPins [] = {A0, A1, A2};
int sensorNum = 3;

for(int x = 0; x < sensorNum; x++){
  readSensor(x);
}

Something like that should work for you.

Put in multiple analog input pins and read them sequentially;
Put in multiple analog input pins and scan them in the adc interrupts.

the first approach is quite simple and the 2nd approach requires a thorough read of the datasheet.

This is pretty simple. Create an array of uint_8 variables that contains your pin numbers.
Then write a function that takes a pin number as an input, reads the ADC, does the math, and returns a value.
sensorPins [] = {A0, A1, A2, A3};

float readTemp(int tempPin) {
  int Vout = analogRead(tempPin);
  float R2 = R1 * (1023.0 / (float)Vout - 1.0); // konvertovanje iz analogne u digitalnu
  float Tk = (1.0 / (Ac + Bc*log(R2) + Cc*log(R2)*log(R2)*log(R2))); // Temperature in Kelven
  Tc = Tk - 273.15; //temperature converted to Celsius
  return Tc;
}

Then write a loop that loops through your array of pin numbers and calls the readTemp function.


text:
how fast does loop() run in Arduino
Hi I am using Arduino Nano to gamify my experience on Unity3D. I know that Update() in Unity3D runs every frame per second but I because I'm not an electronics guy I don't know how loop() function runs on Arduino.
Does it depends on number of CPU cycles(or micro processor chip in case of Arduino) or what? Please explain. I facing some lags in my game. I can fix them only if know how is loop() function running on Arduino
There ain't a lot of information about loop() in arduino documentation

"runs every frame per second" not sure you completely understand frames, or maybe just a typo. but in Unity3D each frame runs as fast as possible, they don't purposefully but a delay in the frame

put a delay in the frame (can't edit it? thought i could)

Looks like the short answer is "as fast as possible".

Loop runs as long as loop needs to run.
Instructions in a CPU run sequentially. The more instructions there are the longer it takes to run.
The more code you put in loop the longer loop will run.
There are two ways to know how long each iteration of loop will take:

Profiling: Actively time each iteration of loop, though be warned, the act of timing will affect the amount of time taken.
Cycle counting. Compile the source into assembly and total up the number of clock cycles needed for all the instructions (including calls to functions). Arduous for small loops, a gargantuan task for anything else.

Also note that many external factors can affect how long loop() takes to run - such as serial communication speed, etc.

Don't forget interruptions for example updating the millis value every 16000 clock cycles (for 16Mhz oscilator). They stop execution of program in regular intervals and prevent the arduino from being a good PWM source. (yes you can turn them off)

@FilipFranik: 1. The interrupt that updates the millis() value runs every 1024 µs, or 16384 CPU cycles at 16 MHz. 2. Interrupts affect the quality of software PWM output (e.g., the Servo library). They have no effect on hardware-generated PWM (e.g., with analogWrite()).

the instructions between the end of loop() and the next run of it are a ret, jmp and a call.
You can consider the main function to be effectively:
void main(){

    init();
    while(1) loop();

}

Though in reality there is some setup done before init() to make millis() and such work.

Also you have serial event code after loop.

@Majenko isn't that done with interrupts?

No, it's not. It's just called at the end of loop. It's very crude and many people don't understand just how pointless it really is.

I think the loop() is optimized by the compiler, so no actual jmp or ret occur. The code translates to: while (1) yourLoopCode; without function call. But I saw horrible dumb things with GCC...

The more I look at the standard runtime of an arduino the more I am dissapointed...

@next-hack: Newer versions of the Arduino IDE call gcc with the -flto option, which enables link-time optimization and may result in loop() being inlined. Older versions do not use this option, so loop() gets compiled into a real function, which is repeatedly called by main().

A look at main.cpp (for avr code in my installation) in file:
C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino\main.cpp

shows that the Arduino runs loop() alternately with serialEventRun() in an infinite loop:
int main(void)
{
    init();
    initVariant();
 #if defined(USBCON)
    USBDevice.attach();
#endif

    setup();

    for (;;) {
        loop();
        if (serialEventRun) serialEventRun();
    }

    return 0;
}

Inspection of HardwareSerial.cpp shows that serialEventRun() simply calls serialEvent(), if you have defined it in your sketch.
This means that you can write your own infinite loop within loop() perfectly safely, unless you have written serialEvent() code and are expecting it to run regularly.
This begs the question: if serialEvent() is called sequentially with loop(), will serialEvent() be called if loop() never returns? In other words, is serialEvent() interrupt-driven as well as being called when loop() returns?  A quick test -see below- shows that it is not interrupt-driven, so the previous paragraph is true.
/*
  Serial Event Checker

  A sketch to see if serialEvent() is interrupt-driven.
  Will serialEvent() be called if loop() never returns?

  This code is based on Tom Igoe's SerialEvent example.

  On (at least) Arduino Uno we find that serialEvent() simply runs
  sequentially with loop().  When loop() never returns serialEvent()
  is never called.

  NOTE: The serialEvent() feature is not available on the Leonardo, Micro, or
  other ATmega32U4 based boards.

  R Symonds-Tayler 2018-02-01

  This example code is in the public domain.

*/

String inputString = "";         // a String to hold incoming data

void setup() {
  // initialize serial:
  Serial.begin(115200);
  // reserve 200 bytes for the inputString:
  inputString.reserve(200);
}

// comment out this definition to allow loop() to return
#define INFINITE_LOOP

void loop() {
#ifdef INFINITE_LOOP
    while(1);
#endif

}

/*
  SerialEvent occurs whenever a new data comes in the hardware serial RX. This
  routine is run between each time loop() runs, so using delay inside loop can
  delay response. Multiple bytes of data may be available.
*/
void serialEvent() {
  while (Serial.available()) {
    // get the new byte:
    char inChar = (char)Serial.read();
    // add it to the inputString:
    inputString += inChar;
    // if the incoming character is a newline, set a flag so the main loop can
    // do something about it:
    if (inChar == '\n') {
      Serial.print("Got: '");
      Serial.print(inputString);
      Serial.println("'");
      // clear the string:
      inputString = "";
    }
  }
}

This means that serialEvent() code might just as well go into your main loop() within a:
if(serial.available()){
   // your code here...
}

block.

It depends on what's in the loop. From a few clock cycles to infinite hang.

try looking up arduino functions
micros()
and
delayMicroseconds()
If you might need your loop to wait longer than 16000 microseconds then also look up the other delay() function which does milliseconds.
By the way, the internal clock is very slightly off and varies with room temperature, so don't rely on it staying synchronised to your other device without a handshake.

micros() and delayMicroseconds() use 32-bit integers (unsigned long) and can manage durations up to 2³² µs, or about 1.19 hours.

In this article bri_huang made a nice experiment using an oscilloscope and simple write functions.
He calculated the speed of the loop to be 117 kHz even though the microcontroller has a 16 MHz clock.
https://learn.sparkfun.com/blog/1687

That link does not really say a lot about how “fast” loop() is (which I.M.O. Is meaningless), but only how fast the Arduino implementation of digitalWrite() is (which is not exactly the fastest way to toggle a pin on the Arduino).

So no satisfactory answer yet? Or can we assume it runs at the speed of the crystal oscillator?

@Alejandro Camus It has a billion factors all the way from temperature of your room to how much load is the microprocessor is handling, we cannot even say that it runs at the speed of the oscillator as commands take time to do

That is a good test of how fast digitalWrite() works; not a good test of how fast loop() loops. In that test, they're benchmarking digitalWrite(), with no reasonable expectation that it's a single clock cycle or a single instruction.

Yep, points taken


text:
Problem with 16x2 LCD using Arduino
I've connected the circuit as shown in
https://www.arduino.cc/en/Tutorial/HelloWorld?from=Tutorial.LiquidCrystal
and I ran the program, but I can't fix this problem:
the LCD seems not to respond correctly: the first row is black and for what concerns the elements of the second, they all have three top lines of pixel high and the others low..
I checked over and over if I made some mistake connecting wires but I haven't found any error..
Is the LCD broken according to you? How can I fix?
Here the photos of the circuit:
https://drive.google.com/open?id=0B2h2zzEgtaqydElrRDVUNGVuWDA

Where's the sketch?

I looked the images you have on Google Drive. On the image called IMG_20170822_233722.jpg, I see you are using a 50k ohm potentiometer to control the display contrast. Normally you would use a 10k ohm potentiometer. Using the 50k will make the adjustment very sensitive and hard to adjust. If you are careful and adjust it slowly, it might work for you.
The other image, IMG_20170822_234242.jpg, clearly shows "poor solder joint" connections on the display. D4 - D6 (especially D5 to D6) look like they could be "shorted" together. I think you could fix them by using Desoldering braid or if you don't have any, you could heat up each connection with your soldering iron then quickly "flick" the display to remove the solder. After you have removed the excess solder from each connection, I strongly recommend applying soldering paste to the connections next. The soldering paste really helps the solder to flow into the connection. Now try re-soldering each connection. I'm not sure what kind of solder or iron you are using but I can tell you what works for me. 25 watt pencil tip soldering iron with 22 gauge / 0.71mm rosin core solder.
I can't tell for sure from the pictures if any of the display pins are shorted together and I don't know if shorting them together will damage the display, Arduino or both.

Yes the soldering look cold and there is too much solder on it. https://cdn-learn.adafruit.com/assets/assets/000/001/978/medium800/tools_Header_Joints.jpg?1396777967 look at this for reference, and practice practice practice.

Black first row suggests that the LCD is incorrectly initiated. That's often caused by wrong code or wrong hardware / connection.


text:
Is it possible to charge a battery using a water flow sensor?
Is it possible to use a water flow sensor to charge a battery? Since the water flow sensor measures water flow using pulses, could I charge a battery using these pulses(instead of using it to read water flow).
Heres an example of the product?
https://netram.co.za/1200-g-12-water-flow-sensor-13mm.html
Thank you

Is it possible to charge a battery using a water flow sensor?

No, it is basically a hall-effect sensor that requires power and generates a low effect pulse.
Look for a generator. Something like this; https://netram.co.za/1199-36v-micro-hydro-generator.html
Cheers!

Thanks so much Mikael.  This helps me a great deal!  Especially that you went through the effort on showing me on the site I used.


text:
Arduino Due works perfectly on Windows but doesn't on Linux (SAM-BA operation failed)
I've been working with the Arduino Due for a project, we have been setting up these Arduinos with an ARM Board that hosts a Linux System with Busybox that connects to the Arduino. Recently I got assigned the job of making it possible for the Arduino Due to be updated with the new code remotely so we don't have to travel to each location every time we need to update anything.
At first it seemed easy, crosscompile bossac for Arduino Due and use it in the ARM Linux Board, needing to open the port at 1200 bauds so the Arduino is available for a new upload.
The problem is, i've tested bossac and it works perfectly on Windows same as the Arduino IDE, it always uploads the sketch without a single problem. On Linux, however it doesn't seem to be working properly, not even the full Arduino IDE in AMD64, we have already tested it in 2 Vbox with Linux and in 2 native Linux installations, testing 32b and 64b, ARM and x86, i've tested everything I've seen on the web: up the permissions, add the user to the dialout group, reset the board manually...
I'm sure i'm missing something stupid but I don't know what and it's driving me crazy because the Arduino IDE is supposed to work properly on Linux. Just in case, these are the steps I've followed:

Download the latest version of the Arduino Due, untar it and sudo ./install.sh
Add my user to the dialout group, and log out.
In the Arduino IDE go to the Board Manager and install the SAM support for Arduino Due
Select Arduino Due (programming port) and /dev/ttyACM0
Upload any sketch (also tried with example sketches), it compiles but when uploading the next message appears

SAM-BA operation failed

And if using the verbose output this always happens after the next output,it seems to fail the last write and tries to overwrite it again (this is not the full output, there are writes and reads before this)
Chip ID      : 285e0a60
version()=v1.1 Dec 15 2010 19:25:04
Version      : v1.1 Dec 15 2010 19:25:04
Address      : 524288
Pages        : 2048
Page Size    : 256 bytes
Total Size   : 512KB
Planes       : 2
Lock Regions : 32
Locked       : readWord(addr=0x400e0a08)=0x1
readWord(addr=0x400e0c08)=0x1
writeWord(addr=0x400e0a04,value=0x5a00000a)
readWord(addr=0x400e0a08)=0x1
readWord(addr=0x400e0c08)=0x1
readWord(addr=0x400e0a0c)=0
readWord(addr=0x400e0a08)=0x1
readWord(addr=0x400e0c08)=0x1
writeWord(addr=0x400e0a04,value=0x5a00000a)
readWord(addr=0x400e0a08)=0x1
readWord(addr=0x400e0c08)=0x1

Almost every time it crashes it's like that but sometimes it even starts uploading and showing the percentage of upload but again "SAM-BA operation failed" before finishing the upload.
What irks me is that in Windows it works flawlessly so the board is all good and even compiling bossac from the sources produces the same error in Linux, I've also tested an Arduino Duemilanove and it works perfectly on Linux however it uses avr, not bossac. As i've said i've tested it in 4 machines and it's always the same, even in the ARM version.
What is it that I'm missing?
Thanks in advance.

Uninstall the modem-manager package from Linux.

Tried it doing apt-get purge modemmanager and still no luck, it keeps saying SAM-BA operation failed, I have also tested it on a new Due and the same thing happens.


text:
Attempt stacking 'CAN-BUS' and 'USB Host' Shields on Mega 2560
I've run into a case of 'In theory it works, but in reality'....
I'm using the CAN-BUS Shield V1.2 from Seeed studio. Many things are written in broken english, so I'm starting to wonder if I can trust all of the information. http://wiki.seeed.cc/CAN-BUS_Shield_V1.2/
The USB Host Shield is a discontinued official Arduino model. https://www.arduino.cc/en/Main/ArduinoUSBHostShield
(I would link to the libraries, but I am unable to post more than 2 links)
CAN-BUS Pins:
AREF
ICSP (SCK, MISO, MOSI)
P9 - CS (SS)
P2 - INT
NC
IOREF
RST
3.3V
5V
Vin

USB Host Pins:
ICSP (SCK, MISO, MOSI)
P10 - SS
P7 - GPX
P8 - INT (actually RES?)
P9 - RES (actually INT?)

The only conflict I see is Pin 9 (CS on CAN, RES on USB). This is where it gets hazy... While the documentation on the bottom of the USBHost page implies that Pin 9 is RES, in the code Pin 9 is actually INT.
So, assuming Pin 9 is actually INT, I re-routed it to Pin 45 on on the Mega and changed it in the UsbCore.h file:
//typedef MAX3421e<P10, P9> MAX3421E; // old
typedef MAX3421e<P10, P45> MAX3421E; // new

Here is a snippet of the code I am running:
#include <PS3BT.h>
#include <usbhub.h>

#ifdef dobogusinclude
#include <spi4teensy3.h>
#include <SPI.h>
#endif

#include <Bounce2.h>
#include <Time.h>
#include <TimeLib.h>
#include <SPI.h>
#include "mcp_can.h"

const int SPI_CS_PIN = 9;

MCP_CAN CAN(SPI_CS_PIN); // Set CS pin

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

    // THIS WORKS
    if (Usb.Init() == -1) {
        Serial.print(F("\r\nOSC did not start"));
    }
    Serial.print(F("\r\nPS3 Bluetooth Library Started"));

    // THIS FAILS
    while (CAN_OK != CAN.begin(CAN_500KBPS))
    {
        Serial.println("CAN BUS Shield init fail");
        Serial.println(" Init CAN BUS Shield again");
        delay(100);
    }
    Serial.println("CAN BUS Shield init ok!");
}

The CAN-BUS Fails to init until I physically remove the USB Host Shield.
If I remove the CAN-BUS code, The USB Host Shield functions normally.
If I remove the USB Host code, the CAN-BUS Shield still DOES NOT init.
I tried to sift through the CAN-BUS init code a little, and I can only assume it's failing to communicate via SPI. What am I missing here?

I think that there is an hardware bug on the USB Master shield:
IC3, the 3-state buffer which converts MISO to 5V, is always active...
The enable pin of this 74LVC1G125 (pin 1) should be connected to the pin ss_3V3.
Then you can stack this shield with another one.

It definitely feels like a hardware bug! I haven't circled back to address this in a while - I'll respond after I try this fix.


text:
I already have a button on my Arduino board, but I don't know what pin number should I use in my code?
I'm attaching a picture of my board which has the push button I want to use, but I cannot because I don't know what pin number should I write in my code.
my code:
int switchPin = Button;
int ledPin =13;

void setup() {
  // put your setup code here, to run once:
pinMode(switchPin, INPUT);
pinMode(ledPin, OUTPUT);
}

void loop() {
  // put your main code here, to run repeatedly:
if(digitalRead(switchPin) == HIGH)
{
  digitalWrite(ledPin, HIGH);
}
else
{
  digitalWrite(ledPin, LOW);
}
}

This is a picture shows the button on the top right "green"

Datasheet says?

What does the user manual say? I assume you have read it?

it doesn't have manual with it!

and I looked online, but I couldn't find one!

Abdulrahman, what's the name of the board, or what identifying text is on it, or what do you think it's called?

I could find this link refrencing that "mCore" board: http://www.makeblock.com/mcore-main-control-board-for-mbot/ However, I'm not sure there is a datasheet (could not find one).

The schematic at makeblock.com of the mbot mcore board shows switch S3 feeding pin A7, which is an analog input pin.  Note, there is a deplorable 0.1 μF capacitor in parallel across S3, probably intended as hardware-level debouncing.
Also see the Port wiring mBot mCore board thread on the Makeblock forum, where one of the posts says there are multiple versions of the board, and provides reference links.
For example, sample code at
newinnovators.ca's “mblock-to-arduino/button-control” page (Dead link) shows pin 2 being used to sense the button.  You may need to run some tests.


text:
Coding for a stop button
I'll like to code for a game, and it'll come with a stop option that allows the player to exit/restart the game.
How should I code for that stop button? Do I put it in a separate while loop under the void loop?

You can use an interrupt function.
https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/

One of the easiest ways to restart your game is to use the inbuilt reset line. The Arduino Uno/Due/M0/101 has a physical reset button next to the USB connector. For some of the other baords like the Arduino Mega, it is closer to the chip in the middle of the board.
The reset line is held high by a pull up resistor. This button shorts the reset pin to Gnd, resetting the microcontroller.
Once reset, the microcontroller starts up again as if it has just been powered on. This has the advantage of saving on adding code to handle the game being reset.

Note that the reset line is also available on a pin header, which can be handy if the OP prefers to wire his own button.

There are lots of possible approaches. One possibility would be to set up your code something like this:
enum { STOPPED, PLAYING } flag;

void setup() {
  // setup stuff ...
  flag = STOPPED;
}

void loop() {
  while (flag == STOPPED)
  {
    // wait for start button
    if (start button pressed)
    {
      // initialise the game ...
      flag = PLAYING;
    }
  }

  while (flag == PLAYING)
  {
    // play the game
    if (stop button pressed)
    {
      flag = STOPPED;
    }
  }
}

And I need to put this code at the beginning of loop()..?

If you code your loop without delay() or busy loops then it is pretty easy:
void loop(){

    if(DigitalRead(RESET_BUTTON)){
       // Reinitialize game state

    }

    //rest of game logic.

}


text:
Midi Program not sending notes
I'm working on a midi device with a pro micro, it's reading as a midi device, but not outputting any notes, here's my program:
    const int button1 = 2;
    const int button2 = 3;
    const int button3 = 4;
    const int button4 = 5;
    const int button5 = 6;
    const int button6 = 7;
int note = 0;

const int c3 = 36;
const int d3 = 38;
const int e3 = 40;
const int f3 = 41;
const int g3 = 43;
const int a3 = 45;

void setup() {

  pinMode(button1,INPUT);
  pinMode(button2,INPUT);
  pinMode(button3,INPUT);
  pinMode(button4,INPUT);
  pinMode(button5,INPUT);
  pinMode(button6,INPUT);

  Serial.begin(31250);

}

void loop() {
  int button1State = digitalRead(button1);
  int button2State = digitalRead(button2);
  int button3State = digitalRead(button3);
  int button4State = digitalRead(button4);
  int button5State = digitalRead(button5);
  int button6State = digitalRead(button6);

  if (button1State == HIGH) {
    note = c3;
    noteOn(0x90, note, 0x64);
  }
  if (button1State == LOW) {
    note = c3;
    noteOn(0x90, note, 0x00);
  }

  if (button2State == HIGH) {
    note = d3;
    noteOn(0x90, note, 0x64);
  }
  if (button2State == LOW) {
    note = d3;
    noteOn(0x90, note, 0x00);
  }

  if (button3State == HIGH) {
    note = e3;
    noteOn(0x90, note, 0x64);
  }
  if (button3State == LOW ) {
    note = e3;
    noteOn(0x90, note, 0x00);
  }

  if (button4State == HIGH) {
    note = f3;
    noteOn(0x90, note, 0x64);
  }
  if (button4State == LOW) {
    note = f3;
    noteOn(0x90, note, 0x00);
  }

  if (button5State == HIGH) {
    note = g3;
    noteOn(0x90, note, 0x64);
  }
  if (button5State == LOW) {
    note = g3;
    noteOn(0x90, note, 0x00);
  }

  if (button6State == HIGH) {
    note = a3;
    noteOn(0x90, note, 0x64);
  }
  if (button6State == LOW ) {
    note = a3;
    noteOn(0x90, note, 0x00);
  }

}

void noteOn(int cmd, int pitch, int velocity) {
  Serial.write(cmd);
  Serial.write(pitch);
  Serial.write(velocity);
}

You are handling your buttons in completely the wrong way. You are basically saying:

While I press this button send a constant stream of NOTE ON commands. Otherwise send a constant stream of NOTE OFF commands.
At the same time, send more NOTE OFF commands because the other buttons aren't pressed.

So you can see it's going to be a bit of a mess.
Instead you need to detect changes in the state of a button.
For example:
void loop() {
    static bool oldButton1 = LOW;

    bool button1State = digitalRead(button1);

    if (button1State != oldButton1) { // It changed from last time
        oldButton1 = button1State; // Remember it for next time
        if (button1State) { // Pressed
            noteOn(0x90, c3, 0x64);
        } else { // Released
            noteOn(0x80, c3, 0x00); // Note: 0x80 is NOTE OFF, not 0x90.
        }
    }

    ... etc for the other buttons ...
}

Check:

If your serial properties are ok (baudrate 31250, 8 bits, 1 stop bit)
Check if noteOn is really called (print out the values which are sent)
Show your MIDI circuit, assuming you think no MIDI notes are send because you have a MIDI connector attached.
Use a protocol analyzer if you have one to check the MIDI signals sent
Check the components of your circuit, e.g. if you use an opto-coupler, what types is it? some are too slow for MIDI
Do not use virtual serial ports, I tried with MIDI and they give bad results (checked on Uno).


text:
Breaking out of while loop using IR remote input
I'm trying to control a series of LEDs using an IR remote. I have a problem when I try to play a sequence with the LEDs where they all light up in a line and turn off accordingly. I loop through the sequence and I am trying to make it so the instant I press a button on the remote it breaks out of that sequence. The issue lies in the Flash(); function, I think. What can I do?
#include <boarddefs.h>
#include <IRremote.h>
#include <IRremoteInt.h>
#include <ir_Lego_PF_BitStreamEncoder.h>

int recvPin = 11;
IRrecv irrecv(recvPin);
decode_results results;

#define BUTTON_ON 0xF076C13B    // codes for different buttons on the remote
#define BUTTON_OFF 0xFF9186B7
#define BUTTON_R 0xE5CFBD7F
#define BUTTON_G 0x8C22657B
#define BUTTON_B 0x2A89195F
#define BUTTON_FLASH 0x35A9425F

int rLED = 5;
int gLED = 4;
int bLED = 3;
int stR = LOW;  // intital state of red LED
int stG = LOW;  // intital state of green LED
int stB = LOW;  // initial state of blue LED
int flash = false;

void setup() {
  Serial.begin(9600);   // Status message will be sent to PC at 9600 baud
  pinMode(rLED, OUTPUT);
  pinMode(gLED, OUTPUT);
  pinMode(bLED, OUTPUT);

  irrecv.enableIRIn();
}

void Flash() {    // flashing function
  while (flash == false) {
    digitalWrite(rLED, LOW);
    digitalWrite(gLED, LOW);
    digitalWrite(bLED, LOW);
    digitalWrite(rLED, HIGH);
    delay(75);
    digitalWrite(gLED, HIGH);
    delay(75);
    digitalWrite(bLED, HIGH);
    delay(75);
    digitalWrite(rLED, LOW);
    delay(75);
    digitalWrite(gLED, LOW);
    delay(75);
    digitalWrite(bLED, LOW);
    delay(75);
    stR = LOW;
    stG = LOW;
    stB = LOW;
    if (results.value == BUTTON_OFF)    // attempting to make it so when i press the OFF button on the remote,
    {                                   // the loop breaks/stops and I can go back to pressing any button on
      break;                            // the remote
    }
  }
}

void loop() {
  if (irrecv.decode(&results))
  {
    if (results.value == BUTTON_ON)
    {
      digitalWrite(rLED, HIGH);
      digitalWrite(gLED, HIGH);
      digitalWrite(bLED, HIGH);
      stR = HIGH;
      stG = HIGH;
      stB = HIGH;
    }
    if (results.value == BUTTON_OFF)
    {
      digitalWrite(rLED, LOW);
      digitalWrite(gLED, LOW);
      digitalWrite(bLED, LOW);
      stR = LOW;
      stG = LOW;
      stB = LOW;
    }
    if (results.value == BUTTON_R)
    {
      digitalWrite(rLED, !stR);
      stR = !stR;
    }
    if (results.value == BUTTON_G)
    {
      digitalWrite(gLED, !stG);
      stG = !stG;
    }
    if (results.value == BUTTON_B)
    {
      digitalWrite(bLED, !stB);
      stB = !stB;
    }
    if (results.value == BUTTON_FLASH)
    {
      Flash();    // calling flash func
    }
    irrecv.resume();
  }
}

Replace delay with millis in Flash().
You do this by making every delay it's own state and give each state a number. Then inside flash you check which state you are in to set the LEDs and how long you have been in it to trigger the next state.
boolean flashing = false;
int flashingState = -1;
long nextFlashingState = 0;

void Flash() {    // flashing function
  if(!flashing ){
    flashingState =-1;
    return;
  }

  long ms = millis();
  switch(flashingState ){
  case -1:
    flashingState =0;
    nextflashingState = ms+75; //init "timer"
    //fallthrough
  case 0:
    digitalWrite(rLED, LOW);
    digitalWrite(gLED, LOW);
    digitalWrite(bLED, LOW);
    digitalWrite(rLED, HIGH);
    if(nextflashingState < ms){
        flashingState =1;
        nextflashingState +=75;
    }
    break;
 case 1:
    digitalWrite(gLED, HIGH);
    if(nextflashingState < ms){
        flashingState = 2;
        nextflashingState +=75;
    }
    break;
 case 2:
    digitalWrite(bLED, HIGH);
    if(nextflashingState < ms){
        flashingState = 3;
        nextflashingState +=75;
    }
    break;
  case 3:
    digitalWrite(rLED, LOW);
    if(nextflashingState < ms){
        flashingState = 4;
        nextflashingState +=75;
    }
    break;
  case 4:
    digitalWrite(gLED, LOW);
    if(nextflashingState < ms){
        flashingState = 5;
        nextflashingState +=75;
    }
    break;
  case 5:
    digitalWrite(bLED, LOW);
    if(nextflashingState < ms){
        flashingState = 0;
        nextflashingState +=75;
    }
    break;
  }
}

I used state -1 as the init state to start the timer, the case block will fall through to the next case. The millis() function returns the number of milliseconds since the arduino booted up (it overflows every ~1.5 months). So when I start a timer I set the the nextFlashingState to the time when it should start the next state.
Then in loop you call it every time.
void loop() {
  if (irrecv.decode(&results))
  {
    if (results.value == BUTTON_ON)
    {
      digitalWrite(rLED, HIGH);
      digitalWrite(gLED, HIGH);
      digitalWrite(bLED, HIGH);
      stR = HIGH;
      stG = HIGH;
      stB = HIGH;
    }
    if (results.value == BUTTON_OFF)
    {
        flashing =false;
      digitalWrite(rLED, LOW);
      digitalWrite(gLED, LOW);
      digitalWrite(bLED, LOW);
      stR = LOW;
      stG = LOW;
      stB = LOW;
    }
    if (results.value == BUTTON_R)
    {
      digitalWrite(rLED, !stR);
      stR = !stR;
    }
    if (results.value == BUTTON_G)
    {
      digitalWrite(gLED, !stG);
      stG = !stG;
    }
    if (results.value == BUTTON_B)
    {
      digitalWrite(bLED, !stB);
      stB = !stB;
    }
    if (results.value == BUTTON_FLASH)
    {
        flashing =true;
    }
    irrecv.resume();
  }

  Flash();
}

Thanks for the answer! I don't really understand your code, however, I uploaded it and it doesn't seem to do what I wanted it to do. When I press the flash button on the remote, it still flashes endlessly, but now when I press something on the remote the lights do kinda respond to it but keep flashing endlessly.

it will stop flashing when you press off. If you add flashing =false; to the other if blocks then flashing will stop when that button is pressed

Alright, thanks, it works! I wonder how I will make it work with more complicated sequences but for now I do wanna understand what you did there in the void Flash() function and anything else you added cause I am a beginner and if you could possibly refer me to some website where I can learn more about this I would greatly appreciate it :)

@EdD I edited my answer to explain a bit how you would go about replacing delay with millis


text:
PWM output maximum current
i made a project with arduino in wich I used arduino to activate 18 n-ch mosfet with PWM. I used the softPWM library to use PWM in 18 output pins, I used a nano v3.
The question is about the maximum current a single pin (and a group) can handle. A raw info can be found here http://www.pighixxx.com/test/wp-content/uploads/2014/11/nano.png and it's a 20mA/pin and 200mA/group but it's not explained if that current is a peak current or an average current.
Increasing the load resistor will case a smaller peak current but will increase the time in wich the mosfet is resistive (hence it will heat up the mosfet). Considering that the pwm frequency is lower than the one defined by the resistor-mosfet, the average drained current is related to the PWM frequency and to the mosfet capacitor (NOT to the load resistor).
Is the current defined as maximum peak current or as continuous current (and which is a typical peak time for the CPU)?
Mr google gives me different and contradictory informations, i found people that uses PWM without load resistors and people that limit the peak current to 20mA. In my project i limited the maximum current to 50mA so I'm sure to have the worst performance i can have keeping the risk of burning my small friend.
Thanks

What is the PWM frequency? If it's quite small, you can afford that, for a certain amount of time, the MOSFET is not fully ON/OFF.

I set a 250Hz frequency to trimmer leds and a 256 resolution hence the load must be faster than 15us. I used an IRLZ44N (1700pF) that with a resistor of 100ohm means a tau=1.7E-7s that is 90times less than the previous one. If I use a 330ohm resistor the value is 26times less. Note that 250Hz is the minimum to avoid flickering

If we were talking about DACs, a DNL error <1/4 LSB would be good for many applications. We can use a similar thinking here. You want the turn-on+turn-off faster than 15us. Let's suppose 4 times faster (similar error of the DAC example). So you can increase the resistors accordingly. The problem is, the slower the transition, the larger the power dissipated. Even if half the LED power were dissipated on the MOSFETs during the 15/4 us transition, the average power dissipation on the MOSFET would be 1/2048 of that of the LED (+Ron*I^2). It's up to you to decide if it's acceptable.

if you're using mosfets, the supply capability of the gpio isn't important. you would still have actual spikes of 50, but the accumulated heat would be that of only 20ma on avg

@dandavis That's the point of the question: could i have a spike of 200mA to charge the 1700pF or not? Higher the current shorter the time, if it's all related to heating the resistor should not matter. But is it true? Can i load a 8uF capacitor with a 250Hz PWM? (8uF -> 40uC -> 0.02C/s -> 20mA)


text:
How do I make the HC-05 bluetooth module take data from the HC-SRO4, and then send it to my Android app?
Currently, I have an Arduino Uno set up, with a HC-SRO4 ultrasonic sensor printing distances of objects in front of it on a scale from 1-15 to the serial monitor. I want to attach the HC-05 bluetooth module and do the following:
First, it will read the values from the serial monitor. Then, I would like the HC-05 module to take these numbers and continuously send it to my Android app, which will then process what to do with the numbers.
I understand the Android part may be out of scope of this forum, but please try to help me with taking data from the serial monitor and have it transmit the data.
Here is the code I have for the ultrasonic sensor:
const int trigPin = 9;
const int echoPin = 10;
// defines variables
long duration;
int distance;
void setup() {
  pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
  pinMode(echoPin, INPUT); // Sets the echoPin as an Input
  Serial.begin(9600); // Starts the serial communication
}
void loop() {
  // Clears the trigPin
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  // Sets the trigPin on HIGH state for 10 micro seconds
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  // Reads the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);
  // Calculating the distance
  distance = duration * 0.034 / 2;
  // Prints the distance on the Serial Monitor
  Serial.print("Distance: ");
  Serial.println(distance);
}

What is the actual code used to get the HC-05 to transmit the data so that my Android app can pick it up?

You're using an uno so you'll need to use the software serial library. Get the hc05 working with software serial. Run a Bluetooth terminal monitor on your Android and make sure you can see the hc05 output.

First, it will read the values from the serial monitor. Then, I would like the HC-05 module to take these numbers and continuously send it to my Android app, which will then process what to do with the numbers.

No. What you do is you connect your Bluetooth module to two digital pins, which you'll use, along with the SoftwareSerial library, just the way you are using currently the Serial object. Look at the SoftwareSerial examples in the IDE.
Before you use the HC-05 module, and transmit data, you'll have to make sure it is set up properly (baud rate, name, PIN code, etc). Plenty of code and tutorials on Google about that.

Use software serial library and connect your HC-05 TX RX pins accordingly, to transmit/recieve the ultrasonic data using bluetooth. From playstore you will get bluetooth terminal software. Install it in your smart phone. Now connect your phone's bluetooth to HC-05 using that software. Now you can see in that app, all data you are receiving via bluetooth. you can also transmit data using that app. If you want to develop your own app, maybe you can check out MIT app inventor. Simple and fast.


text:
Connecting a servo via HC05 and HC06
I want to drive a servo via a HCO6 and HC05 link as a stand alone, using no android or PC.
The question is how to send a 1.5 ms signal (generated with a pulse command on a Nano) from one HC to another HC (to which my servo will be connected) ?
I do not need to care about passwords in my linking. No text to be sent, just the 1ms to 2 ms signal, at a refresh rate of 50 Hz.
I will use the HC with a OOK modulation (on - off on the data pin)?
How to achieve this ?
Thanks !

HC devices are serial. What makes you think you can use other signal formats?

The firmware associated with those model numbers implements a serial interface.  The hardware itself could be reprogrammed to another purpose, but that would be far beyond the scope of the Arduino site.

You cannot. You will need an Arduino at the servo end to generate the PWM signal from serial instructions sent over Bluetooth.
Since PWM is (typically) 8-bit and serial is (typically) 8-bit you could simply have each byte as a 1:1 mapping to a PWM value.
One the transmit end:
bluetoothSerial.write(pwmValue);

On the receive end:
if (bluetoothSerial.available()) {
    analogWrite(9, bluetoothSerial.read());
}

Yes, though one could use something like an ATtiny instead of a full ATmega Arduino.

Sure. Or a pic 16. Or an stm32f1 or a z80 or a 6502. "Arduino" is used here to refer to any small programmable embedded computing device.

Thanks to you all.
I start understanding. In fact, the pulse length information will have to be translated in serial format to be sent to the RX.
Your example seems quite easy.
Another possibility is using a 433 mHZ TX RX system, which can be OOKed.
Thanks a lot !


text:
Unable to connect ESP8266 to WPA2+Enterprise network
I am trying to connect ESP8266 module to WPA2+Enterprise network with my ssid, username and password and the latest version supports such connection. I followed this link, and the code:
#include "ESP8266WiFi.h"
extern "C" {
  #include "user_interface.h"
  #include "wpa2_enterprise.h"
}

static const char* ssid = "ssid";
static const char* username = "username";
static const char* password = "password";
const char* host = "host_ip";

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

  Serial.print("Connecting to ");
  Serial.println(ssid);
   // Setting ESP into STATION mode only (no AP mode or dual mode)
  wifi_set_opmode(0x01);

  struct station_config wifi_config;

  memset(&wifi_config, 0, sizeof(wifi_config));
  strcpy((char*)wifi_config.ssid, ssid);

  wifi_station_set_config(&wifi_config);

  wifi_station_clear_cert_key();
  wifi_station_clear_enterprise_ca_cert();

  wifi_station_set_wpa2_enterprise_auth(1);
  wifi_station_set_enterprise_username((uint8*)username, strlen(username));
  wifi_station_set_enterprise_password((uint8*)password, strlen(password));

  wifi_station_connect();
  Serial.print("Wifi station connect status:");
  Serial.println(wifi_station_get_connect_status());

  // Wait for connection AND IP address from DHCP
  while (WiFi.status() != WL_CONNECTED) {
    Serial.println(WiFi.status());
    delay(2000);
    Serial.println("Not connected");
  }

  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());
}

void loop()
{
  delay(2000);
}

OUTPUT:
Connecting to ssid
Wifi station connect status:1
6
Not connected
6
Not connected
.....

Status 6 is  WL_DISCONNECTED,i.e., module is not configured in station mode. I am not able to figure out what is causing the problem.

The clear commands are not useful until after you have connected.
I use these commands just before setting user ID and password:
wifi_station_set_enterprise_identity((uint8*)username1, strlen(username));
wifi_station_set_enterprise_ca_cert(ca_cert, sizeof(ca_cert));

It is necessary that the radius server have default_eap_type set to TTLS or PEAP for username/password authentication. Perhaps there is another possibility, but there is a bug in ESP8266 so it does not properly search for supported EAP types.
const char* username1 = "anonymous"; //works for me

u8 ca_cert[] = "-----BEGIN CERTIFICATE-----\n"
"MIIFETCCA/mgAwIBAgIJAO0ntD34r/+QMA0GCSqGSIb3DQEBCwUAMIGiMQswCQYD\n"
"VQQGEwJVUzEXMBUGA1UECAwOTm9ydGggQ2Fyb2xpbmExDzANBgNVBAcMBkR1cmhh\n"
"bTEeMBwGA1UECgwVTWl0Y2hlbGwvVHJhbXBlciBJbmMuMR8wHQYJKoZIhvcNAQkB\n"
"FhBidXJ0bXNAZ21haWwuY29tMSgwJgYDVQQDDB9CdXJ0IFNlbGYgQ2VydGlmaWNh\n"
"dGUgQXV0aG9yaXR5MB4XDTE4MDEyMzE1NTgxOFoXDTE4MDMyNDE1NTgxOFowgaIx\n"
"CzAJBgNVBAYTAlVTMRcwFQYDVQQIDA5Ob3J0aCBDYXJvbGluYTEPMA0GA1UEBwwG\n"
"RHVyaGFtMR4wHAYDVQQKDBVNaXRjaGVsbC9UcmFtcGVyIEluYy4xHzAdBgkqhkiG\n"
"9w0BCQEWEGJ1cnRtc0BnbWFpbC5jb20xKDAmBgNVBAMMH0J1cnQgU2VsZiBDZXJ0\n"
"aWZpY2F0ZSBBdXRob3JpdHkwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIB\n"
"AQC2O2m4JCmqimeztaZ8JasIuZqksrxvCjyWpkykoGzoR6v1/kDSuLgdp7EmtLKN\n"
"vOJPQ2ea0yVvkFf0dQYcgDhNdAsXcqskMOprS+jefzlLQUbU1jTk+AOSiOcmxWT1\n"
"H8uYhSp/1TkkWDM8dVO9RRIQyigVinsJNhdPyUVsTaQh3s29AL8CboixUNZWngOo\n"
"d1+66lwy4N+3hXACJWlurgvc0q7RfqSqfJY/+lugfID0ANpGQqqu1Dq2IXZbLyx9\n"
"roOPpC+fqX2wn5g9+RuA18OY/GPtkHc6clAoiJDGXsTRpffgsI5spdJ26WknbhO/\n"
"3Q2vQJ2Q5m/QvSp55qOM5nevAgMBAAGjggFGMIIBQjAdBgNVHQ4EFgQUT3hChU84\n"
"EEXHesDdKOtPqfhrg68wgdcGA1UdIwSBzzCBzIAUT3hChU84EEXHesDdKOtPqfhr\n"
"g6+hgaikgaUwgaIxCzAJBgNVBAYTAlVTMRcwFQYDVQQIDA5Ob3J0aCBDYXJvbGlu\n"
"YTEPMA0GA1UEBwwGRHVyaGFtMR4wHAYDVQQKDBVNaXRjaGVsbC9UcmFtcGVyIElu\n"
"Yy4xHzAdBgkqhkiG9w0BCQEWEGJ1cnRtc0BnbWFpbC5jb20xKDAmBgNVBAMMH0J1\n"
"cnQgU2VsZiBDZXJ0aWZpY2F0ZSBBdXRob3JpdHmCCQDtJ7Q9+K//kDAPBgNVHRMB\n"
"Af8EBTADAQH/MDYGA1UdHwQvMC0wK6ApoCeGJWh0dHA6Ly93d3cuZXhhbXBsZS5v\n"
"cmcvZXhhbXBsZV9jYS5jcmwwDQYJKoZIhvcNAQELBQADggEBADNmDxddEh1XSo8J\n"
"fanCRuYqngpVFtKCzRNCtQ7aOAPrj6gRMtMAqQhlYmcbxjaVOCboAvJ8evY8x5We\n"
"YU6eIAmg95PlDws8EvcVQhO2ZYcuOHTvdu5Q4Ior0oXaCfqdS35YcPW7pRGprY/x\n"
"w7kbG84FFatpXPuDGQB65haqQ2KXPrILiE/jAKpTu9EBLEEN4uIAuxbB6unARovX\n"
"YoXIQHFc32bZAjihquvs4J7FNkcSr3lJpuv03dryqMB+Qn3G8yM7PFLNL2QyS0Zu\n"
"UbS5kDO7UqbTjtrUDolp5sUNvyrkX5ILYfZeEeaHqAlA20SFqNG7BcTY222NsCft\n"
"yNXqX1c=\n"
"-----END CERTIFICATE-----";

works for me. I have to go back and check whether those \n's are needed.
I think I found the enterprise_identity command important for both TTLS and PEAP, and I found I needed a ca_cert to do PEAP but not necessary for TTLS. I am not certain why.


text:
(HELP)How to read Physical Dimensions in datasheets
Sir/ Ma'am,
.
How to read the dimension labels of this IC?

I have annotated your drawing a little to help you understand it better:

Values above the horizontal lines are in inches. Values below it are in mm.

why there is an plus and negative sign?

that is tolerance values, allowed variations in production (for instance). 0.060±0.005 is the range 0.055 to 0.065.


text:
Arduino Micro Power Questions
I have a few questions about the Arduino Micro circuit:

If I can provide a steady 5 V source (connected to +5V), then I don't need to use the voltage regulator module (including the selector) of the circuit. Correct?
If I can provide a steady 5 V source (connected to +5V), then I don't need to connect anything to VIN. Correct? If that's right, should I connect it (VIN) to GND, instead of leaving it floating?
If I'm not using +3.3V, should I connect it to GND (instead of leaving it floating)?
If I'm powering off of just USB, then I can connect +5V to VUSB. Correct?

Schematic below for reference:

Is this a question about circuit design, as in: designing your own board which is nothing to do with a Arduino Micro?

Yes and no. I will be making the Arduino Micro circuit, but without the regulator module and voltage selector. But I want to make sure that this is actually possible to do, before I move on it.

If I'm powering off of just USB, then I can connect +5V to VUSB. Correct?

If you are powering off USB leave everything alone. See the schematic:

The blue line added by me shows what is going on. The VBUS signal from the USB connector goes through a 500 mA resettable fuse (to protect the USB port from overloads). Then it goes to the P-channel MOSFET (FDN340P) which makes a decision about whether to switch on and connect VUSB to +5V signal. It does so if VIN is low, making the MOSFET conduct. If VIN is high (which it would be if you had power into the VIN part of the board) then it disconnects the USB from the +5V line.

If I'm not using +3.3V, should I connect it to GND (instead of leaving it floating)?

Definitely not. The 3.3V line is an output from the 3V3 voltage regulator. To connect it to ground would heat it up and destroy it.

If I can provide a steady 5 V source (connected to +5V), then I don't need to connect anything to VIN. Correct? If that's right, should I connect it (VIN) to GND, instead of leaving it floating?

No, VIN is already connected to ground via a 10k resistor (see schematic above) and thus it is not floating.

The picture helps a lot in terms of clarification! So if we take out the selector circuit, then I would have to connect +5V and VUSB manually, correct?

You might want to leave the fuse in, but yes, that sounds right. You could omit the 3.3V regulator too if you don't need 3.3V. The standard for USB is 5 V ± 5% which is within spec for the processor. I have made plenty of boards up where I just connect up a source of 5V to the Vcc pin of the processor chip. Make sure you leave in the decoupling capacitors on Vcc and AVcc.


text:
Minimum circuitry required to program an AVR
Where is the information what is the minimum-required circuitry to program any AVR via ICSP?
Sometimes I see schematics that show just the chip and the six wires for the ICSP header (RESET, VCC, GND, MISO, MOSI, and SCK).
Other times, I see some passive components connected to some of the pins.
So why is it different some times? How do people know when to use extra components when wiring up the chip for programming? Do the datasheet for these MPU's provide the details?

I have a page about a minimal board. The minimal circuit is the chip itself, and a couple of decoupling capacitors. A pull-up on /RESET is advisable (however the processor has a weak pull-up on it).

The six wires you mention are required for ICSP programming. An example from my page is:

That is using an Arduino as an ICSP programmer.
I think most designers would mandate the decoupling capacitors. You may get away without the pull-up on /RESET but probably at the expense of reliability.
The wires changed colour between the two photos because my earlier board (shown second) had the capacitors further away from the chip pins than they should have been. They really should be next to the chip for maximum effectiveness.

Note that, depending on the fuses, you may need to supply an external clock. In my case I did it like this:

The default chip fuses (from the manufacturer) does not require a crystal.

All good advice, but it might be worth mentioning that if the target AVR has its fuses set to expect an external clock, you need to provide one.

@Nick Gammon
Great post!
Does the wiring of the circuitry generally hold up for all AVR's? Or are more complex AVR's (such as ATmega32U4) going to require different circuitry?

All 8 bit AVRs I know of work with this protocol, except for the 4/5/9/10 6-pin variety.

I added a bit more about the external clock. As for the other AVRs, I have programmed the ATmega32U4 and the ATtiny chips in a similar way (the actual wiring varies, of course). Ditto for the larger chips (Atmega1280, Atmega2560 etc.).

This post was very useful thanks. I did my own diagram for use with a Pololu AVR programmer. https://www.flickr.com/photos/qu1j0t3/49712305953/in/dateposted/

authors: עידן מנעולן ופורץ מנעולים


text:
Questions about the Arduino Micro PCB
I'm planning on integrating an Arduino Micro in the circuit of a small project of mine (USB gamepad). The whole thing will use USB for power and data transfer (between the board and the computer). Before I move on with prototyping, I need to clear up some questions I have about the Arduino Micro schematic (picture included for reference):

Since I'll be powering off of USB, I won't the 5 and 3.3 V regulators or the 5 V Selector (top-right in picture). Am I correct?
For the USB Micro header, does the schematic refer to any particular header (doesn't seem so to me), or will any generic one work? And what are the six pins on the right side (SH1/S1, SH2/S2, SH3/S3, SH4/S4, SH5/S5, SH6/S6)? What do they do? What are they used for? I found the pins on the left (VBUS, D-, D+, ID, GND) on generic USB Micro headers, but I did not find the pins on the right.
Out of curiosity, what do the asterisks in the schematic mean? You can see them all over; for example, look at the top-right of the MCU.
What do the circle and the smaller circle (with an X through it) towards the bottom-right mean?

The 5V regulator is only used when you are powering from external power (>5V). The 3.3V regulator is only used by things that you power from the 3.3V pin on the Micro.
So if you aren't using external power you don't need the 5V regulator. If you aren't using any 3.3V devices then you don't need the 3.3V regulator.
You can use any micro USB or even mini USB connector you like. If you ignore the "ID" pin you can even use an old-fashioned chunky USB B connector like on the Uno.
The circles are fiducial markers and are special patterns on the board used for aligning a pick-and-place machine when manufacturing.

•  “... powering off of USB, I won't [need] the 5 and 3.3 V regulators or the 5 V Selector ...”

True, except that some of those parts maintain circuit continuity.  For example, when USB power is used, its current passes through the T1 P-mosfet.  For explanation of the power selector circuit, see for example usage of bidirectional mosfet in electronics.stackexchange, or arduino power supply selector at engineeredentropy.com.
In brief, you can leave those parts in place on Micros that you purchase, or could leave them out (while connecting VUSB and +5V) if you replicate the rest of the circuit.

• “For the USB Micro header, does the schematic refer to any particular header (doesn't seem so to me), or will any generic one work? And what are the six pins on the right side (SH1/S1, SH2/S2, SH3/S3, SH4/S4, SH5/S5, SH6/S6)?”

Various generics should work ok, even if they don't have all the SHx shell ground pins shown.

• “... what do the asterisks in the schematic mean?”

The asterisks next to PB7, PB6, etc., designate pins with timer-driven PWM capability.

• “What do the circle and the smaller circle (with an X through it) towards the bottom-right mean?”

That's not clear to me.  While they look like fiducial markers, such markers typically are not needed on a schematic diagram.  Fiducial markers may be needed on PCBs or PCB layouts, but serve no obvious purpose on the schematic.  These may be a designer's idiosyncracy or left-overs.

Often the simplest way to get fids on your PCB is to include them as a component in your schematic, that way they automatically appear as a component footprint in the PCB design.

Let's keep it simple. If you are using USB to power it all, connect the power supply to 5V. The 5V regulator is used to regulate the VIN voltage. The 3.3V regulator is only used to power the 3.3V pin.
USB micro is a type of header. Any common USB micro that you get from a local supplier of EBAY/AMAZON will work.
The asterix and the circle with and without the X are problably markers used by Arduino in there schematic. Don't worry about them.

When you say "connect the power supply to 5V", you mean connect VIN to VUSB, right?

VIN is connect to the input of the 5V regulator. 5V pin + USB input is connected to the output of the 5V regulator.


text:
Get pin input status without using the arduino library
I am not allowed to use the Arduino Library (or any Library) for this program. How would I check the input of a pin?
I found two different functions:
In Arduino.h:
#define bitRead(value, bit) (((value) >> (bit)) & 0x01)

Following digitalRead back to pgmspace.h:
#define __LPM_enhanced__(addr)  \
(__extension__({                \
    uint16_t __addr16 = (uint16_t)(addr); \
    uint8_t __result;           \
    __asm__ __volatile__        \
    (                           \
        "lpm %0, Z" "\n\t"      \
        : "=r" (__result)       \
        : "z" (__addr16)        \
    );                          \
    __result;                   \
}))

For the first one, I don't know where bit and value come from and I just don't understand the second one at all.

This looks a very similar topic to your other recent question: How do I use masks to make it so pin 13 (PB7 and the LED) as output and then have pin 10 (PB4) as an input?. Please don't ask two very similar questions in the space of a couple of hours.

I asked this one first to see how to get an input. The other question was to see if use the same Data Port for both an input and an output.

But it's the same project, right? You are just looking at the same problem in slightly different ways.

No I'll more than likely use this for every project I do and the other one, it just depends on the project. Where this one is just get any pin. The other question is how to deal with getting an input from the B data registry and changing the state of the light as an output in the same data registry.

I changed the title of the other question to better describe that question.

For reading, e.g., PB2, you would test
PINB & _BV(PB2)

where PINB is the port input register and _BV(x) is a macro defined as
(1 << (x)).
C.f. the datasheet for the relevant port names.
See also the Arduino tutorial on
port manipulation.

Can you explain what (1<< (x)) does please?

@kingcobra1986: https://www.arduino.cc/en/Reference/Bitshift

I'm sorry, I didn't mean what is a bit shift. I know it is a bit shift to the left by x. What does it do though? Is it for getting the correct pin from the register? Or does it do something else?

It does exactly what you know it does: it shifts 1 by x places to the left. No more, no less. C.f. http://playground.arduino.cc/Code/BitMath

@kingcobra1986 The PB2 is defined as bit position not a bit mask (which is needed for bit manipulation).


text:
How to set string in the structure part of NRF24?
Can anyone help me on how to correct my program ? I want to transmit value in string form.
I put this to TX code
struct payload_t
{

 String sensor1;
};

..................
At the loop part I put this code
String sensor1 = (String(x) + "," + String(y) + "," + String(z)) ;

In the RX part I put this code
 struct payload_t
{

 String sensor1;
};

At the loop part
RF24NetworkHeader header;
payload_t payload;
network.read(header,&payload,sizeof(payload));

Serial.println("Sensor1 ");

Serial.println(payload.sensor1);

Below is the Attach picture result of RX code.
Thanks in advance :)

Did you actually 'instantiate' the struct in the TX and construct sensor1 as payload.sensor1 = ...? Anyways, there's still a problem.
You are using String in your payload. The third argument to read is the maximum message length that can be stored in payload. In your read call, you passed the size of payload as MAX_LEN. You will receive incomplete payloads since the String object in the RX payload struct has no content in it yet and thus payload's size, which you passed as MAX_LEN, will be less than that of the actual payload that was transmitted. Just ditch the Strings and try:
TX:
int vals = {x, y, z};   // guessing they are ints

network.write(header, &vals, sizeof(vals));

RX:
int vals[3];
network.read(header, &vals, sizeof(vals));

Serial.print(vals[0]); Serial.print(',');
Serial.print(vals[1]); Serial.print(',');
Serial.println(vals[2]);


text:
Use Arduino to turn fan on / off
I have a simple fan.
When I plug it to GND and Vin it spins.
I'd like to have the ability to turn it on / off with code.
Any example will do, as long as it gets it to spin.
I have a NodeMCU board, if that helps.

Use a MOSFET as digital switch. Fan+ to Vin, Fan- to MOSFET drain, MOSFET source to ground, MOSFET gate to a digital pin of the Arduino. You can google MOSFET as a switch

Related if not dupe: https://arduino.stackexchange.com/q/54018/17196 and https://arduino.stackexchange.com/q/54145/17196

google images "mosfet switch low side"

Depending of the type of fan you are using, two solutions exist.

First one, use a MOSFET to drive the FAN from you nodemcu
Second one, use a relay to drive the FAN from your nodemcu

Things to consider :

The mosfet allow you to drive the fan without mechanical part moving.
The relay require some transistor and feedback diode to be driven by your µc.

What about a motor driver?

Motor driver in the end is just several mosfets connected in a smart way. It's unnecessarly complicated and redundant if fan just spins when you supply power. There is a very good chance that the fan already has a driver inside it (all computer fans do)

So I didn't have a transistor to do a MOSFET, but I did have a motor driver which I ended up using. From there it was just finding example code to use the motor driver, connecting it up and using it.


text:
Overriding main function in Leonardo
I've trying to write my code in plain C++ dropping out the Arduino's IDE. Although I've succeed in compiling the code, whenever I try to upload it to the board it doesn't run, seems that it stucks at some unknown point.
After that, everytime I try to upload a new code to the board it stops responding and avrdude throws this message:
$ ino upload -m leonardo -p /dev/ttyACM1
/dev/ttyACM1 doesn't exist. Is Arduino connected?

It doesn't matter if I unplug and then plug again the board, that message is still showing up.
In order to restart the board, I open the Arduino IDE and then I upload any sketch, then the board comes to live again.
The first time I tried overriding the main() function and the program didn't run I thought it was the tool I was using at that moment, arduino.mk, the one that was doing something strange.
Then I tried the ino tool, but the result was the same.
I don't think avrdude is failing because it actually uploads the .hex to the board.
My original main() code was:
#include <Arduino.h>

const int LED_PIN = 13;

int main(void)
{
    pinMode(LED_PIN, OUTPUT);

    while (1)
    {
        digitalWrite(LED_PIN, HIGH);
        delay(100);
        digitalWrite(LED_PIN, LOW);
        delay(900);
    }
    return 0;
}

Then I tried to mimic the one that comes with Arduino:
#include <Arduino.h>

const int LED_PIN = 13;

int main(void)
{
    pinMode(LED_PIN, OUTPUT);

#if defined (USBCON)
    USBDevice.attach();
#endif

    while (1)
    {
        digitalWrite(LED_PIN, HIGH);
        delay(100);
        digitalWrite(LED_PIN, LOW);
        delay(900);

        if (serialEventRun) serialEventRun();
    }
    return 0;
}

Sadly, with both codes the board gets stucked at some point.
While I figure out how to solve this issue I've been exercising this solution inside a sketch:
const int LED_PIN = 13;

void setup() {
}

void loop() {
    pinMode(LED_PIN, OUTPUT);

    while (1)
    {
        digitalWrite(LED_PIN, HIGH);
        delay(100);
        digitalWrite(LED_PIN, LOW);
        delay(900);
    }
}

Any ideas that led me to a solution? Thank you!

Solved!
It was a (big) silly mistake of my own. I overloocked the init() function right after entering the main() function. I'm shure it initializes the hardware and the entire system, so my board stucks when I skipped it.
So my code now looks like this:
#include <Arduino.h>

const int LED_PIN = 13;

int main(void)
{
    init();

#if defined (USBCON)
    USBDevice.attach();
#endif

    pinMode(LED_PIN, OUTPUT);

    while (1)
    {

        digitalWrite(LED_PIN, HIGH);
        delay(100);
        digitalWrite(LED_PIN, LOW);
        delay(900);

        if (serialEventRun) serialEventRun();
    }

    return 0;
}

BTW, the mix: Arduino + Vim + ino, rocks! Now I can do whatever I want from the console :)