text:
Digital LED clock - matrix circuit question
i'm making a digital clock.
Right now the plan is to matrix them on a atmega328 using transistors.
I figured i need a transistor on both sides or the current would be sinked/sourced by the atmega, which is not what i want.
I'd rather use the MAX7219 but i'm not sure if it's possible to use transistors, because i don't think the MAX7219 can handle the current.
I found the circuits here, i smushed them together, is this correct? Idk.

This is the led segment i'm using, there's four of them. So four 337 transistors, one for each digit. And seven 327 transistors, one for each segment.
I will scan through the four digits and turn on the apropriate segment.

So yea, please let me know if this is totally wacky or something else.
Edit :
I guess this would be 1 digit. Sorry it's confusing to draw the whole matrix. I hope this clears it up. It's just a normal matrixing situation but with more leds.

So normally it goes something like this :
The cathodes of the leds are controlled directly by the atmega, but results in the atmega supplying the current. So my reasoning would be to put a row of transistors there instead, would that be correct?

why are you using two transistors?

Your schematic has two Q1's, which is confusing. Your schematic is not complete or it does not match your description. Please correct it so they match. The BC327 will be connected to the 7 segments and the BC337's to the (common) cathode of each digit, right?

That's my question. Do i need two for each segment? Like i said in my OP, if i would use 1 transistor, the current would be sourced/sinked by the arduino. I need to leds to be powered seperatly.
One of those should then be Q2, forgot to edit that. I can't match it to my description because i'm not sure if it's correct.
It's a led matrix, but instead of individual leds, i need to turn on sets of 2 and 3 leds. The cathodes are controlled by the BC337, the anodes by the BC327.

I think this will work. Why don’t you test this on a breadboard? The value for R1 should be chosen such that the LEDs light up evenly. I would advise you to use different values for the clusters with two and three LEDs, or use one resistor per LED. You should take the (small) voltage drop from the transistors into account and calculate resistors accordingly.

Since each LED is individual, I'm afraid that you can not put them in parallel. They will lit differently due to their own forward voltage. You might like to put them in series.

Since you're using a matrix of anodes and cathodes you need to connect/disconnect both ends of each LED.
You will probably multiplex these LEDs and only light one at a time. Are the LEDs high enough current that you can't either source or sink enough current for a single LED directly from Arduino pins? Most LEDs run on ≤ 20 mA, which an atmega328 can handle.
If you are trying to drive LEDs that need > 20mA then your plan to switch both the +5 and the ground with transistors should work. As StarCat said, you should consider the "on resistance" of your transistors as part of your calculation for the value needed for the current limiting resistors of your LEDs.

Or just use the MAX7219, specifically designed for 7-segment displays.  It has an operating current spec of 330 mA, good for all segments and the decimal point on at the same time.  A four-digit 7-segment display with a total of 32 LEDs allows 10 mA per LED assuming you have everything on at once.
Am I missing something?
Frank


text:
Can we use ESP32 to program ESP32-CAM through ESP-IDF
Can we just use an ESP32 NodeMCU for example to program an ESP32-CAM? I saw a lot of people programming ESP32-CAM using an arduino Uno, can we do the same for ESP32 NodeMCU? Of course, in the "Arduino as ISP" programming mode.
If we can, is there anything more that I need? if not, why? and are there any other solutions to program it?
Moreover, I want to use ESP-IDF which is better than using the Arduino GUI app.

"Arduino as ISP" is something very different

I really dont even know what to do man. I really need help, sometimes when I power it up (ESP32-CAM) the LED does not even turn on, even if I press the reset button, I am so confused, it only lights up when I give it electricity from the FTDI, I think this board is broken or something...

you can't power an esp32 from FTDI 3.3 V pin. it can't provide enough current

Well, It actually worked fine, the led was flashing, but when I connect IO0 to GND, the flashing stops. If you have any video that explains ESP32-CAM very well, please notify me, it is one of these two: 1. The chip is not genuine. 2. I have a bad understanding about the chip.

it is 2. but please read https://arduino.stackexchange.com/tour

I have discovered how to use the ESP32 NodeMCU as a serial interface. In other words, make the ESP32 traverse ALL of the serial communication to the TX & RX pins directly without any interference. When you press the "RST" (Reset) button, it turns off, but when you release your finger, it will turn on. However, when it is turned off, it traverses all the serial communication to the TX & RX pins, which can then be used to program and contact with the ESP32-CAM. Of course, you can't keep pressing the "RST" button all the time, instead connect the "En" (Enable) pin to GND which will then disable the 3.3 voltage regulator (Same as if you were pressing the "RST" button), in other words, turns the ESP32 off. And then, connect any two GND pins together from both of the ESP32's. At last, upload your program to the ESP32-CAM.

A step by step guide could be found here https://www.instructables.com/Programming-ESP32-CAM-With-ESP8266/

All you need to program any ESP32 (Cam or not) is a serial interface.  How you make that serial interface is up to you.
Most ESP32 development boards have a USB to UART converter on them which you can use just like on an Arduino - keep the ESP32 you're using for the programming in RESET so it doesn't try and respond on the UART.
You could also program the "programmer" ESP32 as a UART passthrough to connect the USB UART through to the other UART so you don't need to mess with holding in RESET.

source: Stack Exchange

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

sort: votes


text:
Arduino-compatible wireless technology which can be suitable for transmitting data
Introduction
I've been meaning to build a vehicle using arduino components and LEGO. I have a mechanical clamp built with arduino which will be locked on top of a custom LEGO build (It should be made out of LEGO blocks and arduino sensors). In my mind, it resembles a crawler.
Question
I've been looking for a way of controlling it remotely.
I only have experience with IR controllers but I'm not sure if this technology would fit for my project.
What I'm looking for is a technology wich could transmit data to an Arduino board (thus, an emitter and a receiver component) which, in my case, could comfortably handle a veichle.
Plus, it should have a range of action of at least 5 meters (15 ft).
If such technology exists, do you know any controller which could do the job for me?

You can use radio transmitter/receivers, they are typically called RF (Radio Frequency) modules.
Typical examples are nRF24L01+ (2.4 GHz), or RF 315/433 modules (on 315/433 MHz).
There are more possibilities, but these are the most used on Arduino and libraries are available.

Thanks for your answer, do you happen to know where to find these modules?

You mean where to buy them? AliExpress, or if you want genuine products, try Mouser, Digikey

Try a pair of Wixels (https://www.pololu.com/product/1336).  A pair of Wixels (one at the PC, one on the crawler) act as a fast USB cable emulator.  The PC-connected Wixel shows up as a USB port, and the one on the crawler (with a Wixel sheild) emulates the Arduiono end of a USB cable.  These are very easy to use, and in addition to remote control will allow you to wirelessly program the Arduino controller.
The ability to remotely program the crawler is a real god-send, as now you don't have to retrieve the crawler and connect it to a hardware USB cable for programming.
Just my $0.02
Frank

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


text:
Function declared in another file not recognized (undefined reference to)
I am making a multi-file arduino project, but the compiler can't recognize a function.
I am using the arduino-cli version 0.10.0
This is the error I received
undefined reference to pin_init() collect2.exe: error: ld returned 1 exit status Error during build: exit status 1
This is the command:
arduino-cli compile -b arduino:avr:uno C:\Users\Cioccarelli\Desktop\transmitterCopy\main

main.ino:
#include "C:\Users\Cioccarelli\Desktop\transmitter\automation\automation.h"

void setup() {
    pin_init();
}

void loop() {}

automation.h:
#pragma once

// This is where the components input pins are stored, they are put here by the add_pin function
byte pinSetup[0];
byte pinSetupSize = 0;

// This function is called in the setup() and it initializes every pin listed in pinSetup[] as input
void pin_init();

automation.cpp:
#include "C:\Users\Cioccarelli\Desktop\transmitter\automation\automation.h"

extern pinSetup;
extern pinSetupSize;

void pin_init() {
    for (int i = 0; i < pinSetupSize; i++)
        pinMode(i, INPUT);
}

I think this issue might have to do with the fact that I don't completely understand file inclusion, but I haven't found anything useful in my research

Update: today I rebuilt the project with different names and I cut everything which wasn't related to the problem, in hope to identify it.
new main:
#include "C:\Arduino\transmitter\nightmare\nightmare.h"

void setup() {
    pin_init();
}

void loop() {}

new automation.h (nightmare.h):
#pragma once

// This function is called in the setup() and it initializes every pin listed
//in pinSetup[] as input
void pin_init();

new automation.cpp (nightmare.cpp):
#include "C:\Arduino\transmitter\nightmare\nightmare.h"

void pin_init() {}

new file structure:

I also made a copy and made some changes so it could become a C++ file
(substituting the setup() with main() and replace every "byte" type with "int")
I then put it in Visual studio, it compiled perfectly.
The arduino IDE gives the same error

To be simple, put all files into one directory, and do #include "automation.h". Since you have a small project, this can work out.

@Linny I know this would work, but I want to do things this way because I want to learn how to manage multiple directories and because this is a very early stage of the project, in the future that kind of solution would work very poorly

The compiler didn't have a problem; the linker did. That is, once your main function was compiled (correctly) to call pin_init(), the loader tried to put together all of the compiled modules and link up calls that were not satisfied locally - within the same file - to functions defined in another module. That is when this message got generated. No such function definition was found, despite the declaration of it in main.ino.
If you can compile this with the Arduino IDE, watch what it does: It will compile each of your source-code modules, one at a time. Then link all of your modules' compiled versions together to produce the .hex file (that will eventually get uploaded to the Arduino). You need to mimic that when you're compiling & loading from the command line.
Update:

today I rebuilt the project with different names

Is your .cpp file in the same folder as your .ino file? Or in another folder, such as the folder containing your .h file? I suspect it's the latter. When I built your project it in the Arduino IDE, it succeeded when the .ino and the .h were in the same folder, failed exactly as you described when I moved the .cpp file to where the .h file is.
The solution goes back to what I suggested earlier; that no definition of pin_input() was found, as the .cpp file containing it wasn't seen by the IDE (or your command-line compiler) and therefore not compiled and linked. Each of your files needs to be compiled and all of them together need to be linked, for the external calls to be satisfied.
With the IDE, put your project's .ino and .cpp files in the same folder so the IDE will see and compile each of them and know what to files to link. The IDE won't give you much flexibility for locating your .cpp files.
With the command line compiler, you can put your files wherever you will, make a separate[1] compile only run for each of them, then make another run of the linker component[2] naming all of the compiled units (the IDE names them as .d) and provide the path to your library folder(s).
[1] I'm not familiar with the command-line compiler's command-line syntax; maybe you're able to specify a number of compiles with one command.
[2] Again, IDK whether you need invoke the linker with the same command but with a link-only option switch, or you'll need to invoke the linker yourself, on the command line.

the arduino IDE gives the same error, I made some additions to the question

The Arduino IDE (and I guess arduino-cli behaves the same) will try to
link into your project every source file that lives in the same
forlder as the main .ino file.
Try this: get rid of the “automation” and “main” subfolders, put
everything at the root of the project, and try to build again. If you
end up with too much stuff in the root, you may consider the possibility
of creating your own libraries, but that's for another day...


text:
Arduino Nano, DS3231 RTC clock module and 4 cascaded FC-16 led matrix modules
Like I said in the title, I am using a DS3231 real time clock module and 4 cascaded FC-16 modules(they are basically MAX7219 led matrices based modules). My goal is to display a timetable, a schedule for a classroom on the matrices. The purpose of the DS3231 module is to keep track of time(mainly hours) from 8:00AM to 20:00PM, to display the hour on the matrix and to change the subject when it hits even hours.
Eg: when it's 8:00AM we have subject A, when it's 10:00AM we have subject B etc
And after that I have to use a ESP8266 wifi module to change the schedule from distance.
EDIT1:
I managed to display the hour on the matrix, but now I really can't figure out how to display the text in 4 rows. I have 4 FC-16 modules and I want to put each of them on top of the other so I can have 4 rows of text. I managed to do this by inserting space between words but this is not optimal. I want this to be automated so the person changing the text in the program doesn't have to do the spacing thing by themselves.
#include "RTClib.h"
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>

const uint16_t WAIT_TIME = 1000;

#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 16

#define CLK_PIN   13
#define DATA_PIN  11
#define CS_PIN    10

MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);

RTC_DS3231 rtc;

//char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

void setup () {
  P.begin();

  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

 if (rtc.lostPower()) {
    Serial.println("RTC lost power, lets set the time!");
//     If the RTC have lost power it will set the RTC to the date & time this sketch was compiled in the following line
   rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));

  }
}

void loop () {
    DateTime now = rtc.now();

    char buffer[] = "hh:mm";  // hours and minutes
    P.print(now.toString(buffer));  // display

   // Serial.println();
    delay(1000);
}```

Re your edit: you commented-out the rtc.adjust() line. Are you sure your RTC is correctly initialized? If not, the returned DateTime can be invalid, which could result in garbage being printed out. You can also check the value returned by now.isValid().

how do I display the time from the DS3231 clock module on the FC-16
  led matrix modules?

You can use the DateTime::toString() method to convert the
current time to a string in the format of your choice, then P.print()
to display that string on the LED matrix:
void loop() {
    DateTime now = rtc.now();
    char buffer[] = "hh:mm";  // hours and minutes
    P.print(now.toString(buffer));  // display
}

how do I use that hour of the day so that the microcontroller knows
  what text it should display next?

Condition your logic on now.hour().

Thank you very much, I will try and I'll come up with an update


text:
FC-16 led matrix module based on MAX7219
EDIT:
const char  *pc[NUM_ZONES] =
{
  "ROOM", //0
  "SUBJECT", //1
  "GRADE",//2
  };

I did this and I can't get them to display every row simultaneously.
void loop(void)
{

 DateTime now = rtc.now();
 char buffer[] = "hh:mm";  // hours and minutes

 for (uint8_t i=0; i<NUM_ZONES; i++){
   P.displayZoneText(0,now.toString(buffer), PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
   P.displayZoneText(1, pc[1], PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
   P.displayZoneText(2, pc[2], PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);  // display
   P.displayZoneText(3, pc[3], PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
 }
}

I can only display one row at a time like this, now it only displays the hour:min.
Tell me what am I doing wrong
EDIT2:
Or like this:
-this is my goal, to change the text based on hour
void loop(void)
{

 DateTime now = rtc.now();
 char buffer[] = "hh:mm";  // hours and minutes

   P.displayZoneText(0,now.toString(buffer), PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);

   if(now.hour()==21){
   P.displayZoneText(1, pc[1], PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
   P.displayZoneText(2, pc[2], PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);  // display
   P.displayZoneText(3, pc[3], PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
   }
   P.displayAnimate();
}

And at the moment with this code it only displays the hour and minutes

When you do it by hand like that, how do you figure how many spaces to put between the words?  All you really need to do is to do that same thing in program, but it isn't clear exactly what that process is.

I haven't used this library, but reading through the documentation it seems it operates on the concept of zones.

Create a zone for each row (a zone is a contiguous block of modules forming a kind of sub-display)
Perform operations on the zones with the zone-specific functions.

For example, setting up your zones would be:
P.begin(4); // We will have 4 zones
P.setZone(0, 0, 3); // Modules 0-3 in zone 0
P.setZone(1, 4, 7); // Modules 4-7 in zone 1
P.setZone(2, 8, 11); // Modules 8-11 in zone 2
P.setZone(3, 12, 15); // Modules 12-15 in zone 3

Then you can clear a zone with:
P.displayClear(2); // Clear zone 2

And write text to a zone with:
P.displayZoneText(3, "P03", PA_CENTER, 0, 0, PA_NO_EFFECT, PA_NO_EFFECT);

I'm not certain about what all the parameters mean, but the prototype is:
void displayZoneText(uint8_t z, const char *pText, textPosition_t align, uint16_t speed, uint16_t pause, textEffect_t effectIn, textEffect_t effectOut = PA_NO_EFFECT);

I managed to do that. I created my 4 zones and I can now display text on any of them. Now, I would like to know how to display hour:minutes from the clock module and text simultaneously. Hour and minutes on one row and text on the other 3

You print the time in zone 0 and the other text in the other zones.

Yes, but I don't know the prototype of that. I can't print them. Only separately

I give you an explicit example in my answer.

I gave you an edit


text:
Parola library and DS3231 clock
EDIT2: Well, this is the "new" code and it just displays random dots on the matrices:
#include "RTClib.h"

#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>

// Define the number of devices we have in the chain and the hardware interface
// NOTE: These pin numbers will probably not work with your hardware and may
// need to be adapted
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 16
#define NUM_ZONES 4

#define CLK_PIN   13
#define DATA_PIN  11
#define CS_PIN    10

// Hardware SPI connection
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// Arbitrary output pins
// MD_Parola P = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);

RTC_DS3231 rtc;
#define SPEED_TIME  25
#define PAUSE_TIME  1000

uint8_t lastUpdateMin = 0;
uint8_t lastUpdateHour = 0;

// Global variable
const char  *pc[NUM_ZONES] =
{
  "TIME",
  "ROOM", //0
  "SUBJECT", //1
  "GRADE",//2
  };

void setup(void)
{

  P.begin();
    if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

 if (rtc.lostPower()) {
    Serial.println("RTC lost power, lets set the time!");
//     If the RTC have lost power it will set the RTC to the date & time this sketch was compiled in the following line
   rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
 }

 P.begin(4);
  P.setZone(0, 0, 3); // Modules 0-3 in zone 0
  P.setZone(1, 4, 7); // Modules 4-7 in zone 1
  P.setZone(2, 8, 11); // Modules 8-11 in zone 2
  P.setZone(3, 12, 15); // Modules 12-15 in zone 3
}

void loop(void)
{

 DateTime now = rtc.now();
 if(lastUpdateMin != now.minute()){  // change every minute
     lastUpdateMin = now.minute();
 char buffer[] = "hh:mm";  // hours and minutes
P.displayZoneText(0,now.toString(buffer), PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);

    if(lastUpdateHour != now.hour()){     // change every hour
     lastUpdateHour = now.hour();
   P.displayZoneText(1, pc[1], PA_RIGHT, 0, 0, PA_PRINT, PA_NO_EFFECT);
   P.displayZoneText(2, pc[2], PA_LEFT, 0, 0, PA_PRINT, PA_NO_EFFECT);  // display
   P.displayZoneText(3, pc[3], PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
   }
  }
   P.displayAnimate();
}

If I do just this:
void loop(void)
{

 DateTime now = rtc.now();
 if(lastUpdateMin != now.minute()){  // change every minute
     lastUpdateMin = now.minute();
 char buffer[] = "hh:mm";  // hours and minutes
P.displayZoneText(0,now.toString(buffer), PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
 }
     if(lastUpdateHour != now.hour()){     // change every hour
     lastUpdateHour = now.hour();

     }

   P.displayAnimate();
}

it displays the hour:minutes.
the problem is it doesn't display the time and the other text at the same time
EDIT: If I execute this code below it will display text on the first row, but my question will be how do I manage to display simultaneously the hour:minutes from the clock and some text of my choice?
void setup(void)
{

  P.begin();
    if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

 if (rtc.lostPower()) {
    Serial.println("RTC lost power, lets set the time!");
//     If the RTC have lost power it will set the RTC to the date & time this sketch was compiled in the following line
   rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
 }

 P.begin(4);
  P.setZone(0, 0, 3); // Modules 0-3 in zone 0
  P.setZone(1, 4, 7); // Modules 4-7 in zone 1
  P.setZone(2, 8, 11); // Modules 8-11 in zone 2
  P.setZone(3, 12, 15); // Modules 12-15 in zone 3

for (uint8_t i=0; i<NUM_ZONES; i++)
    P.displayZoneText(0, pc[0], PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);

}

void loop(void)
{

 DateTime now = rtc.now();
 char buffer[] = "hh:mm";  // hours and minutes

// P.displayZoneText(0,now.toString(buffer), PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);  // display
//if(now.hour()==12){
//  P.displayZoneText(0, pc[0], PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
//}
//else{
 // P.displayZoneText(1, pc[1], PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);  // display
//}
   P.displayAnimate();
}

I have multiple FC-16 modules based on MAX7219 led matrices and I want to use them and a real time clock, DS3231, to build a classroom timetable.
I want the led modules to operate on the concept of zones. I want to create a zone for each row of text (a zone is a contiguous block of modules forming a kind of sub-display) as I did here: P.begin(4); // We will have 4 zones
P.setZone(0, 0, 3); // Modules 0-3 in zone 0
P.setZone(1, 4, 7); // Modules 4-7 in zone 1
P.setZone(2, 8, 11); // Modules 8-11 in zone 2
P.setZone(3, 12, 15); // Modules 12-15 in zone 3
I want this in order to be able to change the text in a row without modifying other rows.
Then, I need to use the hour and minutes from the DS3231 clock module and to display it on the first row of the display and on the other 3 rows I need to display the number of the room, the subject and the class.
const char  *pc[NUM_ZONES] =
{
  "ROOM",
  "SUBJECT",
  "CLASS",};

And when the hour on the first row changes, the text from the other 3 rows should change simultaneously.It's a pretty simple concept but I can't seem to know how to manage this.
This is all the code I gathered up until now:
#include "RTClib.h"

#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>

// Define the number of devices we have in the chain and the hardware interface
// NOTE: These pin numbers will probably not work with your hardware and may
// need to be adapted
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 16
#define NUM_ZONES 4

#define CLK_PIN   13
#define DATA_PIN  11
#define CS_PIN    10

// Hardware SPI connection
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// Arbitrary output pins
// MD_Parola P = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
RTC_DS3231 rtc;
#define SPEED_TIME  25
#define PAUSE_TIME  1000

// Global variables
uint8_t  curText;
const char  *pc[NUM_ZONES] =
{
  "ROOM",
  "SUBJECT",
  "CLASS",

};

void setup(void)
{

  P.begin();
    if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

 if (rtc.lostPower()) {
    Serial.println("RTC lost power, lets set the time!");
//     If the RTC have lost power it will set the RTC to the date & time this sketch was compiled in the following line
   rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
 }

 P.begin(4);
  P.setZone(0, 0, 3); // Modules 0-3 in zone 0
  P.setZone(1, 4, 7); // Modules 4-7 in zone 1
  P.setZone(2, 8, 11); // Modules 8-11 in zone 2
  P.setZone(3, 12, 15); // Modules 12-15 in zone 3

}

void loop(void)
{

 DateTime now = rtc.now();
 char buffer[] = "hh:mm";  // hours and minutes

   for (uint8_t i=0; i<NUM_ZONES; i++)
    P.displayZoneText(i-1, now.toString(buffer), PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);

P.displayAnimate();
}

I dont't know how to display the hour:minutes and my text simultaneously so that I can do the rest then:
{

 DateTime now = rtc.now();
 char buffer[] = "hh:mm";  // hours and minutes

   for (uint8_t i=0; i<NUM_ZONES; i++)
    P.displayZoneText(i-3, now.toString(buffer), PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT); //here I want to display the hour:minutes on the first row

P.displayAnimate();
}```

edited just now

I know how to display text in all 4 zones. I don't know how to display the real time from the clock module and some other text simultaneously

I know how to do that too

What is the Parola library? Where can your readers find this library? What kind of display does it work with? Briefly, what does it do for you? You should provide all of that information in your question.

Parola is mainly used to format text on led matrix displays. My FC16 led modules are based on MAX7219 led matrices. I can't really figure out how to display the time properly and a message simultaneously

you say that you can convert time to text, and you can display text in all zones, then what is actually the problem? ... i am just not able to understand with what you are having a problem ... please add some pictures that show the problem

Your first problem is the definition of the text array:
const char  *pc[NUM_ZONES] =
{ "TIME",      // This will be replaced by real time its only for logic of rows here
  "ROOM",
  "SUBJECT",
  "CLASS"
};

then we need a timer, as you only show minutes we only have to change time in that interval to prevent flicker and other unwanted effects and hour for changing texts lateron:
uint8_t lastUpdateMin = 0;
uint8_t lastUpdateHour = 0;

Then the loop looks like
void loop() {
   DateTime now = rtc.now();
   if(lastUpdateMin != now.minute()){  // change every minute
     lastUpdateMin = now.minute();
     char buffer[] = "hh:mm";  // hours and minutes
     P.displayZoneText(0, now.toString(buffer), PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT); // 1st row
    }
  if(lastUpdateHour != now.hour()){     // change every hour
     lastUpdateHour = now.hour();
     P.displayZoneText(1, pc[1], PA_RIGHT, 0, 0, PA_PRINT, PA_NO_EFFECT);  // 2nd row
     P.displayZoneText(2, pc[2], PA_LEFT, 0, 0, PA_PRINT, PA_NO_EFFECT);   // 3rd row
     P.displayZoneText(3, pc[3], PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT); // 4th row
    }
P.displayAnimate();
}

Things to do - define a two dimensional char table with all the texts needed for the different hours
#define NUM_LECTUREHOURS 7       // seven hour lectures
const char *pc[NUM_LECTUREHOURS][NUM_ZONES] = {
  { "TIME", "ROOM_0", "SUBJECT_0", "CLASS_0"},
  { "TIME", "ROOM_1", "SUBJECT_1", "CLASS_1"},
  { "TIME", "ROOM_2", "SUBJECT_2", "CLASS_2"},
  ...
  { "TIME", "ROOM_Last", "SUBJECT_Last", "CLASS_Last"}  // _Last in this example = 6
};

and display with a variable based on the hour so if your classes start at 9:00 you would use
uint8_t lectureHour= now.hour() - 9; // as arrays start with 0

and your different texts would be called like
  P.displayZoneText(1, pc[lectureHour][1], PA_RIGHT, 0, 0, PA_PRINT, PA_NO_EFFECT); // 2nd row

If your char array gets to large - depending on the texts - you will have to use PROGMEM which is an issue on its own. Hope this gets you started
EDIT
If you want to change every two hours you do
if(lastUpdateHour != now.hour() && lastUpdateHour +1 != now.hour() ){     // change every two hours
or shorter for a variable timespan (e.g. every three hours)
 if( now.hour() - lastUpdateHour > 3 ){     // change every three hours

I did everything you showed me until the char table and it isn't working. It's not displaying anything. And when I build the char table it says "conflicting declaration 'const char* pc [7][4['  "

Please start with the simple example and test, do not go for the full solution before you make the simple work. And edit your question and show the "new" code

just did that  .

I guess you just start your ESP so hour returned = 0 so either wait one hour (just kidding) or set the initial hour to 99 and use my original loop as in your program is an errorinbrackets!

god bless! and if I want to change the text every 2 hours?

See my edit in the answer

It works. Tell me, why the same code that worked a minute ago is not working at all the next moment when I upload? Eg. it worked just fine awhile ago and now it doesn't display anything at all or it displays just some random dots. Without doing hardware changes. Is this a hardware problem or a soft one? The same code, the same untouched hard connections. Sometime works, sometime won't.

Might be an issue with the used libraries, lookup issue tracker of the libs on github for similar problems/solutions. Link can be found in library manager of the IDE under the used lbrary


text:
Receiving garbage value when sending a Json object from Arduino Uno to NodeMCU using SoftwareSerial
I am trying to send a Json Object from Arduino UNO to NodeMCU using SoftwareSerial. I am using Arduino IDE. I am getting garbage value on Serial monitor of NodeMCU. Tried it with different garbage values, couldn't receive data from Arduino UNO. Below is the code. PLease help. Thank you in advance. I haven't made a common ground. I have referred this webpage here.
Arduino UNO code:
    #include <SoftwareSerial.h>
    #include <ArduinoJson.h>
    SoftwareSerial s(5,6);

    void setup() {
    s.begin(9600);
    }

    void loop() {
     StaticJsonBuffer<1000> jsonBuffer;
     JsonObject& root = jsonBuffer.createObject();
      root["data1"] = 100;
      root["data2"] = 200;
      if(s.available()>0)
      {
       root.printTo(s);
      }
    }

NodeMCU code:
    #include <SoftwareSerial.h>
    SoftwareSerial s(D6,D5);
    #include <ArduinoJson.h>

    void setup() {
      // Initialize Serial port
      Serial.begin(9600);
      s.begin(9600);
      while (!Serial) continue;

    }

    void loop() {
      StaticJsonBuffer<1000> jsonBuffer;
      JsonObject& root = jsonBuffer.parseObject(s);
      if (root == JsonObject::invalid())
        return;

      Serial.println("JSON received and parsed");
      root.prettyPrintTo(Serial);
      Serial.print("Data 1 ");
      Serial.println("");
      int data1=root["data1"];
      Serial.print(data1);
      Serial.print("   Data 2 ");
      int data2=root["data2"];
      Serial.print(data2);
      Serial.println("");
      Serial.println("---------------------xxxxx--------------------");

    }

I haven't made a common ground. -- they maybe you should? https://majenko.co.uk/blog/importance-sharing-grounds

I tried making common ground too, same result

The problem with ArduinoJson.h is that it doesn't ensure robust and reliable transfer over UART serial.
Instead, you should use SerialTransfer.h to automatically packetize and parse your data for inter-Arduino communication without the headace.The library is installable through the Arduino IDE and includes many examples.
Here are the library's features:

This library:

can be downloaded via the Arduino IDE's Libraries Manager (search "SerialTransfer.h")
works with "software-serial" libraries
is non blocking
uses packet delimiters
uses consistent overhead byte stuffing
uses CRC-8 (Polynomial 0x9B with lookup table)
allows the use of dynamically sized packets (packets can have payload lengths anywhere from 1 to 254 bytes)
can transfer bytes, ints, floats, and even structs!!

Example TX Arduino Sketch:
#include "SerialTransfer.h"

SerialTransfer myTransfer;

void setup()
{
  Serial.begin(115200);
  Serial1.begin(115200);
  myTransfer.begin(Serial1);
}

void loop()
{
  char buff[] = "hi";

  myTransfer.txObj(buff, sizeof(buff));
  myTransfer.sendData(sizeof(buff));
  delay(100);
}

Example RX Arduino Sketch:
#include "SerialTransfer.h"

SerialTransfer myTransfer;

void setup()
{
  Serial.begin(115200);
  Serial1.begin(115200);
  myTransfer.begin(Serial1);
}

void loop()
{
  if(myTransfer.available())
  {
    char buff[40];

    myTransfer.rxObj(buff, sizeof(buff));

    Serial.println("New Data: ");
    Serial.write(buff, sizeof(buff));
    Serial.println();
  }
  else if(myTransfer.status < 0)
  {
    Serial.print("ERROR: ");

    if(myTransfer.status == -1)
      Serial.println(F("CRC_ERROR"));
    else if(myTransfer.status == -2)
      Serial.println(F("PAYLOAD_ERROR"));
    else if(myTransfer.status == -3)
      Serial.println(F("STOP_BYTE_ERROR"));
  }
}

Thank you so much. It solved my problem. The transmission is proper now.


text:
Driving higher loads with PWM
My Arduino Pro Micro can source 500mA from 3.3V VCC, when it is USB powered.
The chip itself, is rated for 200mA, though, and its output pins for 20mA recommended, 40mA max.
I am looking to have 3 PWM outputs, though, each doing 120mA. The combined 360mA would be in-spec for VCC, but not for the chip.
Is there a buffer IC that I can use that will switch these loads at that current, and can keep up with a few hundred Hz PWM?
From what I've read, you can switch loads with discrete transistors, but these require extra components like resistors? Are there CMOS chips that will take the PWM signal and output it at 120mA?
I am looking to source the current, not sink it.
The load in my application are LEDs driven with constant-current drivers that are daisy chained. I just want to PWM the Vled supply so I can dim per channel, of the entire daisy chain.
UPDATE: I went with @Majenko's solution of pre-biased DTB114EK. Although it somewhat works, it seems to struggle to deliver 30mA out, even though it is rated at 500mA?
UPDATE: The DTB113ZC works better. Due to a lower bias resistor, I can get more current through it.

@gbg that datasheet seems to indicate it needs 4.5V to operate? My Arduino runs with 3.3V as VCC. Also, 2A per channel is far more than I need?

Wait, what kind of load do you have? RGB LED, I presume?

@gbg It is complicated. I drive LEDs with a TLC5928 but I want to dim them per channel, by modulating Vled. I now there is the TLC5940 option, but I want to stick with the 5928. So the load is a led, hooked up to a constant current driver. I'll add a link to my application.

You can get pre-biased transistors that don't need resistors, such as the DTB114ECHZG.

@Majenko Thanks! That looks interesting. So I would hook my PWM output to the base, my VCC to emitter and the load to the collector? Also it mentions 'invertor.' Does that mean that I need to reverse my duty cycle?

That's correct. You pull the base LOW to turn the output ON. You could add an NPN (or n-FET) to invert it for you if you wanted but that's more components...

How about the ULN2003?

@gbg They sink current, not source it.

I used this module https://wiki.seeedstudio.com/Grove-MOSFET/

Use a transistor. Here is an example schematic and calculations I did for an NPN BJT transistor. You can learn how to do the math and process yourself following my answer.

Here is a part that will do the job for you, just 4 wires to connect.  Use your favorite search engine or go to your favorite china supplier and use this term: "Low Control High Voltage 12V 24V 36V switch Mosfet Module For Arduino Connect IO MCU PWM Control Motor Speed 3V 5V". You will get many choices several in the dollar range. It is opto isolated so that eliminates the ground connections etc. I have used them several times and they work nicely.


text:
Control of 3 LEDs over Bluetooth using MIT App Inventor
As per title, I have 3 LEDs connected to an Uno. Also connected is an HC-05.
edit: forgot to add a question, my bad.  Is there any glaring major issues in this code that I've overlooked?  Not looking for anyone to write my code for me, just want to understand what I messed up and an idea of how to fix.
const int RED=2;
const int BLUE=4;
const int GREEN=6;

String inputString;
String buttonId;

char junk;

void setup() {
  Serial.begin(9600);
  pinMode(RED, OUTPUT);
  pinMode(BLUE, OUTPUT);
  pinMode(GREEN, OUTPUT);
  digitalWrite(RED,LOW);
  digitalWrite(BLUE,LOW);
  digitalWrite(GREEN,LOW);
}

void loop()
{
  if(Serial.available()){
  while(Serial.available())
    {
      char inChar = (char)Serial.read(); //read the input
      inputString += inChar;        //make a string of the characters coming on serial
    }
    Serial.println(inputString);
    while (Serial.available() > 0)
    { junk = Serial.read() ; }
    if(inputString == "r_on"){      // control red led
      digitalWrite(RED, HIGH);
    }else if(inputString == "r_off"){
      digitalWrite(RED, LOW);
    }
    inputString = "";
    if(inputString == "b_on"){      // control blue led
      digitalWrite(BLUE, HIGH);
    }else if(inputString == "b_off"){
      digitalWrite(BLUE, LOW);
    }
    inputString = "";
    if(inputString == "g_on"){      // control green led
      digitalWrite(GREEN, HIGH);
    }else if(inputString == "g_off"){
      digitalWrite(GREEN, LOW);
    }
    inputString = "";
  }
}

Picture of my App inventor block program in imgur link below
https://i.sstatic.net/F6jBq.jpg

Was there a question to go with this?

I see a huge bug in the beginning where you are throwing away data without knowing what it is.  But I don't know if that's what you're asking about.  Reading data is way faster than it arrives, so if you send "r_on" that first available will be true when the 'r' gets there.  Nothing else has made it yet so it exits.  Now you got a chance that maybe when the '_' gets there its on the first available call, but that might happen right before it gets there and then the second one catches it and throws it away.  Now we play the same russian roulette game with the 'o' and the 'n'.

In the end you don't know which characters you got and which ones you threw away.  Throwing away serial data or "clearing the buffer" as noobs like to say is almost never a good idea.  There shouldn't be junk in there unless you put it there.  There's no reason to throw it away.  Just don't send it if you don't want it.

So, the code just throws away the string before it can even reach the if statements? Or am I misunderstanding?

The one that says junk=Serial.read() and then you don't do anything with junk.  That is throwing away data.  You don't know that junk was a good character or a bad character.  You seem to think that when the first if statement catches that it will read the whole entire string.  But there's no guarantee that the whole string has arrived yet.  You're at 9600 baud (why so slow?) so there's about a millisecond between characters.  In that time your loop function can repeat hundreds of times.  It's not going to sit in that while loop waiting for the whole message to get there.

And whenever a character does arrive, you're playing Russian roulette with it.  Maybe it arrives after the first if statement runs but before the second one.  In that case it will be read into the junk variable and never used.


text:
ESP8266 print DNS address (obtained via DHCP)
I've set up an ESP8266 (Wemos D1 Mini) to get IP-information via DHCP.
Everything works fine and I can print the information :
Serial.print(WiFi.macAddress());
Serial.print(WiFI.localIP());
Serial.print(WiFi.subnetMask());
Serial.print(WiFi.gateway.IP());
But how do I print the DNS-address ??
I cant find a function for this ???
/Kind regards : Gurra

https://arduino-esp8266.readthedocs.io/en/latest/esp8266wifi/station-class.html#dnsip

Serial.println(WiFi.dnsIP());

If you have more than one DNS server you can specify the index:
Serial.println(WiFi.dnsIP(1));

Thanks Majenko, i've Googled this question and found answers to ip, netmask, mac & gateway but not DNS, so you saved me hours of extra work by this....So I am very grateful !!

You're welcome. You can find all the functions in the ESP8266WiFiSTA.h header file.


text:
Eclipse AVR for arduino not uploading
I recently read this post about setting up Eclipse for Arduino.  I Build the test project with no erros, but when I go to upload my test project it just hangs at 5%, with no error messages.
If I unplug the arduino-uno it cancels the upload, so I know it can see the arduino board. It is just not uploading. Does anyone have any ideas as to what is wrong?
I don't know whats changed, but now it doesn't hang i just get a message after trying to upload:

avrdude: stk500_recv(): programmer is not responding

Does the Arduino IDE upload successfully with the identical physical setup?

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


text:
Blank Serial Print AdaFruit BTLE
I working on a prototype with an Arduino UNO and an AdaFruit Low Energy Blue tooth
I have an array of uint32_t that I am trying to send via blue tooth to a given device.  I don't think i can send the array so I was trying to send it as a comma separated string.
I can print out each individual index of that array just fine, but its completely blank when i try to make a comma separated String..  See code and comments below.
Ay Array:
uint32_t items[]= {0,3513728,7925384,0,0,0};

In My Loop:
String output = "";

for(int i = 0; i<6;  i++){

  BTLEserial.print(items[i]); // Prints as expected
  output += getStringForUI32_T(items[i]);
  output+=",";

 }
 BTLEserial.print(output); // prints BLANK

I imagine this has something to do with memory but I am at a complete loss.. Please help!

Does it work when printing to the normal serial monitor? BTLEserial.print might not accept a String as an input and instead just print out the pointer address. You might have to copy it to a char buffer first (toCharArray(but,len)).

I doesn't work on Serial.println either..  behaves pretty much the same way.  would you mind showing me how to do the buffer way above.. C is not my strongest suite

There's no reason to concatenate everything into a temporary String - just send each piece in its own call to the sending function.

I'd probably do it directly like:
for(int i = 0; i<6;  i++) {
  BTLEserial.print(items[i]);
  BTLEserial.print(',');
}
BTLEserial.println();

But with the string I think it would be something like:
String output = "";

for(int i = 0; i<6;  i++) {
  output += getStringForUI32_T(items[i]);
  output+=",";
}
BTLEserial.println(output[0]);

But as someone else got it working using String on your adafruit thread maybe this is just barking up the wrong tree.

@ChrisStratton How about that for the String object? I didn't realise you could reference the char array of the String using [].

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


text:
Controlling keyboard LEDs with USB Host Shield
I've got a USB keyboard connected to my Arduino Uno with a USB Host Shield. I'm reading keystrokes using this example from the USB Host Shield library.
I need to toggle the LEDs in the keyboard (that indicate the state of Caps Lock, Num Lock etc.)
This thread mentions using Usb.setReport(), but this method doesn't seem to exist any more: there's no such method in Usb.cpp in the library. There does seem to be a method called SetReport in the USBHID class, which looks like it takes the same arguments, which I'm trying to use.
What I'm currently doing:
void keyboard_setup(){
    static HIDBoot<USB_HID_PROTOCOL_KEYBOARD> HidKeyboard(&Usb);
    if (Usb.Init() == -1) {
        Serial.println("OSC did not start.");
    }
    delay(200);
    HidKeyboard.SetReportParser(0, &Prs);

    static USBHID usbhid(&Usb);
    uint8_t leds = 1;
#define KBD_ADDR 1
#define KBD_IF 0
    usbhid.SetReport( KBD_ADDR, 0, 1, KBD_IF, 0, &leds );
    delay(100);
    leds = 255;
    usbhid.SetReport( KBD_ADDR, 0, 1, KBD_IF, 0, &leds );
    delay(100);

Neither call to SetReport seems to work, and I'm not certain the values of KBD_ADDR or KBD_IF are correct (I'm using ones that I've seen in examples), or event that calling SetReport is right .
What am I doing wrong?

I posted an answer but deleted it.  My 1st thought was that you were creating your own instance of the SetReport method (which you are) that didn't work w/any USB device.  But looking at your code again - I'm not so sure.

@st2000 I'm creating my own instance of USBHID, which I don't otherwise use, because I seem to need it to use SetReport(). I'm not sure if that's the right approach though.

This is going to take a bit of thinking for me.  But I think the best way to go about controlling the keyboard LEDs is to expose SetReport to your Sketch by adding a wrapper method to the USBHost library.  Otherwise, I'm thinking you need to setup all the USB stuff in your Sketch - which the driver already is capable of doing.

I thought NicoHood/HID github page was the answer, but I think it works with custom keyboard and does not necessary work w/standard USB keyboard LEDs.

the NicoHood/HID uses an Arduino to emulate a keyboard .... there is no actual keyboard involved

There does seem to be a method called SetReport in the USBHID class, which looks like it takes the same arguments, which I'm trying to use.

The method arguments of the new SetReport() method aren't quite the same and some are in a different order.
The old method signature was:
uint8_t setReport( uint8_t addr, uint8_t ep, unsigned int nbytes, uint8_t interface, uint8_t report_type, uint8_t report_id, uint8_t* dataptr );

...while the new one is:
uint8_t SetReport(uint8_t ep, uint8_t iface, uint8_t report_type, uint8_t report_id, uint16_t nbytes, uint8_t* dataptr);

It seems to me the equivalent call would be:
usbhid.SetReport( 0, KBD_IF, 0x02, 0, 1, &leds );


text:
Arduino Uno R3 not working after shorting 5V to GND
While wiring up my new Arduino Uno R3 on a proto-board, I accidentally shorted the 5V pin directly to Ground. The LED's immediately turned off and connection was lost. It was powered by USB connection. After 3-5 seconds I removed the short. The LED's have remained out, and I haven't been able to reestablish connection with my computer since. I've unplugged and re-plugged the USB cable and tried the re-set button plenty of times. This short shouldn't have fried the board...  what happened? How can I get my Arduino working again??

Have you tried restarting the computer? The computer will shut down the usb port to protect it from a malfunction like this (over-current).

@sachleen can you please post your comment as an answer, so that we don't see this question as unanswered although it has been solved already?

After it is solved you should mark the answer as correct.

Have you tried restarting the computer? The computer will shut down the USB port to protect it from a malfunction like this (over-current).
You can also try the ports on the other side of the computer (or front/back) as they're usually on different controllers.

The genuine Arduino boards feature a digital (temperature based) fuse.
When shorting an Arduino, it will heat up the fuse on the Arduino. When the fuse gets to a certain temperature, it will automatically cut off the power from the USB connection to the Arduino board.
When the fuse cools down, it will conduct again.
The motherboards of most computers these days also work with these digital fuses, so you might have heated up both. It wouldn't hurt to reboot the PC and disconnect the Arduino and give it a minute to cool down.
If it still doesn't work, you might have fried the Arduino or the specific USB port.
Try a USB port that is likely not connected to the same USB controller in the PC. Meaning, don't just try the first USB port next to the one you used, but try a USB port on the other side of the PC / laptop, they are likely to be connected to different USB controllers.


text:
Pixy(CMUcam5) robot Distance code
Can anyone help me with the code-ing to allow the robot to stop at a certain distance when the robot is approaching the tracked object. I am trying to implement it as a colour tracking wheel chair. For Example, the motorized wheelchair is able to track the colour of the shirt of the person infront is wearing and follow the person, and at the same time it is able to leave a distance between the person infront and the wheelchair to prevent collision.
the pixy robot : https://learn.adafruit.com/pixy-pet-robot-color-vision-follower-using-pixycam/overview
The code :https://learn.adafruit.com/pixy-pet-robot-color-vision-follower-using-pixycam/the-code
Currently the code is only able to track the object till it reaches the object. But my objective is to let it chase the object, but at the same time, leaving a 1 metre distance
away from the object.
Please help me. Thank you

Try to play with this one:
int forwardSpeed = constrain(400 - (size/256), -100, 400);

By changing the value of 256 and 400, not at the same time though, you better use 2 potentiometer to change those values. That's a trial and error though, I hope this will give you an idea.

Old question, but I'd simply use the angle of the Pixy tilt mechanism. If the camera is mounted low (on a wheelchair) and looking up (to see a t-shirt), the angle will be more "up" when the t-shirt is close.
void loop()
{
   if(tiltAngle < 45) // Angle in degrees
      moveWheelChairForward();
}

However, if someone bends down, the tilt angle will go down, so the wheelchair will ram them! Thus, a proximity sensor is probably still going to be needed.


text:
Can you query the current serial port's speed?
Is there some code I can use to find out what the a chosen serial port's speed is running at ?

Might just be easier to define the speed in a variable :)

Do you mean the PC or some other device sets the serial speed, and the Arduino to adjust itself to match?

There is not a top level, easy to use way. Sorry. It is probably easier to just store your chosen baud rate in a variable when you setup the serial port.
Anyway, What you can try to do for the AVR-based, hardware UARTs is undo what Serial.begin does to set up a particular baud rate, but its a bit of a pain. This is the code for setting the baud rate:
  // Try u2x mode first
  uint16_t baud_setting = (F_CPU / 4 / baud - 1) / 2;
  *_ucsra = 1 << U2X0;

  // hardcoded exception for 57600 for compatibility with the bootloader
  // shipped with the Duemilanove and previous boards and the firmware
  // on the 8U2 on the Uno and Mega 2560. Also, The baud_setting cannot
  // be > 4095, so switch back to non-u2x mode if the baud rate is too
  // low.
  if (((F_CPU == 16000000UL) && (baud == 57600)) || (baud_setting >4095))
  {
    *_ucsra = 0;
    baud_setting = (F_CPU / 8 / baud - 1) / 2;
  }

  // assign the baud_setting, a.k.a. ubrr (USART Baud Rate Register)
  *_ubrrh = baud_setting >> 8;
  *_ubrrl = baud_setting;

You can find the results of this by reading the right UCSRA, UBRRH, and UBRRL registers. On an uno those are the correct register names, on an mega its UCSR0A, UBRR0H, UBRR0L for Serial, UCRS1A ... for serial1 and so on. Non-avr boards (and Serial on a leonardo) will be totally different.
There will be a single state for those three registers on an AVR hardware serial port for a particular board (and frequency of that board) at each baud rate. You can try and make an equation to get the original baud rate out, but I recommend just comparing the direct values with a lookup of some kind because the integer arithmetic rounding errors will make it a huge mess.
For example, on my mega UBBR0H, UBBR0L, and UCSR0A are 0, 207, 2 at 9600 baud, but they are 0, 51, 2 at 38400 baud and 0, 16, 0 at 57600 baud.

thanks this is the sort of thing i was looking for, but as said it may be more trouble than worth compared with other alternatives.


text:
Send \r or \n via phone serial monitor
I have a bluetooth adapter connected to uno, and using a serial monitor on phone.
In the arduino code im debugging there is this line waiting for new line signal in the serial stream:
char c = SerialBT.read();

if (c == '\r' || c == '\n'){

no matter what i try sending to via my phone i cant get this to evaluate as true...
if i send \n , i believe it is sending it as 2 chars \ and n , not as a single char.
is this a problem with the phone app or what ?

It turns out it was a problem with the android terminal program i was using, by switching to another that specifically has support and options for \n \r things it works now.

If you had used third party app terminal, and in EditText field you wrote Hello World\n then yes it will send it as '' and 'n' because it reads them  as chars.


text:
Help needed understanding Due performance
I'm going to be writing some performance critical code and have started trying to get an understanding of timers and how much "work" the Due CPU can do per second.  To help get started with this, I wrote a bare sketch that simply increments a counter whilst a timer which ticks every second dumps the value of the counter to the serial log and then resets the counter.  Here's the code I'm using:
#include <Arduino.h>

void EnableTimer7TickEverySecond();

volatile uint32_t gCounter = 0;

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

    EnableTimer7TickEverySecond();

//  while ( true )
//  {
//      ++gCounter;
//  }
}

void loop()
{
    ++gCounter;
}

void EnableTimer7TickEverySecond()
{
    pmc_set_writeprotect(false);
    pmc_enable_periph_clk(ID_TC7);
    TC_Configure(TC2, 1, TC_CMR_WAVE |
        TC_CMR_WAVSEL_UP_RC | TC_CMR_TCCLKS_TIMER_CLOCK1);
    TC_SetRC(TC2, 1, 656000 * 64);
    TC_Start(TC2, 1);
    TC2->TC_CHANNEL[1].TC_IER = TC_IER_CPCS;
    TC2->TC_CHANNEL[1].TC_IDR = ~TC_IER_CPCS;
    NVIC_EnableIRQ(TC7_IRQn);
}

void TC7_Handler()
{
    TC_GetStatus( TC2, 1 );

    Serial.println( (uint32_t)gCounter );

    gCounter = 0;
}

When I run this, I get values averaging 446,000 in the serial log for the increments per second.  That is way lower than I was expecting.  On an ARM chip running at 84MHz, I'd expect at least 14 million increments as few ARM instructions take more than 2 clock cycles and an increment should involve a read from memory, addition and a write back to memory (approx 6 clock cycles by my reckoning).
The timer is configured correctly, the TX led flashes regularly at 1 second intervals as the Serial.println is called.  I've checked for overflow on the counter (oddly, I found that the number of increments when working with a uint64_t was slightly higher).  I've also tried not calling Serial.begin() until I'm about to write the value to the log (and then only writing the value once) and whilst there is a slight increase in "performance", it doesn't account for the whole difference between expectation and reality.
My best guess would be that loop() is called on some sort of timer or has a built in default delay, so it occurred to me that if I comment out the counter increment in loop() and instead comment in the infinite while loop in setup(), I should be able to counteract any delay caused by how frequently the Arduino IDE calls loop().  I have seen other examples that never bother with loop() and just stick all their code in setup().
I do see a performance increase with this setup, but only to around 9 million, not the 14+ million I would expect. Oddly though, sometimes, randomly, the value is 2 or 3 times the "usual" value.  Not between 2 and 3 times, but exactly 2 or 3 times.  This happens regardless of whether I am incrementing the counter inside the loop() function or my own loop inside setup().  It is not a case of the timer "skipping", the output is written every second like clockwork.
So, my questions are:

What does the Arduino library do to make loop() so inefficient?
Is there any harm in keeping all your code inside an infinite loop in
setup() and never returning out of it?
Why would I sometimes see the number of increments being 2 or 3 times
higher than usual?  Could the counter be getting cached (despite
being marked as volatile) and not reset properly?  If so, how can I
prevent this?

What does the Arduino library do to make loop() so inefficient?

Alot.  For a start it's a function, so it has to push registers onto the stack before it runs, and pop them off afterwards.  Secondly there is the "serial event" system outside the loop.  In main.cpp in the core you can see how loop is called:
setup();

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

Is there any harm in keeping all your code inside an infinite loop in setup() and never returning out of it?

If you don't use serial events, no harm whatsoever.

Why would I sometimes see the number of increments being 2 or 3 times higher than usual? Could the counter be getting cached (despite being marked as volatile) and not reset properly? If so, how can I prevent this?

My guess is the operations you are using are not atomic.  This is, the interrupt is able to be fired right in the middle of doing the series of instructions that perform the increment. The temporary registers end up not being the same as they were at the start of the operation, and consequently the value is corrupted.  You should wrap the increment in a critical section (i.e., disable interrupts before it, and enable them afterwards).
To better analyse the speed of execution you can look at the generated assembly code of your program.  If we look at the disassembled main() function for the bit where it loops you can get this:
80596:  f7ff fe05   bl  801a4 <loop>
8059a:  4b04        ldr r3, [pc, #16]   ; (805ac <main+0x30>)
8059c:  2b00        cmp r3, #0
8059e:  d0fa        beq.n   80596 <main+0x1a>
805a0:  f7ff feec   bl  8037c <_Z14serialEventRunv>
805a4:  e7f7        b.n 80596 <main+0x1a>
805a6:  bf00        nop

loop() consists of this:
801a4:  4b02        ldr r3, [pc, #8]    ; (801b0 <loop+0xc>)
801a6:  681a        ldr r2, [r3, #0]
801a8:  3201        adds    r2, #1
801aa:  601a        str r2, [r3, #0]
801ac:  4770        bx  lr
801ae:  bf00        nop

If we feed that into main() where it calls loop() the finished code looks like:
80596:  f7ff fe05   bl  801a4 <loop>
801a4:  4b02        ldr r3, [pc, #8]    ; (801b0 <loop+0xc>)
801a6:  681a        ldr r2, [r3, #0]
801a8:  3201        adds    r2, #1
801aa:  601a        str r2, [r3, #0]
801ac:  4770        bx  lr
801ae:  bf00        nop
8059a:  4b04        ldr r3, [pc, #16]   ; (805ac <main+0x30>)
8059c:  2b00        cmp r3, #0
8059e:  d0fa        beq.n   80596 <main+0x1a>
805a0:  f7ff feec   bl  8037c <_Z14serialEventRunv>
805a4:  e7f7        b.n 80596 <main+0x1a>
805a6:  bf00        nop

So that is what gets executed for every single iteration of loop().  If we (incorrectly) assume that each instruction takes 1 clock tick, that's 13 ticks.  84,000,000 / 13 = ~6.4 million loops per second.
Now - if we map the instructions against actually how many clock cycles they take, we can get a clearer picture:
bl                  1+P  (P = 1 to 3)
ldr (pc relative)   2
ldr (word)          2
adds                1
str (word)          2
bx                  1+P  (P = 1 to 3)
nop                 1
ldr (pc relative)   2
cmp                 1
beq.n               1 or 1+P (P = 1 to 3)
bl                  1+P (Only if serial event runs)
b.n                 1 or 1+P (P = 1 to 3)
nop                 1

So taking a worst case scenario where P = 3 (pipeline re-fill clock counts, that is), and no serial event running, we can calculate a total number of clock cycles of 4+2+2+1+2+4+1+2+1+4+0+4+1 = 28.
84,000,000 / 28 = 3,000,000 loops per second.
But hang on - that's still much more than you're seeing.  That's because you're still only looking at the small picture.  You're looking at just your sketch and forgetting what else there is going on.
Every millisecond the SysTick_Handler() gets called which does various tasks, including calling the TimeTick_Increment() routine to deal with millis().  That's 1,000 times per second, and that eats into your processing time somewhat.
Another important point is it can't be incrementing while you're running your interrupt.  The more you do in your interrupt (and using serial is a very heavy-weight thing to do in an interrupt) the less of your 1-second slice you get for doing your incrementing.
As an experiment, why not try disabling all the interrupts except just the one you are using for your timer and see how it changes the value.

Thanks for the extremely detailed answer. Where do you get the disassembly from? I find it interesting that it appears to be 16bit THUMB instructions rather than the 32bit ARM instructions.  I was planning to optimise a certain section of my code using ARM assembler.

Yes, it's thumb.  The compiler is called with the -mthumb option.  To get a disassembly you need to use arm-none-eabi-objdump -h -S <elf file>


text:
nuttx hex too large
I have a teensy 4.1, and I am trying to install NUTTX the Real Time Operating System ( RTOS ). Teensy is a supported platform.
I am trying install nuttx compiled from source, and upload it using the teensy loader program. my current issue is that the hex file is too large. the file size is 229Kb, which shouldn't be an issue where the flash size for a teensy 4.1 is 8MB.
I have been following the steps on these websites:
this one where Nuttx is installed on a teensy 3, and the documentation for nuttx on their website
any tips or recommendations to install nuttx on a teensy 4.1 would be greatly appreciated.

OK, so I pressed the reset button and the teensy loader program reset, and reloaded the hex file. Now it lists as I would expect it to, using 1% of the flash space. and uploads without error.


text:
Mouse.move: how do I move the mouse to the center of a screen?
I have a program operating in full screen mode. I would like to move the mouse to the center of the screen. Is this something I can do with the functionality of Mouse.h?
https://www.arduino.cc/reference/en/language/functions/usb/mouse/
Mouse.move moves fixed increments. maybe I should change the mouse start location in the computer program.
my issue, is that the "circuit playground" is the primary interface, using the accelerator for position. Once the computer is running the software, the Arduino has to be centered to work properly.
alternatively, is there a command I can send that could center the mouse?

There are two ways of working with HID mice - absolute and relative. The Arduino Mouse library only works in relative mode, but you want absolute.
There's another library https://github.com/NicoHood/HID which does do considerably more than the normal Arduino HID libraries - including "Absolute Mouse".

hey cool, samd21 support!
Thanks @Majenko


text:
teensy as a keybooard throws error as keyboard input
I have a program (bash script) I wrote that is for stop motion animation. The script works perfectly, when I use any given keyboard on my laptop, and it works on other computers, as well.  So i wanted to add a controller, using a teensy, and the keyboard library. source here:
The teensy, set up as a keyboard, using one of the example codes, which I modified. The output appears correct: when I press any of the buttons, I get the expected output (asdw). But, the script throws an error, and exits anyhow, which means something else is being sent besides the key presses I desire.
So, WHY?
Here is the keyboard source for the teensy:
 /* Buttons to USB Keyboard Example

   You must select Keyboard from the "Tools > USB Type" menu

   This example code is in the public domain.
*/

#include <Bounce.h>

// Create Bounce objects for each button.  The Bounce object
// automatically deals with contact chatter or "bounce", and
// it makes detecting changes very simple.
Bounce button0 = Bounce(0, 10);
Bounce button1 = Bounce(1, 10);  // 10 = 10 ms debounce time
Bounce button2 = Bounce(2, 10);  // which is appropriate for
Bounce button3 = Bounce(3, 10);  // most mechanical pushbuttons
Bounce button4 = Bounce(4, 10);
Bounce button5 = Bounce(5, 10);  // if a button is too "sensitive"
Bounce button6 = Bounce(6, 10);  // to rapid touch, you can
Bounce button7 = Bounce(7, 10);  // increase this time.
Bounce button8 = Bounce(8, 10);
Bounce button9 = Bounce(9, 10);

void setup() {
  pinMode(0, INPUT_PULLUP);
  pinMode(1, INPUT_PULLUP);
  pinMode(2, INPUT_PULLUP);
  pinMode(3, INPUT_PULLUP);
  pinMode(4, INPUT_PULLUP);
  pinMode(5, INPUT_PULLUP);
  pinMode(6, INPUT_PULLUP);  // Teensy++ LED, may need 1k resistor pullup
  pinMode(7, INPUT_PULLUP);
  pinMode(8, INPUT_PULLUP);
  pinMode(9, INPUT_PULLUP);
}

void loop() {
  // Update all the buttons.  There should not be any long
  // delays in loop(), so this runs repetitively at a rate
  // faster than the buttons could be pressed and released.
  button0.update();
  button1.update();
  button2.update();
  button3.update();
  button4.update();
  button5.update();
  button6.update();
  button7.update();
  button8.update();
  button9.update();

  // Check each button for "falling" edge.
  // Type a message on the Keyboard when each button presses
  // Update the Joystick buttons only upon changes.
  // falling = high (not pressed - voltage from pullup resistor)
  //           to low (pressed - button connects pin to ground)
  if (button0.fallingEdge()) {
    Keyboard.println("s");
  }
  if (button1.fallingEdge()) {
    Keyboard.println("d");
  }
  if (button2.fallingEdge()) {
    Keyboard.println("w");
  }
  if (button3.fallingEdge()) {
    Keyboard.println("a");
  }
}

What should I do to just get the key presses (asdw) from the teensy as if it were a plain old keyboard.

You are calling Keyboard.println() which sends the character string followed by a new line.  If you want to emulate a keyboard you should only use Keyboard.print() which only sends the character string with no new line.

Ok I figured it out. The code includes "keyboard.println". I should use "keyboard.print instead", to properly simulate keyboard presses. the newline is what was screwing it up.


text:
Flip text in LCD screen
Im using <LiquidCrystal.h> arduino library,on a 2x16 LCD screen, with an accelerometer. I'd like to flip the the text when my x value exceeds N value. I get how to output text.
I tried straight up flipping the text, with an online converter, but the text that renders is garbage.
  lcd.print("¡pןɹoʍ 'oןןǝɥ");  // Print a message to the LCD.

what does this actually mean? ... flip text

@jsotola it means to rotate the letters. see example in the question. as Majkenko points out unicode chars wont do. but i have an idea.

I asked because it could also mean to reverse the background and foreground colors

@jsotola, ah I see.

can you link the datasheet of the LCD you have

It's not possible. The text is a simple ASCII character set that is encoded in ROM. It can't (other than a few user-defined characters) be changed. And being simple ASCII it doesn't support any UNICODE characters which are used for "upside down" text.
To do what you want you'd need a graphical LCD screen instead of a pure text one.

maybe I can make a bunch of byte arrays and write my own alphabet of upside down glyphs. Im dyslexic AF so it should be fun. I wonder how much it'll occupy in memory

@j0h You only have 8 user defined characters. Not enough for the whole alphabet. Maybe enough for a short word or two...

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


text:
lcd.createChar() only allows for 8 custom characters
I have a teensy4.1, with a 16 by 2 LCD screen, and an I2C LCD interface.
I was trying to write a bunch of custom characters to an LCD screen, to flip some text.
my issue is that it works fine, but on only up to 8 custom characters. any more than that produces odd results. with a loop of 16, the first 8 characters are printed. should more than 8 characters be defined, only the last assigned are in use.
I commented out all but the first 8 custom characters, and iterates through them in a loop of 16 iterations. this loops over the start. -- I guess that works as I would expect. If I define more than 8 custom Characters, only the last 8 assigned will output.
Here is a picture of that in action:

here is my code:
#include <Adafruit_LiquidCrystal.h>
Adafruit_LiquidCrystal lcd(0);

//upside down char glyphs... default characters are 7x5 1 px w/space on the bottom
//these glyphs are 7x5 with space on the top
byte uA[8] = {  B00000,  B10001,  B10001,  B10001,  B11111,  B10001,  B10001,  B01110};
byte uB[8] = {  B00000,  B01111,  B10001,  B10001,  B01111,  B10001,  B10001,  B01111};
byte uC[8] = {  B00000,  B01110,  B10001,  B00001,  B00001,  B00001,  B10001,  B01110};
byte uD[8] = {  B00000,  B00111,  B01001,  B10001,  B10001,  B10001,  B01001,  B00111};
byte uE[8] = {  B00000,  B11111,  B00001,  B00001,  B01111,  B00001,  B00001,  B11111};
byte uF[8] = {  B00000,  B00001,  B00001,  B00001,  B01111,  B00001,  B00001,  B11111};
byte uG[8] = {  B00000,  B11110,  B10001,  B10001,  B11101,  B00001,  B10001,  B01110};
byte uH[8] = {  B00000,  B10001,  B10001,  B10001,  B11111,  B10001,  B10001,  B10001};
byte uI[8] = {  B00000,  B01110,  B00100,  B00100,  B00100,  B00100,  B00100,  B01110};
byte uJ[8] = {  B00000,  B00110,  B01001,  B01000,  B01000,  B01000,  B01000,  B11100};
byte uK[8] = {  B00000,  B10001,  B01001,  B00101,  B00011,  B00101,  B01001,  B10001};
byte uL[8] = {  B00000,  B01111,  B00001,  B00001,  B00001,  B00001,  B00001,  B00001};
byte uM[8] = {  B00000,  B10001,  B10001,  B10001,  B10101,  B10101,  B11011,  B10001};
byte uN[8] = {  B00000,  B10001,  B10001,  B11001,  B10101,  B10011,  B10001,  B10001};
byte uO[8] = {  B00000,  B01110,  B10001,  B10001,  B10001,  B10001,  B10001,  B01110};
byte uP[8] = {  B00000,  B00001,  B00001,  B00001,  B01111,  B10001,  B10001,  B01111};
byte uQ[8] = {  B00000,  B10110,  B01001,  B10101,  B10001,  B10001,  B10001,  B01110};
byte uR[8] = {  B00000,  B10001,  B01001,  B00101,  B01111,  B10001,  B10001,  B01111};
byte uS[8] = {  B00000,  B01111,  B10000,  B10000,  B01110,  B00001,  B00001,  B11110};
byte uT[8] = {  B00000,  B00100,  B00100,  B00100,  B00100,  B00100,  B00100,  B11111};
byte uU[8] = {  B00000,  B01110,  B10001,  B10001,  B10001,  B10001,  B10001,  B10001};
byte uV[8] = {  B00000,  B00100,  B01010,  B10001,  B10001,  B10001,  B10001,  B10001};
byte uW[8] = {  B00000,  B01010,  B10101,  B10101,  B10101,  B10001,  B10001,  B10001};
byte uX[8] = {  B00000,  B10001,  B10001,  B01010,  B00100,  B01010,  B10001,  B10001};
byte uY[8] = {  B00000,  B00100,  B00100,  B00100,  B01010,  B10001,  B10001,  B10001};
byte uZ[8] = {  B00000,  B11111,  B00001,  B00010,  B00100,  B01000,  B10000,  B11111};
//pockets
byte cornerA[]={B11111,B10000,B10000,B10000,B10000,B10000,B10000,B10000};//top left
byte cornerB[]={B10000,B10000,B10000,B10000,B10000,B10000,B10000,B11111};//btm left
byte cornerC[]={B11111,B00001,B00001,B00001,B00001,B00001,B00001,B00001};//top right
byte cornerD[]={B00001,B00001,B00001,B00001,B00001,B00001,B00001,B11111};//btm right
void flip(char *text);
void setup() {
  Serial.begin(9600);
  lcd.begin(16,2); //
  //flipped characters
lcd.createChar(0,uA);
lcd.createChar(1,uB);
lcd.createChar(2,uC);
lcd.createChar(3,uD);
lcd.createChar(4,uE);
lcd.createChar(5,uF);
lcd.createChar(6,uG);
lcd.createChar(7,uH);
lcd.createChar(8,uI);
lcd.createChar(9,uJ);
lcd.createChar(10,uK);
lcd.createChar(11,uL);
lcd.createChar(12,uM);
lcd.createChar(13,uN);
lcd.createChar(14,uO);
lcd.createChar(15,uP);
/*lcd.createChar(16,uQ);
lcd.createChar(17,uR);
lcd.createChar(18,uS);
lcd.createChar(19,uT);
lcd.createChar(20,uU);
lcd.createChar(21,uV);
lcd.createChar(22,uW);
lcd.createChar(23,uX);
lcd.createChar(24,uY);
lcd.createChar(25,uZ);
lcd.createChar(26,cornerA);
lcd.createChar(27,cornerB);
lcd.createChar(28,cornerC);
lcd.createChar(29,cornerD);
*/
  //ascii coversion prolly like n+66
  //setCursor be like: (column, row) 16 cols, 2 rows, both start at 0
lcd.setCursor(0,0);

  for (int i=0; i<16;i++){
  lcd.write(i); //prints ABCDEFGHABCDEFGH
  lcd.setCursor(i+1,0);
  delay (500);
  }
  lcd.setCursor(0,1);
  lcd.print("LIMIT 8 CHARS?");
}

void loop() {}

I would like to make more than 8 customChars, am I approaching this correctly? is there a limit somewhere I can change?

Note that some letters need not be flipped: HINOSXZ. For others, you could use lookalikes: M → W, P → d, b → p, d → q...

@EdgarBonet: And (depending on the character set in the particular device used) there may be other usable characters too. Most HD44780 displays have some katakana characters, so eg E → ヨ may also be usable.

These displays only allow up to 8 custom defined characters. The hardware just only has the character RAM for at most 8 characters. They will be mapped to char codes 0 to 7 and 8 to 15. The character code 8 always prints the same character as code 0, 9 as 1 and so on.
So no, there is no way to use more than 8 custom characters at once. Of course, you can change the characters dynamically, so that a certain location of the screen always shows a changing custom character icon.

Bloody hell, its in the datasheet. I tried modding the library first, and that did not work.
https://cdn-shop.adafruit.com/datasheets/HD44780.pdf

Yea, you can modify the library, but you can't modify the hardware...


text:
How does an 8bit MCU make use of data-types over 8bits?
how does an 8bit MCU handle 16bit output?
How does an 8bit MCU store values higher than 8bits?
I am using an attiny, on an adafruit trinket. and other 8bit MCUs.
http://www.atmel.com/devices/attiny85.aspx
I was doing some things with uint32_t datatypes, when it hit me, that it would seem like uint32_t would be an incompatible datatype. Even 2Byte data type like int seems peculiar. "int stores a 16-bit (2-byte) value"
considering the MCU is 8bit.
I saw this link, that sounded like it would have more info, but its pages are incomplete. http://playground.arduino.cc/Code/DatatypePractices
So how does that work?
How does an 8bit MCU make use of data-types over 8bits?

Human children are often first taught to do arithmetic with single-digit arguments, and then to do operations on multi-digit place-value numbers using rules that give a sequence of single-digit operations.  Computers use very similar methods, doing multiple word-width operations to accomplish wider ones.

It's the compiler that convert the 32-bit operations into 8-bit instructions.

Is MCU micro controller unit?

The basic answer is that the processor does math in 8-bit chunks, so it takes more instructions than it would on a 32-bit processor.
A good answer is found in EE.SE

Actually a 1-bit MCU could be used to execute code (e.g. C/C++) with N-bit numbers. Not very fast as it will require O(N) operations for addition and subtraction.
To better understand this for the 8-bit AVR MCU used in Arduino I recommend reading the Instruction Set Description Manual, AVR/GCC Wiki and assembler code listings for some sketches. This will reveal the secret(s) behind this "alien technology/magic".
Cheers!


text:
how can i conect a lipo charger to a teensy 4.0?
I have the battery charger product https://www.adafruit.com/product/2124
and a teensy 4.0, that I would like to use to power it.
what, if any pin would I connect from bat, to the teensy?
Its my understanding that the Lion backpack is a voltage regulator, and thats it. it takes Vin, ground, and Vout.
I understand the 5v output goes to the 5volt pin of the teensy.
the gnd goes to gnd. should Vin go someplace? Or should I leave it off?
Please assist.

the charger does not have a Vin pin

The output voltage of the charger board is marked with BAT. You should connect it to the Vin pin of the Teensy, which then will convert the batteries 3.7-4.2V down to 3.3V.
Of course you need to connect the grounds of the charger board and the Teensy (on the charger board ground is marked with G).
The 5V pin on the charger board is no output. The board does not give you 5V. This is actually the pin for the charging voltage, which is 5V. Here it depends on how you want to charge the battery. If you use an external source, you can simply connect it's 5V to the board. If you want to use the USB jack of the Teensy, you can connect the boards 5V to the Teensys 5V. But: Be sure to cut the little trace between Vin and VUSB/5V at the back of the Teensy. You don't want to connect the battery voltage with an USB power source.

I was going back and forth on that. I didnt want to smoke my teensy experimenting, and I couldnt find clear statements on that. I hooked it up that way, and it totaly worked though. A side note, the teensy has a tutorial on cutting vin away from a pad connected to VUSB. VUSB has a through hole via though. I cut the trace between the via and the VUSB pad, giving me a larger pad to solder to. I would have preferred a via for VIN, but using 2 pads seems to make a pretty solid connection.


text:
how can I delete contents of an SD card in arduino?
I have a datafile, datalog.txt I can open, read and write cool. What is the best way to delete all the file contents?
Should I try rewriting the SD card file with NULL data?
I have been reading the "SD.h" header file. I see a flush() and truncate() function should I use one of these?
or maybe I should just close  and reopen the file, and overwrite the data. But I'm concerned that this might lead to some miss representations if the old data is not completely removed.
I am using a teensy 4.1 with built_in SD card.

Just open the file. There is no "not completely removed".

To remove a file use SD.remove("datalog.txt");
SD library's FILE_WRITE is O_READ | O_WRITE | O_CREAT | O_APPEND so it would append at the end of the existing file.
to start with an empty file: File file = FS.open("datalog.txt", O_READ | O_WRITE | O_CREAT);
EDIT: opening the file with O_READ | O_WRITE | O_CREAT doesn't clear the content of the file, only starts to overwrite it from the beginning.


text:
'Basic electronics' resources
I've seen that there are many resources on programming basis for arduino for people that have some electronics basis or background. Are there similar resources on the opposite? Basics electronics for programmers? Things that cover:

How to read schematics (different elements that appear there)
What different pins are used for (yeah, even on a more basic level than arduino documentation)
General idea of how a protoboard/protoshield works and how to connect components
General common components (resitors, capacitors...) and when and how to use them...
Safety rules, what happens when you do something wrong

Hi, this question is way too broad for this site. In fact, it's really 5 very broad questions in one. If you could re-word questions to make them more specific they would be a better fit for our Q & A format.

I'm asking for a colection of links/books con the topic. Thought. There's no specific cuestión but i thought it would be nice to have it posted here for future newcommers. If it's not appropiate I can deleite it.

no need to delete. These kinds of questions, while very useful, are difficult to manage. Something like this could turn into a never ending post with hundreds of edits and comments. That's just not what this site is for.

From zero to Arduino (maybe a HOWTO someday?)
Rule zero:

Don't overestimate the other Arduino users! They all were not born with this knowledge too.
Never be too shy to ask!
Making mistakes is ok as long as they trigger learning.

(-: short break :-)
You'll find lots of HOWTOs and other tutorials in the wild wild web.
I assume, the confusing thing is to read them in the wrong order.
Forget your Arduino(s) for a while and start with reading about:

General common components (resitors, capacitors...) and when and how to use them...

This will at least partially answer:

Safety rules, what happens when you do something wrong
How to read schematics (different elements that appear there)

If not already done:

Read about ANDs, ORs, NANDs, NORs, FLIPFLOPs...

This will show how their schematic symbols look like.

...compare them to creating the same behaviour by programming (if,
and (&&), or (||), ...)
Have a look at bit operations (&, |, ... on whole number variables.

The programming up to this point can be done on your PC.
After this, dedust your Arduino again and jump into:

What different pins are used for (yeah, even on a more basic level
than arduino documentation)

(Happy end. At least for now.)
(I make this a community wiki answer to invite others to expand this text.)

Well making mistakes in electronics can cost a lot: from a few bucks to your life!

Yes... the dangerous mistakes should be avoided... but when turning a logic chip into magic smoke and then learning why this happened at least was a honourable dead for that chip. And to avoid the most dangerous mistakes, you can power your Arduino by a battery pack and keep it far away of 120V/240V power lines... at least in the beginning...

@jfpoilpret When applying for the Darwin awards (what I have seen done on Arduino.EE couple times already) does not obey yeti's rule #0 sub 3:  "Making mistakes is ok as long as they trigger learning."

mmm, should we open showcase thread on arduino darwin awards? could be funny, and illustrative too :p

Instead of joking arround, you could have improved the answer. That's what wiki is desiged for...

This is an extract of an introductory book that shows basic schematic  components:

Hi, please add more information to your answer. Link-only answers are discouraged as it becomes useless if the link target changes or gets removed.

@sachleen -- As of now, the link is dead.


text:
Is it harmful to write to unused bits in PORT registers?
Background:
I'm looking at writing a library to drive an LED matrix panel (one of these:http://www.adafruit.com/product/607) from my newly acquired Arduino Due.  My background is C++ programming, not electronics.
I'm planning to experiment with various optimisations of the code for memory and speed, but one constant is that I would like to be able to send the data to the matrix with single memory writes to port registers without having to use masking operations to leave certain bits unaffected.  As I need to send 6 bits of data with a clock signal, I figured this could be easy with an 8 bit write to one byte of a port register.  The 8th bit/pin could be used as the latch or some other used line.
Looking at the nice pinout diagram that someone has kindly put together (http://forum.arduino.cc/index.php/topic,132130.0.html), I was pretty shocked to discover that my plans weren't going to be as easy as I would have liked.  There are only two circumstances where there are whole bytes of port registers that connect to digital pins (Port A byte 1 and Port D byte 0).  All other bytes have "holes" in them, for example Port C byte 0 has no connection for bit 0, but has bits 1-7;
While two complete bytes is enough (I actually only need to use 13 pins to control the display, plus ground connections), the pins of the available two are spread out in a way that would make it a little awkward for me to make a stripboard shield as I intended due to the pins on the Arduino boards not being evenly spaced (why is that?) and I'm guessing that since most of the digital pins in Port A byte 1 are used for communication pins (including RX0 and TX0) I would lose my ability to print to the debug log.  As a result, I've ruled out using those port registers.
That leaves me with bytes 0 and 1 of Port C.  There are just enough pins available with those bytes and they are grouped nicely on the double connector at the bottom of the board (Digital pins 33-40 and 48-51), however some bits in those bytes are not mapped to Arduino IO pins.
Would it be bad if I were to write to bits of a port register that do not have Arduino IO pins assigned to them?  Would the answer depend on whether I had set those bits to be inputs or outputs using the Output Write Enable Registers?  I'm assuming that these bits are used for IO pins on the SAM3X8E chip but just not made available to the Arduino boards.

If the pins have no connection to the outside world (i.e., they don't have any actual pin associated with them on the SAM3X chip) then writing to the PORT (or indeed any other register associated with them) will have no effect whatsoever.
If they have a pin but that pin is not connected to anything, then there will be little effect.  There may be slightly increase current draw as the pin switches on/off, or you enable/disable the internal pullup resistor, but that's all.
If the pin exists and is connected to something on the board - maybe a button or LED, then you will basically be providing an output to that item.  If it's an LED it will flash.  However, if it's a button, and you provide an output opposite of its active state (i.e., provide a HIGH when it normally connects to ground when you press it) and that button lacks any current limiting resistance, then you could risk burning out that IO pin if the button gets pressed.
If the pin just goes straight to a header, then as long as nothing gets connected to that header then there will be no effect other than as detailed in the "pin present on the chip but not connected".

Thanks for the very concise info. Do you known how I can find out if the bits of a PORT register do relate to pins on the SAM3X chip and then if those pins are used on the Arduino board?

Read the datasheet and the schematic.


text:
panstamp device signature is random
I Have 2panstamp. I can program the first but not the second with the arduino program.
When I upload the sketch (a simple blink) on the second, I got this

Reading | ################################################## | 100% 0.03s

avrdude: Device signature = 0x004e22
avrdude: Expected signature for ATmega328P is 1E 95 0F
Double check chip, or use -F to override this check.

avrdude done.  Thank you.

And if I retry, I got this.

Reading | ################################################## | 100% 0.03s

avrdude: Device signature = 0x81f014
avrdude: Expected signature for ATmega328P is 1E 95 0F
Double check chip, or use -F to override this check.

avrdude done.  Thank you.

The device signature is not the same anymore ...
I've changed the wire and re-open arduino program. But it don't change, the device signature change (often 0xE1E1E1). I've check the connection between the ATmega and the wire and everything is ok.
Is the Panstamp broken ? or should I do a kind of factory reset?

Is the Panstamp broken ?

Sounds like it. If one works, and the other does not, using the same wiring, it looks like you have a faulty one.

or should I do a kind of factory reset?

You can't really "factory reset" a chip like that. Possibly there is a problem with the fuses. You may be able to explore further here:
Have I bricked my Arduino Uno? Problems with uploading to board


text:
From transfer function to arduino
This question might seem stupid, but I have been curious about it for a long time.
So I am a new engineering student, and we learned a lot about "designing a controller". For example, design controller for a car steering system and so on. All the "controllers" we designed are in the Laplace domain aka s-domain. And most of the times it will be just a transfer function. So how do real control system engineers use these transfer functions in arduino and other microcontrollers? I mean you cannot just put the function in there right?
Do you have to convert the transfer function to some other form and write the code for the microcontroller or is there a simpler way to do it?
Thanks for your time!

Let's assume you have an Arduino that you have arranged to sample a signal with a sample rate of 1/T that is then processed by your controller. Let's also assume that the processing time for your controller is small compared to T e.g. 0.1/T
Firstly, you need to convert the controller transfer function to discrete time. There are lots of ways to do this. Matlab has a convenient c2d() function. One way you can do it on paper (not the best way), is to use Euler's Method.
s=(z-1)/T   where T is the sampling period.
Converting a transfer function then: (s+a)/(s+b) => (z-(1-aT))/(z-(1-bT))
So now you have a TF in z such as : Y(z)/X(z)=(z-c)/(z-d)  where Y is the output and X is the input.
To implement this in a controller you need this as a difference equation in terms of delays. So convert the equation to a function of (z^-1) which is a delay:
Y(z)/X(z) = (1-cz^-1)/(1-dz^-1)
and re-write as:
Y(Z)(1-dz^-1) = X(z)(1-cz^-1)
Y(Z)-d.Y(z).z^-1 = X(z)-c.X(z).z^-1
and change to sample time treating z^-1 as a delay:
y(n) - d.y(n-1) = x(n) - c.x(n-1)
rearranging:
y(n) = d.y(n-1) + x(n) - c.x(n-1)
You can implement this easily in the Arduino by realising that y(n-1) is the previous value of y(n) and similarly for x(n), and x(n) is the value input to the controller; i.e. the reference minus the output from the ADC.

Would you mind giving us some code example in order to implement these kind of exercises? I would be really thankful to you. In my case a have a transfer function a/s+a, "a" is a value a have to enter through a keyboard connected to the arduino mega, i have calculated the operations like this, using tustin method: a1Z+a2/b1Z+b2 where each value is: a1=a2=(aT/aT+2); b1:is always 1; and b2:aT-2/aT+2. T is the sample time.
As you can see I have calculated everything but I have difficulties in the programming code in arduino mega, if you can help me I would be really thankful.


text:
Most efficient way to store number in EEPROM?
I would like to store temperature readings in eeprom, the value from -55.00 to 125.99. What is the most space efficient way to store these numbers with two significant digits along with epoch timestamp?
Thanks

My best off-the-top-of-my-head figure is 6 bytes.
4 bytes for the timestamp (assuming a 32-bit value).  Two byte for -32768 to +32767.
Multiply the temperature by 100 to make it into the integer range -5500 to +12599. That then fits comfortably inside a 16-bit signed integer.
However, there are other tricks you can use.
For instance, if you know the time of one reading you don't need to store the time of the next - only how much later it is.  One byte can then store up to 255 "whatevers" later than the previous entry - be that seconds, minutes, hours, whatever.
Similar with the temperature.  You can just store the difference from the previous reading as a single byte if you know that successive readings will never deviate by more than +/-1.27 degrees.
Also, you can check to see what the last saved temperature was, and only save a new temperature if it has changed from before.
Another thing is the resolution of your data.  You say 2 decimal points, but if the values are all multiples of 0.05 then what is the point of storing at 0.01 resolution?  Just store how many 0.05s there are (divide by 0.05) then multiply it out again afterwards to get the original temperature.  Most useful when coupled with a temperature difference to increase the storage range.
There's many tricks, you see, and which work best depend exactly on what you want to do with the data.

Wow, thank you so much! this is gold, I really like the temp diff and the resolution ideas.

Multiply the temperature by 100, not 10 !

Oops, typo there.


text:
How to request data via I2C?
How do you program an Arduino Uno to request data over I2C, sending parameters defining the request?
I'm trying to program Arduino A to read a sensor value from another Arduino B, and it first needs to tell B which sensor to report, but I can't find any easy way to do this with Arduino's Wire library. There doesn't seem to be anything like Wire.requestFrom(addr, 1235, 2) which would then call a handler on the slave the looks like onRequest(sensor_id).
I found this page on how to push data one way to a slave, and I found this page on how to request data from a slave without specifying any input, but I can't find anything in between.
Is the solution to use the first method to set the parameters, and then the second to get the data? If so, that seems very circuitous. Is there a more direct method?

Welcome to serial communications.

Its the way the protocol is designed. From the very first byte that is sent, you already indicate if you want to read or write data. You can't do both. The protocol is a lot more straightforward this way, one transaction at a time. Plus it gives the feel of a data frame, with START and STOP bits delimiting the frame (not regarding repeated STARTs).
But even for a full-duplex protocol like SPI, you've already said that the master must first send certain parameters to the slave. Nothing can be sent by the slave until it has received these parameters and processed them, full-duplex comms or not. Only after this, can it reply with the requested data.
The Wire methods are designed to send data in one direction at a time, as it should be. You could, of course, create a function like the one in your question, but it would inevitably involve the same process of first writing to the slave and then reading.


text:
Firmata C++ library for host?
Firmata seems to be a popular protocol for communicating between the Arduino and host computer. However, there only seems to be C/C++ libraries for the Arduino. Most Firmata libraries for the host appear to be in Python. I've found a few C/C++ Firmata libraries for the host, but they seem incomplete and unmaintained. Is anyone aware of a full-featured C++ Firmata library designed to run on the host computer?

Do you have an update or answer on this?  I am looking after the same

@JoseECalderon, No. I was researching this as part of a ROS project, but I ended up going with the rosserial_arduino package, which implements its own similar protocol.

openFrameworks appears to have this capability. It's written in C++.
From openFrameworks - Communication:

Arduino and other serial devices communication
The communication module has classes to communicate with other devices
  by now through the serial protocol. This mainly allows to communicate
  with devices like the Arduino. There's 2 classes in this module,
  ofSerial which allows to communicate with any device through the
  serial protocol. It can be used to send custom commands to for example
  an Arduino sketch that will receive them and do something in response
  like turn an LED on, move a motor... It also works the other way
  around, you can send messages from the Arduino (or any other serial
  device), for example the read from a temperature sensor to
  openFrameworks.
The second class, ofArduino, is specific to the arduino, it uses a
  protocol called firmata to send messages to and from the arduino that
  way you don't need to care about implementing the communication
  protocol from the Arduino sketch to openFrameworks and viceversa but
  instead you can just send and read values directly to and from any pin
  in the Arduino.


text:
What are safe memory usage limits?
The Arduino IDE used to warn you when your sketch used too much memory. This warning now seems to have been removed. I compiled a sketch, and was surprised to see it use 175% of data memory...but not give me any explicit warning that this would be unstable, much less be physically unable to load onto the Arduino.
What are program and data memory usage levels that you should be concerned about? I seem to remember the best practice was to keep data memory under 80%. Is this still true? Is there any general rule for program memory?

I'm surprised it even compiled...

It seems unlikely the linker would accept this, perhaps there's a broken configuration as it seems like the percentage is being calculated against something that mismatched the linker map - for example, link for one chip, compare against another.

@Majenko, Me too :)

Had you selected the wrong board?

What version of the Arduino IDE are you using?

The compiler can only report the amount of statically allocated (RAM) memory. Depending on what you are doing in your sketch the value may be important, or it may be completely meaningless.
Suffice it to say, the total of heap + stack + static must not exceed the memory of your MCU.
When it comes to the Flash memory you can go right up to 100%.

There is a "StackPaint" https://arduino.stackexchange.com/questions/763/im-using-too-much-ram-how-can-this-be-measured but I don't know if that still compiles today.

It's a tough question to answer as it depends on the rest of the sketch.  You can safely use every single byte of memory as long as you're sure that's all you're using.  The number that it spits out on compile doesn't tell you that.  It just tells you about global and static variables really.  If you've got a loop that doesn't call any functions then you only need to save a few bytes for the stack. But if you've got a function that creates a local array with 500 ints then you're not safe even if that number it spits out on compile is only 50%.