text:
Send sensor data through GATT with Adafruit Bluefruit
I have the BLE Module Adafruit ItsyBitsy nRF52840 Express and I want to send sensor values from a Hallsensor to my computer. I was able to have the right data checking with the Serial monitor.
int adcin = A1;
int adcvalue = 0;
float mv_per_lsb = 1200.0F/4096.0F; // 10-bit ADC with 3.6V input range
double freq = 100;
uint32_t lastMicros = 0;  //variable to track sampling frequency
double microseconds = 1000000.0;
double interval = microseconds/freq;

void setup()
{
  Serial.begin(115200);
  // Set the analog reference to 3.0V (default = 3.6V)
  analogReference(AR_INTERNAL_1_2);
  // Set the resolution to 12-bit (0..4095)
  analogReadResolution(12); // Can be 8, 10, 12 or 14
  // Let the ADC settle
  delay(1);
}

void loop() {

  // Get a fresh ADC value after intervall (1/freq)
  if (micros()-lastMicros >= interval)
  {
    adcvalue = analogRead(adcin);
    lastMicros = micros();

    // Display the results
    Serial.print(lastMicros);
    Serial.print(" [");
    Serial.print((float)adcvalue * mv_per_lsb);
    Serial.println(" mV]");
  }
}

Then I tried to send these values through BLE connectin to my computer. So I knew I had to create a service and a characteristic for the GATT profile. But using the guide from adafruit was not really helpful. Right know I saw that with the following code I was able to see the module on my computer and read the characteristic I made. But it seems to just give me random Hex values rather than my sensor data.
#include <bluefruit.h>

BLEService        myService = BLEService(0x187A);
BLECharacteristic myChar = BLECharacteristic(0x184D);

BLEDis bledis;    // DIS (Device Information Service) helper class instance

int adcin = A1;
int adcvalue = 0;
float mv_per_lsb = 1200.0F/4096.0F; // 10-bit ADC with 3.6V input range
double freq = 100;
uint32_t lastMicros = 0;  //variable to track sampling frequency
double microseconds = 1000000.0;
double interval = microseconds/freq;
float volt = 0;

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

  //Setup for data acquisition
  // Set the analog reference to 3.0V (default = 3.6V)
  analogReference(AR_INTERNAL_1_2);
  // Set the resolution to 12-bit (0..4095)
  analogReadResolution(12); // Can be 8, 10, 12 or 14
  // Let the ADC settle
  delay(1);

  Serial.println("BLE data acquisition");
  Serial.println("-----------------------\n");

  // Initialise the Bluefruit module
  Serial.println("Initialise the Bluefruit nRF52 module");
  Bluefruit.begin();

  // Set the advertised device name (keep it short!)
  Serial.println("Setting Device Name to 'Adafruit_BLE'");
  Bluefruit.setName("Adafruit_BLE");

  // Set the connect/disconnect callback handlers
  Bluefruit.Periph.setConnectCallback(connect_callback);
  Bluefruit.Periph.setDisconnectCallback(disconnect_callback);

  // Configure and Start the Device Information Service
  Serial.println("Configuring the Device Information Service");
  bledis.setManufacturer("Adafruit Industries");
  bledis.setModel("Bluefruit");
  bledis.begin();

  // Setup the BLEService and BLECharacteristic classes
  Serial.println("Configuring the custom Service");
  setupSer();

  // Setup the advertising packet(s)
  Serial.println("Setting up the advertising payload(s)");
  startAdv();

  Serial.println("Ready");
  Serial.println("\nAdvertising");
}

void startAdv(void)
{
  // Advertising packet
  Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
  Bluefruit.Advertising.addTxPower();

  // Include custom Service UUID
  Bluefruit.Advertising.addService(myService);

  // Include Name
  Bluefruit.Advertising.addName();

  Bluefruit.Advertising.restartOnDisconnect(true);
  Bluefruit.Advertising.setInterval(32, 244);    // in unit of 0.625 ms
  Bluefruit.Advertising.setFastTimeout(30);      // number of seconds in fast mode
  Bluefruit.Advertising.start(0);                // 0 = Don't stop advertising after n seconds
}

void setupSer(void)
{
  myService.begin();

  myChar.setProperties(CHR_PROPS_READ);
  myChar.setPermission(SECMODE_OPEN, SECMODE_OPEN);
  myChar.setFixedLen(4);
  myChar.begin();
}

void connect_callback(uint16_t conn_handle)
{
  // Get the reference to current connection
  BLEConnection* connection = Bluefruit.Connection(conn_handle);

  char central_name[32] = { 0 };
  connection->getPeerName(central_name, sizeof(central_name));

  Serial.print("Connected to ");
  Serial.println(central_name);
}

void disconnect_callback(uint16_t conn_handle, uint8_t reason)
{
  (void) conn_handle;
  (void) reason;

  Serial.print("Disconnected, reason = 0x"); Serial.println(reason, HEX);
  Serial.println("Advertising!");
}

void loop()
{
  // Get a fresh ADC value after intervall (1/freq)
  if (micros()-lastMicros >= interval)
  {
    adcvalue = analogRead(adcin);
    lastMicros = micros();
    volt = (float)adcvalue * mv_per_lsb;
    // Display the results
    Serial.print(adcvalue);
    Serial.print(" [");
    Serial.print(volt);
    Serial.println(" mV]");
    myChar.write16(volt);
  }
}

I really got confusing with how to write my sensor values to the characteristic.
Does anyone know how I can achieve that?
Cheers


text:
How to use 3 digital input pins on Arduino Uno for frequency inputs and total the output?
I am working on a Arduino tachometer that reads the RPM of a BLDC motor. The motor circuit does not use the hall sensors so I would like to use them for RPM sensors. I have already hooked up an Uno board using one pin as an input with the internal pull up enabled and it works fine.The reason I want to use all 3 hall sensors is to increase the pulse count per revolution to steady the reading on my LCD display at lower speeds.
I have been searching for information on how to read 3 inputs, and totalize the pulses for this purpose but have not been able to find the information.

if the sensors have open collector outputs, then you can connect them all together to one input

Assuming that only one sensor will trigger each time then (as jsotola suggested) tie them together and connect the common output to an interrupt pin. Arduino UNO has interrupt functionality on pins 2, 3.
As an example for counting the pulses using pin2 on falling edge (modified from https://www.arduino.cc/reference/en/language/functions/external-interrupts/attachinterrupt/):
const byte interruptPin = 2;
volatile int numPulses = 0; // change type of variable according your needs

void setup() {
    pinMode(interruptPin, INPUT_PULLUP);
    attachInterrupt(digitalPinToInterrupt(interruptPin), sumPulses, FALLING);
    Serial.begin(9600);
}

void loop() {
    Serial.println(numPulses);
    delay(500);
}

 void sumPulses { // keep the ISR as short as possible
    numPulses++;
 }

The hall outputs on the BLDC motors are sinking so two of the outputs are high at any time so parallel won't work. I may have to get a dual shaft motor and add a pickup with a higher PPR count on the rear shaft to achieve the results I am looking for. Thank you for your suggestions though.

An alternative method of frequency determination is to measure period and take the reciprocal. It can be extremely accurate and responsive at very low frequencies, so you don't need to combine multiple sensors just to increase the rate.
Note that you are not limited to measuring a single period; you can count the microseconds in N periods to increase resolution at high frequencies.

source: Stack Exchange

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

sort: votes


text:
Arduino : send data via satellite (or other solutions ? without GSM)
I'm a researcher and I'm looking to build a very tiny embedded system. I must to send data from the desert and above the ocean, to do that I think that my single option is to use satellite transmission (and not GSM).
Thus, I found Iridium Satellite (RockBLOCK) but my main issue is that their Arduino module is too big for my project (4cm of length and too heavy).
Do you know if there is other module to send data via satellite with Arduino ?
If not, do you know other microcontroller which can do that ? (Using Arduino is not mandatory for me)
Thank you a lot,
Sincerely.

This would probably be better asked on the electronics stack exchange. If you post there, you might as well list all of your requirements up front rather than people discovering them as their comments and answers are rejected.

i agree with @timemage ... any useful answers would reach a wider audience in future research ... the other place might be https://iot.stackexchange.com/questions .... the bottom line is, that this question is unrelated to the Arduino, so it is off topic here

My two cents: A possibility might be LoRaWAN on the 2.4GHz spectrum, for which there are also satellites in orbit.
The LoRaWAN ("Long Range Wide-Area-Network") protocol is based on a chirp-spread-spectrum (CSS) modulation and has a very high range.
I've used LoRaWAN before but not on 2.4GHz or with a satelitte, so I can't comment on the practical feasibility. However, there are some materials from The Things Conference (by The Things Network, a leading developer of LoRa network servers).

https://www.youtube.com/watch?v=iwocSYupdIQ
https://www.youtube.com/watch?v=jlNyBDxpKUw
https://enterpriseiotinsights.com/20190618/channels/news/lora-shoots-for-75pc-of-iot-market
https://enterpriseiotinsights.com/20200130/channels/news/lorawan-enters-2-4gh-plus-satellite-boost-network-sharing-embedded-security
https://www.semtech.com/company/press/semtech-and-swarm-deliver-satellite-communications-with-lora

Also maybe other modules that can talk to the Iridium satellites suite you better. Sparkfun has a few

https://www.sparkfun.com/products/13745
https://www.sparkfun.com/products/16394

Thank you a lot for your answer ! I will check that

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


text:
Drawing a line at a given angle
Im attempting a device that measures lean angle. I have an ESP8266 + MPU6050 + SSD1306 setup, and I've managed to build a shaky but somewhat functioning device.
What Id like to do is use the Adafruit_SSD1306 library to call the display.drawLine(x, y, x1, y1, color) function and have the line drawn to the measured angle output of the MPU6050.
The screen I'm using is 128 X 64
The MPU6050 is initially laying flat at 180 degrees, but is set and displayed as 0 degrees of tilt. The line is drawn vertically on the screen and pivots around x1 and y1 at 64, 64 respectively in the middle at the bottom of the screen.
If the MPU6050 pivots left like in the picture, the angle measurement itself is roughly correct, but the line indicator is showing more like 30 degrees than 45, and gets worse the larger the angle value.

My code:
#include <Adafruit_MPU6050.h>
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_Sensor.h>

const int MPU_addr=0x68;
int16_t axis_X,axis_Y,axis_Z;

Adafruit_MPU6050 mpu;
Adafruit_SSD1306 display = Adafruit_SSD1306(128, 64, &Wire);

int minVal=265;
int maxVal=402;

double x;
double y;
double z;
int tiltAngle;
double y2;

void setup(){
  Serial.begin(9600);
  Serial.println("MPU6050 OLED demo");

  if (!mpu.begin()) {
    Serial.println("Sensor init failed");
    while (1)
      yield();
  }
  Serial.println("Found a MPU-6050 sensor");

    // SSD1306_SWITCHCAPVCC = generate display voltage from 3.3V internally
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) { // Address 0x3C for 128x64
    Serial.println(F("SSD1306 allocation failed"));
    for (;;)
      ; // Don't proceed, loop forever
  }

  display.display();
  delay(500); // Pause for 2 seconds
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setRotation(0);
}
void loop(){
  display.clearDisplay();
  display.setCursor(0, 0);

  Wire.beginTransmission(MPU_addr);
  Wire.write(0x3B);
  Wire.endTransmission(false);
  Wire.requestFrom(MPU_addr,14,true);
  axis_X=Wire.read()<<8|Wire.read();
  axis_Y=Wire.read()<<8|Wire.read();
  axis_Z=Wire.read()<<8|Wire.read();
    int xAng = map(axis_X,minVal,maxVal,-90,90);
    int yAng = map(axis_Y,minVal,maxVal,-90,90);
    int zAng = map(axis_Z,minVal,maxVal,-90,90);

     x= RAD_TO_DEG * (atan2(-yAng, -zAng)+PI);
     y= RAD_TO_DEG * (atan2(-xAng, -zAng)+PI);
     z= RAD_TO_DEG * (atan2(-yAng, -xAng)+PI);

     tiltAngle = (int) x - 180; // we want the tilt angle to be 0 degrees
     display.println(" ");
     display.println(" ");
     display.println(" ");

     // display only positive angle values for either direction of tilt
     if(tiltAngle > 0){ display.print(tiltAngle);}
     else if (tiltAngle < 0) { display.print(tiltAngle * -1);}
     else {display.print(tiltAngle);}

     display.drawLine(-tiltAngle + 64, 0,64,64,WHITE);
     display.display();
     delay(100);
}

Im aware that for my first y co-ordinate I will need to use some kind of formula to get the line to move down from 0 (the top of the screen) as the lean angle gets greater. I'm hoping someone could point me in the right direction for drawing the line at the angle given by the MPU6050.
I did consider using case statements for each angle value and drawing the line with fixed co-ordinates based on each angle value. But that seems too compute intensive and could take up too much of the DRAM. Is anyone aware of a simple formula I could use? Thanks for reading.

Use trigonometry (sin() and cos()) functions to get the right x and y coordinates.
I would consider replacing your drawLine() command with something like this (untested) assuming the tiltAngle is in degrees from -90 to +90 (with 0 degrees is straight up) and you want to draw a line at this angle from the origin (63, 63) with a radius of 64.
float tiltAngleRad = tiltAngle * DEG_TO_RAD; // convert angle to radians
int xEnd = 63 + 64 * sin (tiltAngleRad); // Ending x-coordinate offset & radius
int yEnd = 63 - 64 * cos (tiltAngleRad); // Ending y-coordinate offset & radius
display.drawLine (63, 63, xEnd, yEnd);

You might have to experiment with the offset and radius but I believe this will get you close yo what you want.

Hi, thanks for this, I'm gonna have to educate myself more on the trig involved here, but thanks again it seems to work!


text:
Calibrating Adafruit TCS34725 for RGB colors
I am new to Arduino. I am currently working on a project which requires color detection using the TCS34725 Adafruit sensor module.
For the project, I need to calibrate the sensor with RGB colors. Color patches of RGB will be exposed to the sensor. After exposing each color patch, a push button will be pressed and then the calibration for that color should start.

Calibrate for Red

Calibrate for Green

Calibrate for Blue

After calibration, the sensor needs to detect the colors of objects.
I have no idea what is meant by calibrating the sensor for RGB values. Can someone please be kind enough to explain it to me.
Thank you in advance.

It means exposing a known color with known lighting and using the returned sensor data to define that data as, e.g., "red". Subsequent "unknown" colors can then use the calibration data to attempt to identify unknown colors. You might want to check out the Learning Guide which also includes a link discussing (roughly) this topic.

your question is off topic here because it is unrelated to the arduino


text:
Reading and writing to GD25B32CPIG flash memory
I recently removed a GD25B32CPIG flash memory chip from a commercial coin-operated arcade game. Apparently it has all the game's sounds stored directly on the chip. I decided to see if I can learn to communicate with the chip to read the current data and write new data to it so that I can possibly change the game's sounds as the game itself doesn't have the ability to do that.
After searching online, I found schematics for the chip, including its functions and pinouts.

I've wired it up to my Arduino Uno's MOSI, MISO, CK, and SS pins as well as the 3.3V and GND for power. This is the only part I know is correct.
Unfortunately, I am lost on what to do next since I've never used the SPI library by itself (normally other libraries handle the SPI connections in my other projects). Nobody else has a tutorial on this particular chip and I'm a little bit lost by the datasheet's commands. I also did some research on SPI and found the tutorials to be a bit confusing.
I haven't tested anything because I don't want to alter the data unless I know what I'm doing.
The question:
Is there a way to read all data at once and write to a particular register?

https://github.com/Marzogh/SPIMemory may work.


text:
ESP32 Espressif ESP32_DevKitC_V4 in platformio: flash issues
I am using the Espressif ESP32_DevKitC_V4 with platformio, and i cannot flash the board. I read about the various "button dance" procedures, and the ES32-WROVER and the ESP32-WROVER-B seem to behave differently as well.
From the 80 tries of doing the "button dance" i got it one time to work. Are there any other options on how to flash the board with platformio without attaching a 100nF capacitor from EN to GND?
Here is the output when trying to flash
Auto-detected: /dev/ttyUSB0
Uploading .pio/build/ESP32/firmware.bin
esptool.py v3.0
Serial port /dev/ttyUSB0
Connecting........_
Chip is ESP32-D0WD (revision 1)
Features: WiFi, BT, Dual Core, 240MHz, VRef calibration in efuse, Coding Scheme None
Crystal is 40MHz
MAC: 4c:11:ae:6c:c8:b4
Uploading stub...

A fatal error occurred: Invalid head of packet (0x65)
*** [upload] Error 2  ==========

[FAILED] Took 9.83 seconds ==========================
    The terminal process "platformio 'run', '--target', 'upload'" terminated with exit code: 1.

These are the settings in the platformio.ini file:
[env:ESP32]
platform = espressif32
framework = espidf
board = esp32dev
board_build.flash_mode = dio

Thanks everyone for the help!

Reduce the programming baud rate?

A genius solved this problem by attaching a 100nF capacitor from EN to GND.

for the ESP32 DevKitC v4, the pio board configuration should be like this:
[env:esp32dev]
platform = espressif32
board = esp32dev
framework = arduino
board_upload.flash_size = 4MB
build_flags =
   -DBOARD_HAS_PSRAM
   -mfix-esp32-psram-cache-issue


text:
Program SMT32 black-pill without pushing buttons or propriatary devices
Are there any options for programming an STM32 black-pill from the Arduino IDE without first having to manually push buttons to go into DFU mode or having to buy an ST-Link device?
A solution that leverages a second micro-controller board (I have Arduino Nanos, Pi Picos and ESP32 boards available) or requires some (easy) soldering would be fine.

something like Nucleo F303k8 - it has on board stlink and it also emulates hard drive, so you just drag and drop the binary file (or elf, i don't remember)

Your question is one I was recently interested in as I too have begun using Blue/Black Pills, and I am still learning!

Have you got your Arduino IDE set up, and have you added the plugin for the STM32 boards? If not then you can find a tutorial in many places on the internet, one example being on youtube, if you prefer video tutorials...
https://www.youtube.com/watch?v=b1123kz_3MM
Some are better than others and I prefer a written instruction, with or without pics!
Essentially you have to add:-
https://github.com/stm32duino/BoardManagerFiles/raw/master/STM32/package_stm_index.json
to your list or boards in the preferences. Many Tutorials will explain in detail.

Programming options include:

STLink-v2.1 etc. The STLink-v2.1 is easy to source, cheap, and after it is eventually replaced by something else you can even repurpose it as if it is a STM32 USB stick!
FTDI USB to TTL breakout adapter, 3.3v only, connected to the SWD pins on the opposite end to the USB socket.
An Arduino board acting as a TTL/SWD adapter but already kind (talking) to Arduino!
Burning an STM32-Arduino boot-loader onto the blue/black pill, and plug it in like an Arduino, using tutorials.
Install STM32CubeProg, on your host computer, which is free and a very good IDE.
NO DOUBT a search engine (of traditional values!) can find other options including JTAG, JLink, Bus-Pirate, etc. (Avoid search engines that send you straight to selling sites!)

All of these need to be searched, read and understood before a logical choice is made, but all of them are usable choices. Every reader will know that you will get user advice insisting that you do what they have done, or worse, warning you to avoid methods that others have used successfully. Caveat Emptor!

Follow the easiest path to begin with, one of those that are given in the Arduino site perhaps, and investigate others when you have found what you want the process to do, and which process suits your methods and budget. Much depends on memory needs and applications.

you don't answer the question. the question is how to program it over UART without manually setting the BOOT pin


text:
STM32 "black pill" won't enter DFU mode reliably
I'm following the standard process to put an STM32 "black pill" (STM32F401CC) into DFU mode so that I can upload from the Arduino IDE over USB:

Hold down boot0.
Press and release rst.
Release boot0.

When the board is not in a circuit this works somewhat reliably but not 100%. While breadboarding with only a few connections it becomes very unreliable and sometimes won't work at all.
The USB serial device set up by my Arduino sketch works fine, it is only DFU mode that does not want to work.
When it fails to enter DFU mode I see the following error in the Arduino upload process:
      -------------------------------------------------------------------
                        STM32CubeProgrammer v2.13.0
      -------------------------------------------------------------------

An error occurred while uploading the sketch
Error: Target device not found
Establishing connection with the device failed

I'm using Arduino on Ubuntu 20.04 and when it fails I see in /var/log/syslog:
Apr 27 13:26:08 smurfenaar kernel: [79594.279257] usb 1-3: USB disconnect, device number 10
Apr 27 13:26:08 smurfenaar kernel: [79595.078232] usb 1-3: new full-speed USB device number 11 using xhci_hcd
Apr 27 13:26:09 smurfenaar kernel: [79595.192387] usb 1-3: device descriptor read/64, error -71
Apr 27 13:26:09 smurfenaar kernel: [79595.413389] usb 1-3: device descriptor read/64, error -71
Apr 27 13:26:09 smurfenaar kernel: [79595.636370] usb 1-3: new full-speed USB device number 12 using xhci_hcd
Apr 27 13:26:09 smurfenaar kernel: [79595.751435] usb 1-3: device descriptor read/64, error -71
Apr 27 13:26:09 smurfenaar kernel: [79595.973367] usb 1-3: device descriptor read/64, error -71
Apr 27 13:26:09 smurfenaar kernel: [79596.082540] usb usb1-port3: attempt power cycle
Apr 27 13:26:10 smurfenaar kernel: [79596.462407] usb 1-3: new full-speed USB device number 13 using xhci_hcd
Apr 27 13:26:10 smurfenaar kernel: [79596.462674] usb 1-3: Device not responding to setup address.
Apr 27 13:26:10 smurfenaar kernel: [79596.666550] usb 1-3: Device not responding to setup address.
Apr 27 13:26:10 smurfenaar kernel: [79596.874414] usb 1-3: device not accepting address 13, error -71

When it is successful I see:
pr 27 13:22:33 smurfenaar kernel: [79379.772197] usb 1-3: new full-speed USB device number 9 using xhci_hcd
Apr 27 13:22:33 smurfenaar kernel: [79379.899601] usb 1-3: New USB device found, idVendor=0483, idProduct=df11, bcdDe
vice=22.00
Apr 27 13:22:33 smurfenaar kernel: [79379.899605] usb 1-3: New USB device strings: Mfr=1, Product=2, SerialNumber=3
Apr 27 13:22:33 smurfenaar kernel: [79379.899607] usb 1-3: Product: STM32  BOOTLOADER
Apr 27 13:22:33 smurfenaar kernel: [79379.899609] usb 1-3: Manufacturer: STMicroelectronics
Apr 27 13:22:33 smurfenaar kernel: [79379.899611] usb 1-3: SerialNumber: 3466365E3135

and I can also see it with the lsusb command:
Bus 001 Device 052: ID 0483:df11 STMicroelectronics STM Device in DFU Mode

I found this solution in the stm32duino forums:

Tying A10 to GND successfully makes it enter DFU bootloader mode 100% of the time (though just not leaving PA10 floating is probably sufficient)
Hypothesized Explanation: In the last paragraph of Sec 4.3 of AN2606 (the STM bootloader manual), it states:

It is recommended to keep the RX pins of unused bootloader interfaces (USART_RX, SPI_MOSI, CAN_RX and USB D+/D- lines if present) at a known (low or high) level at the startup of the bootloader (detection phase). Leaving these pins floating during the detection phase might lead to activating unused interfaces.

PA10 is the RX pin for USART_1. I believe that since PA10 is floating, the bootloader senses traffic on USART_1, and believes that's the interface it should use, and thus turns off USB. By tying PA10 to GND, the bootloader doesn't sense UART traffic and correctly enables USB.

While I followed the advice of tying it to ground I assume tying it to ground via a high resistance value would work too and should allow you to keep using PA10 for something else. After tying PA10 to GND I find entering DFU mode is 100% reliable, even when the board is in a circuit.

I recently purchased two "WeAct V3.0 STM32F411" Black Pill boards on eBay. I've purchased many boards & other electronic items from this seller in the past without any issues. This eBay seller is very highly rated: 99.8% positive feedback with >1 million items sold. However, I cannot confirm whether these boards are "genuine" WeAct boards since I did not purchase them directly from WeAct.
Both of my Black Pill boards can be programmed with ST-LINK V2 using the standard 3 (or 4) wire SWD interface pins. No problems.
However, both boards initially failed to enter USB DFU programming mode after resetting boards with the BOOT0 button pressed. Then I tried grounding pin A10 as suggested above. This totally fixed DFU programming. Now both boards program perfectly every time via DFU mode.
The only downside is the requirement to press BOOT0 + NRST buttons on board to initiate DFU programming mode prior to uploading with Arduino IDE.


text:
NEMA 17 Stepper motor + Arduino Mega + driver doesn't move using GRBL and UGS
3x NEMA 17 Stepper Motors: https://www.amazon.com/gp/product/B00PNEQKC0/ref=ppx_yo_dt_b_asin_title_o01_s00?ie=UTF8&psc=1
3x DM542T Stepper Driver: https://www.omc-stepperonline.com/download/DM542T.pdf
Power supply: 12V, 30A
Arduino Mega: https://www.amazon.com/ARDUINO-MEGA-2560-REV3-A000067/dp/B0046AMGW0/ref=sr_1_3?dchild=1&keywords=arduino+mega&qid=1623258848&sr=8-3

I am currently trying to use the GRBL (Mega version 1.1f - https://github.com/gnea/grbl-Mega) and Universal G-code sender (UGS classic version 2.0.7 - https://github.com/winder/Universal-G-Code-Sender) to program my 3 NEMA 17 Stepper motors, but none of the motors move. I have tried powering just one NEMA motor using a simple arduino code successfully.
I successfully uploaded the GRBL Mega software onto the arduino and connected that with the UGS. Upon using the toggle buttons, the status shows that the coordinates are jogging, but my stepper motor does not move. I probed the pins with an oscilloscope as well and read a continuous 5V on pins 11 and 12, which I don't exactly understand. Shouldn't there be pulses sent to the pins used, not continuous voltage?
Here are my current connections:
V+ on driver is connected to V+ on power supply
V- on power supply is connected to GND on arduino and GND, DIR-, PUL- on the driver
The other four wires are connected from motor to driver.
DIR+ is connected to pin 5, and PUL+ is connected to pin 2
Please suggest anything I can try!

There's... a lot of things you could try. There's at least two layers of troubleshooting: circuit (which we can't see) and GRBL config, which includes both the GRBL compilation itself, e.g., everything custom required for the driver, and the customization doable once it's loaded (neither of which we can see).

Solved! I mistakenly assumed pinouts were the same on the Arduino Uno vs. Mega configurations. Changing the pins worked!

can you please provide pinouts that has to be changed.


text:
Can't transfer information from esp8266 to arduino
I have esp8266. Which I am trying to set up to be a self-contained access point and server (tcp).
ESP8266 is connected to ports 2,3 of Arduino Uno. On Arduino, I want to process all information coming into esp8266.
Here is my current connection diagram:

And a simple code like this:
ESP8266
/* Create a WiFi access point and provide a web server on it. */
#include<SoftwareSerial.h>
#include <ESP8266WiFi.h>
#include <WiFiClient.h>

/* Set these to your desired credentials. */
const char *ssid = "JP_TestAP";

int status = WL_IDLE_STATUS;
boolean alreadyConnected = false; // whether or not the client was connected previously

WiFiServer server(23);
WiFiClient client;

void setup()
{
   delay(1000);
   Serial.begin(9600);
   Serial.println();
   Serial.print("Configuring access point...");
   /* You can remove the password parameter if you want the AP to be open. */
   WiFi.softAP(ssid);
   delay(200);
   IPAddress myIP = WiFi.softAPIP();
   Serial.print("AP IP address: ");
   Serial.println(myIP);

   Serial.println("\nStarting server...");
  // start the server:
  server.begin();
}

void loop()
{
  // wait for a new client:
  if (!client) {
      client = server.available();
  }
  else
  {
     if (client.status() == CLOSED) {
      client.stop();
      Serial.println("connection closed !");
    }
    if (!alreadyConnected) // when the client sends the first byte, say hello:
    {
      // clead out the input buffer:
      client.flush();
      Serial.println("We have a new client");
      client.println("Hello, client!");
      alreadyConnected = true;
    }

    if (client.available() > 0) {
      // read the bytes incoming from the client:
      char thisChar = client.read();
      // echo the bytes back to the client:
      server.write(thisChar);
      // echo the bytes to the server as well:
      Serial.print(thisChar);
    }
  }
}

Arduino Uno
#include<SoftwareSerial.h>
SoftwareSerial esp8266(2,3);
String message = "";
bool messageReady = false;
void setup() {
  // put your setup code here, to run once:
 Serial.begin(115200);
esp8266.begin(9600);
}

void loop() {
  while(esp8266.available() > 0) {
    message = esp8266.readString();
    messageReady = true;
  }
  if(messageReady) {
    Serial.println(message);
    messageReady = false;
    return;
  }

}

Unfortunately, I am not receiving any information from the ESP8266 (just a clear log on monitor port). I don't understand where the mistake.

ESP Rx to Uno 3, ESP Tx to Uno 2.

@hcheung what did you mean?

i think i already have same connection, which you mention

@hcheung okay, sorry. I tested. now it works. (i tested many variants, how i can miss that?, maybe when i tested "right version" smth whent wrong with Arduino IDE)


text:
Modbus TCP together with MQTT over same ethernet
I'm currently in a planning phase for a project.
I want to read some sensor data over Modbus TCP, do some simple calculations on the Arduino and publish the results over MQTT. Which means I have 2 RJ-45s and two different protocols.
Given a Arduino Mega with an Ethernet shield.
Does it work if I simply add a network switch and connect the sensor and an internet router to it, and use both protocols in parallel?
Or are there any problems running such a thing on only one Arduino?

don't underestimate Arduino. here are the ino files of Arduino sketch for my main project: https://github.com/jandrassy/Regulator#sketch it runs on ATmega1284p boaard. and a simpler Modbus TCP project with web server https://github.com/jandrassy/IsgModbusTcpSG which runs on Nano Every

Does it work if I simply add a network switch and connect the sensor and an internet router to it, and use both protocols in parallel?

Kind of, yes. You just connect both the MODBUS device and the Arduino to the network provided by the router. The Arduino is just a normal network device - the IP address for it allocated by the router, as is the MODBUS device.
Any device can communicate with any other device in a network.


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

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

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

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

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

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

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


text:
What wireless protocols can be used with arduino?
Before you close this saying it's not related to programming. It is related to programming since i'm using it and asking about libraries.
What are the common types of communication protocols and their libraries? Theres WiFi which uses esp8266 etc. Zigbee which can be used with XBee, Bluetooth which can be used with esp32 and others.
What are a list of wireless protocols and chips and libraries for those wireless communications? (This list will be compiled by multiple people hopefully so its okay if you don't know the library or chip but protocol is good) thank you and hopefully no take down <3

Any and all protocols can be used if you can find/build/program the interface to them.

I'm asking what protocols exist. Link a list?

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

this question is not arduino specific

Arduino can use all wireless protocols both in existence today and which yet will be invented in the future. There is no limit to wireless protocols which may be used with Arduino. The correct answer is: all of the protocols.

Arduino allows you to connect external peripherals (via I2C, SPI, UART, I/O) and shields.
It'll be impossible to list them all, as you can even make your own; but here an overview of the most common I can think off:

WiFi
Bluetooth
LoRa
Zigbee
Z-wave
RF (433mhz)
InfraRed
GSM/LTE

It'll be a trade-off between signal range, power usage, delay and bandwidth.
Do note that your question in this way is quite broad. If you want to use this to start your own wireless proejct, you can follow these steps (, but do note that we expect one to do some research/tests himself before posting a question):

Find a tranmission layer applicable for your project based on requirements.
Find Arduino compatible hardware (if none found; make your own or find another transmission layer / adjust requirements)
Find libraries/examples of this hardware being used with Arduino.
Buy the hardware (this is not step 1!)
Use the found sources and make your project reality.


text:
Arduino 2 times slower? Broken?
Hello I have been here for a couple hours troubleshooting code and turns out it wasn't even my code that was the problem. My arduino uno is like 2 times slower than what its supposed to be. If I blink a led with a delay of 500ms it takes 1 second. I was using it last night and it was working just fine. I am working on a remote of sorts and the IR led was going retartedly slow. So then I switched it to my backup, still didn't work. Then digitalWrite showed me it was 2 times slower than it should be. I haven't done anything to it besides the following: (Flashed it around 100 times since i got it). I've only had it for like a month so I would appreciate if someone could tell me what I could do to fix it :/

Do you have the right board selected in the menu? Is serial still working at the correct baud rate?

My programmer is set to "AVRISP mkil", board is set to "Arduino uno". And I have used 19200 in Serial.begin before and its possible that I tried to flash it as a esp8266 but yeah.. That's about it :/

If you Serial.print() something, is that received correctly in your Serial Monitor with the same baudrate used in the sketch?

@chrisl I can't tell the speed but if I set the serial monitor to 9600 and Serial.begin(9600) I can see it fine it seems.


text:
Smallest microcontroller?
I am looking for a microcontroller that is small (like a attiny10) which is the smallest one I could find.
Requirements I need: analogRead on 1 pin, 7 pins for analogWrite to micro leds so in total 10 pins (ground, power, analogRead, analogWrite). It's circuitry has to be basic no adding extra things like a crystal oscillator etc.. This will allow me to send a certain code to the recieving pin and then the microcontroller decide which led to turn on.

10 pins already rules out the smallest microcontrollers. Also I'm sure you have other requirements, like the minimum amount of (flash/ram) memory it has, does it have to be through-hole or surface mount. Since you're posting this on an Arduino site, does it need to be compatible with the Arduino IDE? Does it need to be an AVR processor? There are other ways to control individual LEDs that don't need an output pin per LED. Have you looked into those?

The physical size of a microcontoller is mainly dictated by its pins. The distance between each pin is set by the package type. The typical hobbyist microcontrollers use the DIP package with 0.1" pin pitch. But when you have chosen a fitting microcontroller, which fits all your requirements, you can choose a different package, which is small enough for you. Though that will be difficult to solder, if you don't have the right tools

PSoC 4000 are truly small (even tinier than an ATtiny10): about 1.5 x 1.5mm in a WLCSP package (16 "pins"/balls). They're still quite powerful: 32-bit Cortex M0@16MHz with 16KB of flash and 2KB of RAM. They don't have enough PWM outputs though...

PSOC doesn't match my requirements. I'll study more of the specifics and get back to you. thanks <3

For LED driving you don't need hardware PWM - software generated PWM is more than adequate. A little bit of jitter really doesn't matter for LEDs.

So ur saying that you can make 2 leds turn off on etc seperatly with only software and no giant libraries that would fill a attiny10?

Yes. I once made an electronic candle with an rgb led and a pic10 - only had about 300 bytes of flash and 16 bytes of ram.

can you tell me how i would do that?

It depends on what you want to do. On the PIC10 I had a tight loop with a counter and three (R, G and B) duty cycle variables. Plus a crude PRNG routine. All written in assembly language. You would probably be fine using a timer or something like that if you want to make it more concurrent.

check out this EEVBLOG video ... multiple microcontrollers may be the way to go ... https://m.youtube.com/watch?v=VYhAGnsnO7w

EEVBLOG helped me find some microcontrollers.

You can drive 12 LEDs out of 4 digital pins using Charlieplexing.

"doesn't match my requirements", "changed my plans" - So only you know what you want to do and can decide what you need to do it. While it is interesting to contemplate, this question is under-specified, seems to be a moving target, and doesn't appear to be about Arduino hardware or software. [Voting put on hold pending OP update].

I don't know whether it's really the smallest you can find but... The
ATtiny84 has an ADC, more digital pins than you need, and is
available in 3 mm packages (UFBGA and VQFN). There is also an
Arduino-compatible core available for it.

The Attiny84 is huge compared to what I need sadly. I need something like the attiny10 but with more pins. preferabily avr

More pins = more size - unless you want to go BGA or chipscale, which is normally outside the abilities of hobbyists.

@Macaroni, 3mm x 3mm is huge?

@Majenko I changed my plans but I still need alot of pins so I might use BGA. I found 2 microcontrollers but I'll have to watch a video to learn about how to solder them because they are WACK. Which one is compantibe with arduino ide and which one should I choose etc.. I need alottt of pins its a big project. Like a mini computer is what im working to.

https://lcsc.com/product-detail/ATMEL-AVR_MICROCHIP_AT91SAM9G45C-CU_AT91SAM9G45C-CU_C111548.html
15 X 15mm 324 pin
https://lcsc.com/product-detail/NXP-MCU_NXP-Semicon-MCIMX6U5EVM10AC_C394782.html
11 X 11mm 624 pin

JLCpcb seems to have a smt service. Don't know if they would do bga so :/

You said you needed 10 pins. Is that a "lot"?

"I changed my plans"

I made a Arduino develop board with ATtiny3217, it has a 24-pin VQFN form factor, but as powerful as ATmega328p, with no external crystal and capable running at 20MHz.
If this is not suitable for you, look into the new tinyAVR family, they are the new generation of ATtiny with more functionalities than the older ATtiny family with the smaller footprint.


text:
Wide range of protocols one chip?
Is there some way to do raw radio on a esp32 and change frequencies. If not what would I need to transmit rf, wifi, bluetooth, zigbee etc. There seems to be no tutorials on how to do anything of the sort.

search for SDR software-defined radio

There seems to be no tutorials on how to do anything of the sort.

That's because doing such a thing is not something the manufacturer of a part typically expects you to want to do. Yes, some chips may be capable of other protocols internally, but making them use those protocols would mean direct manipulation of the low level components in the chip.
Chips like the ESP32 or the nRF24L01 are geared towards specific protocols. They expose functionality that is good for those protocols.
There are other chips which are designed with (almost) any protocol in mind, but there's nothing "arudinoy" about using them. To access other protocols you would download the SDK for that chip and create new firmware specifically for the protocol you want to use. In many cases such SDKs and the associated documentation is protected under NDA so you or I getting access to such a thing is not usually possible.
In general though a chip is designed with a specific protocol and application in mind and is optimised specifically to handle the requirements of that protocol.


text:
digitalwrite() HIGH for arduino
How too know whether digitalwrite(HIGH, pin_number) sets the voltage to 5 volts or 3.3 volts. I am yet to purchase arduino uno. I want digital pin voltage to be 5 volts. I am aware that thereis a pin already have 5 volts but I want to know only about the voltage output at digital pins.
Sorry if question is too silly. I am not very knowledgable in Electronics.

Different boards operate internally at different voltages. This is dictated by the main chip on the board.  That main internal operating voltage is also the voltage at which the IO pins operate.
Most "old" Arduino boards operate at 5V.  This includes, but is not limited to:

Arduino UNO
Arduino Mini
Arduino Leonardo

Newer more powerful boards, many made by other companies, operate at 3.3V. Again, this includes such boards as:

Arduino DUE
Arduino MKR1000
Teensy boards (v3.0+)
chipKIT boards
ESP8266 & ESP32 boards

Some boards come in variants that give either voltage - the most notable being the Pro Mini boards from Sparkfun.  These come in both 5V and 3.3V variants and it is important to pick the right board for your needs.
In general, though:

If it's 8-bit and runs on an ATMega chip it's likely 5V unless otherwise stated
All 32-bit boards will be 3.3V unless otherwise stated.

When you use digitalWrite(pin_Number,HIGH); this sets the output pin to 5 V but still if you want to check the voltage you can you a digital multi meter set its knob to DC voltage and connect its positive to the pin and the ground pin to ground and the voltage will be displayed on the multi meter

Thanks, but this link says HIGH depends on 5volt board or 3.3 volt board https://www.arduino.cc/reference/en/language/functions/digital-io/digitalwrite/ . How to know Arduino Uno is 5 volt board or 33 volt board ?

@HiteshSomani: It's 5 V, written very prominently on the product page.

The Uno is a 5V Arduino. For other types the answer is more complicated, as explained in Majenko's excellent answer.


text:
Servo motor analog vs digital and AC vs DC
I am little confused with servo motor terminology.
Q1. AC servo motor requires AC power source ?
Q2. DC servo motor requires DC power source ?
If answer to above 2 questions are YES then what does analog servo motor means.
Q3. Can I use arduino uno to control analog RC servo motor ?

Q1. AC servo motor requires AC power source ? Q2. DC servo motor requires DC power source ?

Yes. It's all down to the kind of motor that is used in the servo - an AC synchronous motor (often with VFD), a small DC brushed motor (the most common RC type) or a brushless DC motor.

Q3. Can I use arduino uno to control analog RC servo motor ?

Yes. That's precisely what the bundled Servo.h library is for. All the Arduino servo examples you will find online use analog RC servo motors.
The name "analog" though for those motors is not really 100% correct. They are driven by a PWM signal where the duty cycle is used to control the angle. The signal itself is 100% digital. The "analog" component comes in the form of the duty cycle of the signal.


text:
Multiple functions at the same time with Arduino Uno
I would like to make a stepper motor run in for loop in time intervals. I also want to stepper motor run when I press the button. Two functions independently. One does not affect the other. I wrote both functions but I have no idea how to make them both work in the same time. I'm using an Arduino Uno.
This is my code:
const int stepPin = 3;
const int dirPin = 4;
const int buttonPin = 2;

void setup() {
  pinMode(stepPin,OUTPUT);
  pinMode(dirPin,OUTPUT);
  pinMode(buttonPin, INPUT);
}
void loop() {

 // One function
   digitalWrite(dirPin,HIGH);

  for(int x = 0; x < 100; x++) {
    digitalWrite(stepPin,HIGH);
    delayMicroseconds(3000);
    digitalWrite(stepPin,LOW);
    delayMicroseconds(3000);
    }
  delay(30000);
    }

// Second function
  digitalWrite(dirPin,HIGH);
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
  digitalWrite(stepPin,HIGH);
  delayMicroseconds(3000);
  digitalWrite(stepPin,LOW);
  delayMicroseconds(3000);
}

Can anyone help me? :)

You can’t do this with blocking code.  You’ll have to rewrite loop so that it can repeat over and over very fast and doesn’t have to stop and wait for anything to happen.  It’s called non-blocking code and it’s probably your first lesson in real coding.  Instead of thinking of a for loop that takes the action from start to finish, think of a loop function that takes one tiny step and then comes back around next time to take the next step.   Look up the blink without delay example and any of the myriad tutorials about it for some more information on how.

do not use if button pressed, then run motor and if timer, then run motor ........... instead use if button pressed, then set flag and if timer, then set flag and if flag set, then run motor

I'm also confused because your two functions both do the same thing.  What do you actually want to see happening?  If you want the stepper to just constantly step then remove the 30 second delay.


text:
Ultrasonic HC-SR04
Having trouble with arduino
Ultrasonic Sensor  Module
HC-SR04
I'm sure when you read this you're going to say how stupid can he be and you're probably right but I'm 82 years old and I'm trying very hard. They say you're never too old to learn I hope they're right
This sensor model is driving me crazy I have tried and written two or three sketches and I cannot get it to work I know how simple it is for wires big deal but when I tried to read it through my serial monitor I get this a bunch of backward ? A C S A ? But the question are backwards . I have used two different boards new ones and tried three Ultrasonic Sensor hope you can help me thank you Dennis

you said absolutely nothing about the hardware, how it is connected, the program and the problem you are having

It sounds like an incorrect baud rate setting to me.

With such question please always include your code and your wiring. But I second Majenko with that it sounds like a wrong baudrate. In the Serial Monitor you need to select the same baudrate, that you used in your sketch with Serial.begin().


text:
Arduino u8glib Problem
I am Trying to make tetris on a 128x64 oled 1.3", and I am using the u8glib library. Here Is My Code:
#include "U8glib.h"

U8GLIB_SH1106_128X64 u8g(13, 11, 10, 9);

int val = -53;
int val2 = -53;

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

static const uint8_t PROGMEM tetris1 [] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

static const uint8_t PROGMEM tetris2 [] = {
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
};

void draw() {
  u8g.drawBitmapP(val, 41, 16, 64, tetris1);
}

void d() {

}
void draw2() {
 u8g.firstPage();
 do {
  u8g.drawBitmapP(val2, 41, 16, 64, tetris2);
  val2 += 1;
  delay(250);
 }while(u8g.nextPage());
}

void loop() {
  // put your main code here, to run repeatedly:
  u8g.firstPage();
  do {
    draw();
  }while (u8g.nextPage());
  draw2();
}

The Problem is that when I call draw2() it creates a new page only displaying the shape from function draw2(), but what I want is for the shape from function draw() to stay there. Is there anyway I can do this??

u8g.firstPage() starts a new page. Anything you want to appear on that page has to be drawn on that page.

Most monochrome LCDs and operate on a principle of "pages". A page in this context is not a whole screen, but one strip of pixels, often 8 pixels high.
U8G draws the screen using these strips. It iterates over the whole screen on a page-by-page basis (a strip at a time, that is) and draws the content. Any drawing functions within that iterative loop (between u8g.firstPage() and the last u8g.nextPage()) get called for each strip and only the portion that is within the strip being drawn will be rendered.
This of course overwrites everything else on the screen. To display something it has to be within this loop of drawing each page. If you draw something in one loop then draw something else in another loop the second loop will overwrite what was there already.
This also means that you should not do anything other than drawing in a page loop. No delays, no complex calculations, etc. You want that loop to operate as fast as possible. Do any calculations outside the loop then run the loop. This is why the loop is often separated out into its own "draw" function, so you do all your work, then "draw" it to the screen.
So to draw two tetris pieces both those pieces have to be rendered within the same .firstPage() ... .nextPage() loop.

Since it is going to overwrite anything after nextPage(), how do I know where the first shape was originally so that I can put in the same spot again while the other shape gets drawn?? And also, how can I detect collision of the pieces in u8glib?

By writing the functionality in your program. You know where things are because you knew where they were when you put them there.

but when I make tetris the shapes will be falling down at different random locations and I wont know where they fell. So how do i keep track of that?

And how will yo make them "fall"...?

In the draw2() function, I add 1 to the x value every 250 milliseconds, which causes it to move down.

Then you know where it is as you have the X variable.

Here's a tip: Tetris doesn't remember where every piece is. Once it has landed it's just a collection of square blocks and ceases to be a shape any more.

Oh ok thank you. Also do you know how I can get collision detection in u8glib as I will need to know when it touches another piece so it can stop there

You're thinking about it all the wrong way. u8glib is just a way of drawing to the screen. It's up to you to know where things are and if they collide. u8g won't do that for you.

oh alright. thank you for the help

@hellopeople Personally if I were writing it I wouldn't be working with shapes. I'd be working with single blocks - shapes are just collections of those blocks in certain arrangements. Then the whole playfield is just a list of "There is a block here, but no block here" as a grid. Probably I'd just have a single binary value per row, and arrange them in an array to make a grid that can be tested for the presence of a block in any position rapidly. A full row is then just one where all the bits are set to 1, and moving rows down is as simple as copying values in the array.


text:
Disable Keyboard.h status LED
As soon as I include keyboard.h my pro micros LED starts flashing (as far as I know this indicates a serial connection is stablished or so.)
But it's really annoying having a flashing led on my desk all the time.
Is there an option to disable this 'debugging' behaviour from the keyboard.h libary?

Those LEDs are controlled by the USB Core code, and are defined in the board variant.  For the pro micro that's the pins_arduino.h file in the micro variant:
#define TXLED0          PORTD &= ~(1<<5)
#define TXLED1          PORTD |= (1<<5)
#define RXLED0          PORTB &= ~(1<<0)
#define RXLED1          PORTB |= (1<<0)
#define TX_RX_LED_INIT  DDRD |= (1<<5), DDRB |= (1<<0), TXLED0, RXLED0

If you edit that file and remove everything after the macro name, so you have 5 empty macros, it should disable the LEDs completely.
#define TXLED0
#define TXLED1
#define RXLED0
#define RXLED1
#define TX_RX_LED_INIT

Edit:
For the Sparkfun Pro Micro, edit the file at
...\AppData\Local\Arduino15\packages\SparkFun\hardware\avr\1.1.13\variants\promicro

This is because it has an extra package that is not installed by default.

Didn't work for me. I even deleted them completly, but no error nothing. Maybe I am in the wrong directory or do I need to recompile something? Do I need to change it at some different place since the pro micro needs extra libaries to function anyways?
The full path I used : C:\Program Files (x86)\Arduino\hardware\arduino\avr\variants\micro\pins_arduino.h

If you had to install more boards packages (I have not used that board) then the file will be in that package somewhere.

Works now :D.
If anybody is interested: The file you need to edit is at
...\AppData\Local\Arduino15\packages\SparkFun\hardware\avr\1.1.13\variants\promicro
It's a bunch of stuff in the file. You need to look for a second to find the keywords but they are there.

it's really annoying having a flashing led on my desk all the time.

As a software engineer I know we often fall into the trap of thinking that all problems must have a software solution. Try thinking of this as a hardware problem.

Cut out a small piece of a sticky label and stick it over that annoying LED.
Use a soldering iron to remove the offending LED.
Use needle-nosed pliers to crush the offending LED.

The more destructive solutions can be reversed with a soldering iron and maybe a new SMD LED. For Arduinos with female or stacking headers you could instead reinstate the feature by plugging a thru-hole LED and resistor into the appropriate positions in the Arduino's header sockets. E.g. D13 and GND. For other Arduinos by adding LED and resistor in adjacent positions in a breadboard.
There might be a good software solution but it can be worth considering other approaches.


text:
i am tying to make a automated parking lot with a gate, sensor, button, keypad, how can i time how long has each car spent inside?
the project requires a automated parking lot, I have been able to connect and function the sensor and button for exit and enter, and the led(red lights when parking is full, green when there is spots). the maximum cars are 5. and the lcd prints the spots available and the spaces taken. the keypad is also connected. now what I need is to make a code that times each car that enters in the order that they enter in and for each car that leaves it has to enter its order of entering to calculate the price it has to pay with this equation: Parking Fee (fils) = time(sec) x 0.29fils
here is the code i have at the moment:
#include <Servo.h>
#include <LiquidCrystal.h>
#include <Keypad.h>
LiquidCrystal lcd(12,11,5,4,3,2);
Servo myservo;

#define Servo 7
#define exit SDA
#define power 6 // extra
#define ground 10 // extra
#define capacity 5
#define R_led SCL
#define G_led 13
int val;
int n = 5;
int s = 0;

const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
 {'1','2','3'},
 {'4','5','6'},
 {'7','8','9'},
 {'*','0','#'}
};
byte rowPins[ROWS] = {A4, A3, A2, A1}; //Arduino Pins
byte colPins[COLS] = {8, 9, 10}; //Arduino Pins

void setup(){
  for(int i=0;i<4;i++){
    pinMode(rowPins[i],INPUT);  //set row pins as inputs
    pinMode(colPins[i],OUTPUT); //set column pins as outputs
  }
  Serial.begin(9600);
  myservo.attach(Servo);
  lcd.begin(16,2);
  pinMode(power,OUTPUT);
  pinMode(ground,OUTPUT);
  pinMode(exit,INPUT);
  pinMode(G_led,OUTPUT);
  pinMode(R_led,OUTPUT);
  digitalWrite(ground,LOW);
  digitalWrite(power,HIGH);
  myservo.write(0);
  digitalWrite(R_led,LOW);
  digitalWrite(G_led,LOW);
}

void loop(){
  if (n>=1){
    lcd.clear();
    lcd.setCursor(1,0);
    lcd.print("Spots left: ");
    lcd.print(n);
    lcd.setCursor(1,1);
    lcd.print("Cars inside: ");
    lcd.print(s);
    digitalWrite(G_led,HIGH);
    digitalWrite(R_led,LOW);
    delay(30);

  }
  else {
    lcd.clear();
    lcd.setCursor(1,0);
    lcd.print("The parking is");
    lcd.setCursor(0,1);
    lcd.print("full!");
    digitalWrite(G_led,LOW);
    digitalWrite(R_led,HIGH);
    delay(30);
  }
val = analogRead(A0);
// Serial.println(val);
if (val>950)
{
  if (n!=0){
    n--;
    s++;
    myservo.write(90);
    delay(3000);
    myservo.write(0);
  }
}
if (digitalRead(exit)==1)
{
  if (n!=capacity){
    n++;
    s--;
      myservo.write(90);
    delay(3000);
    myservo.write(0);
  }
}
delay(20);
  int keyValue=0;
    digitalWrite(colPins[0],HIGH); //Set column1 as high
    digitalWrite(colPins[1],LOW);
    digitalWrite(colPins[2],LOW);
    digitalWrite(colPins[3],LOW);
    for(int i=0;i<4;i++){             //iterate over rows to find if key is pressed
      keyValue = digitalRead(rowPins[i]);
      if(keyValue== 1){
            //display either 1,4,7 or *
        Serial.println(keys[i][0]); //display key pressed
        delay(500);
      }
    }

    digitalWrite(colPins[0],LOW);
    digitalWrite(colPins[1],HIGH); //Set column2 as high
    digitalWrite(colPins[2],LOW);
    digitalWrite(colPins[3],LOW);
    for(int i=0;i<4;i++){              //iterate over rows to find if key is pressed
      keyValue = digitalRead(rowPins[i]);
      if(keyValue== 1){
        //display either 2,5,8,0
         Serial.println(keys[i][1]); //display key pressed
        delay(500);
      }
    }
    digitalWrite(colPins[0],LOW);
    digitalWrite(colPins[1],LOW);
    digitalWrite(colPins[2],HIGH);//Set column3 as high
    digitalWrite(colPins[3],LOW);
    for(int i=0;i<4;i++){
      keyValue = digitalRead(rowPins[i]);
      if(keyValue== 1){               //iterate over rows to find if key is pressed
        //display either 3,6,9,#
         Serial.println(keys[i][2]); //display key pressed
        delay(500);
      }
    }
    digitalWrite(colPins[0],LOW);
    digitalWrite(colPins[1],LOW);
    digitalWrite(colPins[2],LOW);
    digitalWrite(colPins[3],HIGH);//Set column4 as high
    for(int i=0;i<4;i++){
      keyValue = digitalRead(rowPins[i]);
      if(keyValue== 1){               //iterate over rows to find if key is pressed
        //display either A,B,C,D
         Serial.println(keys[i][3]); //display key pressed
        delay(500);
      }
    }
}

Depends on the required accuracy. You can use millis() to measure time, though it is not very accurate depending on the internal clock. If you need correct time you need to use a Real Time Clock module (RTC). How accurate should it be? What time ranges do you want to measure?

yes I want to use millis(), but I can't figure how to do it on the requirements I mentioned above

the range is when the car enters the parking until it exits

some of your code makes no sense ... it seems that you are not thinking clearly about your program ... why are you scanning the keypad? ... look at Keypad library examples

just do what a real parking lot does, record the arrival time

ok can you please let me know how to record the arrival time ? I would really appreciate it

When using millis(), the arrival time is the return value of millis() at the time of arrival. Thats what millis() does. It gives you the number of milliseconds since startup, thus time. When someone arrives, save the value of millis() in a variable. Later you can subtract that value from millis() and get the time of stay in milliseconds.

yes I understand that but I want to know how to count the time for different cars at the same time, to be more precise 5 cars and each car when it leaves it enters the number of order it entered in to calculate the fee

do this on paper first ... draw the parking lot with 5 spaces ... use pieces of paper to represent vehicles ... write down everything that you need to keep track of ... translate into a program

@FaisalAlrafaei did you write the code that you presented?

firstly about drawing there is no need for it because I am using tinkercad, secondly the code I collected information I found on the internet and edited them

@FaisalAlrafaei With drawing on paper jsotola wanted to guide you to solve the problem yourself. Often programming questions can be solved, when you make yourself clear what the exact steps in a process are. These steps then can be translated to code way easier. Tinkercad doesn't do that for you and you don't seem to have every step of the process in mind.

ok, use toy cars instead, but write down all the information that you need in order to charge for the correct time of each parked vehicle

code I collected information I found on the internet and edited them ... you really need to learn what the code actually does ... the sketch has a lot of un-necessary code

For measuring the time for each parking lot:
Declare an array of unsigned long with one element per parking lot (so 5 in this case) and initialize it with zeros:
#define N_PARKING_LOTS 5
unsigned long timestamps[N_PARKING_LOTS] = {0};

Then go to the place in your code where a new car arrives in its parking lot. You need the number of the used parking lot. Set the corresponding element in the array to millis() (for example here element 3, so the 4th parking lot):
timestamps[3] = millis();

When the corresponding car leaves you can get the time by calculating the difference and by that calculate the price:
unsigned long park_duration = millis() - timestamp[3];
float price = (park_duration/1000)*0.29;

How you know the parking lot depends on your actual process. It is difficult to understand what you want to say in your question. You could guide the arriving car to a parking spot chosen by you.
Btw: The code will get much easier for you when you actually use the Keypad library, instead of just including it. Then your current code will get way shorter.

How do you know which car is which. You could use a long range RFID tag in each one then when sensing you will know who and your clock will tell you when and you hopefully know if it is coming or going. After that you should be able to work the code.


text:
ESP32 sending data of type uint16_t(or anything except for uint8_t and char*) over bluetooth(classic) serial
I'm making a custom gamepad with an ESP32 and the joystick output is read by an ADC using uint16_t analogRead(uint8_t pin);. Now that I want to send the data and receive and parse it, I ran into a problem. The BluetoothSerial library I'm using only has this function for sending data:
size_t write(uint8_t c);

And the only other function I know of is this:
size_t Print::printf(const char *format, ...);

However, I don't want to convert the data to characters. Is there a way of sending integer/float/double etc bytes directly without converting them to characters?

Send it as two bytes?

How? I am not very familiar with this type of low level byte manipulation. I'll be glad if someone helped me out :)

@DaveNewton what's more, how do I distinguish the high and low bytes when they are received at the other end?

They'll be received in the order sent and can be shoved back together in whatever endian-ness is required. Splitting it up is masking and shifting, e.g., https://stackoverflow.com/questions/53367838/how-to-split-16-value-into-two-8-bit-values-in-c, https://forum.arduino.cc/t/changing-a-16bit-binary-number-into-two-8-bit-byte/44940, and so on.

@davenewton I have done just that(I searched for it and got the second forum post myself) and got it working with ~93% success rate. It seems that I have to allot a larger buffer than I'm sending or the success rate drops to 15-20%. And by larger buffer I mean at least 3 times larger. I'm sending 4 16-bit integers and I'm using two 0's for the beginning and the end, so I'm checking for that and the known largest ADC integer value after parsing. I also have to time it correctly or it doesn't work (10 ms delay). Is this common?

Without seeing any code it’s impossible to guess what might be happening.


text:
Why won't my motor run?
I am trying to run a small 3v motor with a Keyestudio MEGA 2560(which is the same as the Arduino MEGA 2560). I am getting a consistent 5 volts everywhere I check with a multimeter. The voltage drops to 0.01-0.05 once I connect the motor. The motor runs once it is connected directly to the Arduino's 5v output pin. The motor draws about 600mA consistently when we connect it directly to 5v.
My code is rather basic, which just sends voltage out pin 5.  I am not using any shield. controlling the speed is not my main concern here, though later on in my project I would like the motor to be able to reverse as well.
I found this circuit diagram in "Arduino for dummies," and found this same diagram on many other websites too.
void setup() {
  pinMode(5,OUTPUT);
}

void loop() {
  digitalWrite(5,HIGH);
}

simulate this circuit – Schematic created using CircuitLab

An NPN bipolar transistor requires a current to flow from base to the emitter which is then multiplied by the beta of the transistor controlling the maximum current which flows from the collector to the emitter.  A 2n2222 beta is about 100.  Let us calculate the amount of current which will be allowed to flow from the collector to the emitter of the 2n2222 transistor.  First calculate the current from the base to the emitter:
I(be) = (5.0 volts- 0.7 volts) / 1,000 ohms
I(be) = .0043 Amps

Use this current to find the maximum current flowing from the emitter to the collector:
I(ce) = 100 x I(be) = 0.430 Amp or 430mA

We see that the transistor does not provide enough current to drive a 600mA motor.
We need to reduce the value of R1 such that I(ce) is at least 600mA which means that I(be) needs to be at least 6mA.  Rearranging the earlier equation to find R1:
I(be) = (5.0 volts- 0.7 volts) / 1,000 ohms
I(be) = (5.0 volts- 0.7 volts) / R1
R1 = (5.0 volts- 0.7 volts) / I(be)
R1 = (5.0 volts- 0.7 volts) / 0.006 Amps
R1 = 716.67 ohms

However, because of the large amount of I(ce) current necessary to drive the load, we find the transistor reaching it's limits and the beta of the transistors drop apprecably:

This diagram is a little hard to understand.  And there is no curve for 600mA.  But we can get an idea of what to expect if we look at the 500mA curve.  We see that in order to get less than a volt drop across the transistor (V(ce)) we need to pump in more than 10mA (I(be)).  To get similar results for 600mA we would likely approach 20mA and now we are dangerously close to the processor pin current driving capabilities.
A common alternative is to use a Darlington Transistor configuration:

The resulting beta is essentially the product of the individual transistor's betas.
Let's do some rough calculations.  If the 2n2222 that switches the load current has a lower beta of about 10, we would need about 60mA to switch a 600mA current.  To generate 60mA through the transistor connected to the processor, we would need about 0.6mA from the processor.  That's really small and we can afford to triple it to ensure reliable operation.  So let's pick 3mA:
R1 = (5.0 volts- (2 * 0.7 volts)) / 0.003
R1 = 1200 ohm

So a 1K ohm resistor should likely work.

The DC gain of the transistor will likely be lower than that. “About 100” is an order of magnitude estimate of the typical gain at moderate currents. The gain goes down when I_C goes above 100 mA. According to this datasheet (Fig. 4), the typical gain @ (I_C = 500 mA, V_CE = 1 V) is 50, and more like 10 if you want to be well into saturation (V_CE ≈ 0.2 V).

Dang, I missed that entirely @EdgarBonet.  I'll fix the answer.  Thanks.

Ok, I fixed the solution.  I'm eager to hear your thoughts @EdgarBonet.

Wouldn't a power MOSFET be a better choice for this application, since they have very low on resistance and require almost no current to the base?

That is a good suggestion @DuncanC.  I've see both used.  Do you have a reference to a good discussion we can read?


text:
Arduino project - will this fit together?
I'm about to order parts for my project and I'd like to avoid some rookie mistake I might've missed. I'll be using Arduino chip and a wifi module to host a very simple webpage and a battery to make this all portable. I've decided to use Arduino Mini Pro 8MHz because of 3.3V input voltage, same as ESP8266, also FT232RL to program the board and TPS73601 for my battery. This is where I have some doubts, the battery I've picked is Li-Ion from my old Samsung Galaxy S AFAIK when charged it supplies ~4.2V and nearly discharged ~2.7V so the regulator should work (?). Is using Li-Ion in any way different from regular AA or just +/- because I see 3 pins on the back of it? Except for charging of course I'll be using the phone for that. Thanks in advance for any suggestions.

have you considered programming the esp8266 directly? It has a few GPIO pins and can host small webpages.

http://randomnerdtutorials.com/esp8266-web-server/

I had not known that, but I'll be using a couple of analog sensors in my project, did not include them here because they are pretty straight forward. I assume GPIO on ESP8266 are digital? If so then I'll have to stick with Arduino chip anyway.

From what you've provided everything seems to be compatible.
Concerning the battery, a quick look at the Arduino website shows:

Input Voltage 3.35 -12 V (3.3V model)

Meaning the regulator will work as long as the battery provides voltage above 3.35 but since your battery's voltage drops as it gets depleted you might not get the battery life you'd expect :/. In other words: it'll work initially  until the voltage drops below 3.35V and then you would have to recharge it.

Is using Li-Ion in any way different from regular AA

Yes and No.
No : both provide a stable DC source and both can be used in similar applications.
Yes: Li-Ion batteries can be recharged and have a longer life-span, and most importantly, Li-Ion batteries don't have a sharp voltage drop as they get depleted, unlike regular AA batteries. Which is a bonus for this project ( i guess :p )

I see 3 pins on the back of it

There are only 2 pins that actually provide the power from the battery while the third is usually used to monitor temperature or battery life remaining.So you can use this battery by only connecting the power providing pins (usually indicated by + and - ) and safely ignore the third.
Gd Luck!

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


text:
analogWrite causes value from IR receiver to change
I'm playing around with an IR receiver and an RGB led.
I had it up and running, until I changed around some code. The remote seeming stopped working, but after looking at the values in the Serial Monitor it appeared that the values that were being printed out weren't the same.
After playing around a bit I found that if analogWrite is run on pin 11, the value changes. Why is this so?
Code is as follows:
#include <IRremote.h>

int ir_recv_pin = 2;

IRrecv irrecv(ir_recv_pin);

decode_results results;

void setup()
{
    Serial.begin(9600);
    irrecv.enableIRIn();
}

void loop()
{
    if (irrecv.decode(&results))
    {
        //Serial.println(results.value);
        Serial.println(results.value == CH_MINUS);
        Serial.println(results.value);
        Serial.println(CH_MINUS);

        analogWrite(11, 125);
        irrecv.resume();
    }
}

Output is as such when pressing the button twice in a row (without holding the button down):
1
16753245
16753245
0
3810010651
16753245

Initially the values come out as expected (16753245), but after the analogWrite, the value changes (3810010651).
Looking at the documentation it says that pin 11 runs at 980Hz. Is this why the value changes? If so, why?

Because IRremote uses timer 2 by default, and the PWM output on pin 11 is generated via OC2A. Either edit IRremoteInt.h to use timer 1, use a pin on timer 1 for PWM, or frob OCR2A directly instead.

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


text:
arduino resets or hangs after providing power to DHT22
I'm developing a low power project based on Atmega328p which among other things uses a DHT22 to measure air humidity. DHT22 spec says that it consumes 50uA when idle. This is too high for me (I'm aiming at sub 10uA consumption for the whole device when in sleep mode) so I've figured out that I'll just power it from one of Atmega328p pins. This will give me the ability to turn it off or on at software level. DHT22 consumes only 1.5mA during measurement so I should be fine (a single Atmega's pin can safely provide up to 20mA). I've set up a following test circuit:

The red wire powers DHT22, the blue one is for data transfer, the black one is GND and the 4.7k is a pull-up resistor.
My problem is that after I turn on the DHT22 using just:
digitalWrite(4, HIGH);

the Atmega either resets or hangs or... successfully turns on the DHT22 and keeps working, but that happens about 10% of the time. My suspicion is that there is some current spike in the moment of supplying power to the DHT22. Unfortunately I don't have an oscilloscope to confirm this.
I've added a 220 ohm resistor between VCC pin of DHT22 and the pin 4 on the Arduino and it solved the problem. My question is: will it work like this reliably? Are humidity readings reliable when voltage is not stabilized (but stays within 3.3-5.5V range as required by the datasheet)? I could of course use a transistor to turn it on/off, but I'd like to keep it as simple as possible.
Why DHT22's datasheet doesn't mention this current spike? Here it is for reference: http://www.adafruit.com/datasheets/Digital%20humidity%20and%20temperature%20sensor%20AM2302.pdf

This is probably due to a voltage drop when you start powering the DHT. Have you tried adding a decoupling cap between pin 4 and GND? Otherwise a MOSFET triggered by pin 4 and providing the supply to the DHT may be a good solution.

Please note that sub 10uA consumption when idle is very ambitious and I wonder how you'll be able to stay under this threshold with such a circuit.

The 220 resistor is a solution, but you probably want to add a capacitor after it, to smooth the voltage at the DHT. The datasheet already suggest adding a  100nF capacitor across the power of the sensor.

pinMode(4, OUTPUT)?

I haven't ever had to use the cap even with 20 meter cable runs.  (Maybe the cable does that for me.)  With that long of a run I get a definite voltage drop so it barely takes any current yet provides accurate values.  Never would I put a resistor across any of the pins, even if my cable is only 10cm long.  But have you tried it?

The sensor is a large capacitive load. You need to improve decoupling of the CPU power supply.
A 10 uF between 5V and GND will help for the current spike and the resistor in series with the sensor will not be an issue (50 uA on 250 Ohm makes only 12.5 mV voltage drop once the sensor is started).

The previous answers regarding adding decoupling capacitors are good.
You don't have to be concerned about the voltage drop across your 220 ohm resistor. MAC's answer states that only 12.5mv drop at 50uA (when not measuring).
During measurement, 1.5mA will result in 0.33v drop across the 220 ohm resistor. This should be noted, but is not a problem. The DHT22 data sheet shows that it will accept any supply voltage between 3.3v and 6v.
  Looks like you have a good design.

Decoupling capacitors do help, as mentioned in the other answers.
Also, to get a good reading, after powering up your digital pin 4, a delay of maybe 100-500ms may be required to allow the DHT22 to stabilize. For better results, you can also perform multiple readings (call delay(dht.getMinimumSamplingPeriod()) between the readings) and average them.
It looks like you are using an Arduino Uno. For further power savings, you might consider using a Pro Mini and performing some hardware modifications. For software power saving techniques, there is no better resource than Nick Gammon's Power saving techniques for microprocessors.


text:
How to address arbitray leds (WS2812B) in an already defined leds array?
I want to address the first and last three pixels of a 9 pixel strip and apply a gradient to them using FastLED.  I can successfully address them but the colors displayed are not correct.  Is there something I'm overlooking or misunderstand about the way FastLED works?
#include <FastLED.h>

// the whole strip
#define NUM_LEDS 9

#define LED_PIN 6

CRGB leds[NUM_LEDS];

// Define the indexes of the first and last 3 indexes of a 9 pixel strip
int customLeds[6] = {0,1,2,6,7,8};

// My Palette
DEFINE_GRADIENT_PALETTE (heatmap) {
  0, 255, 0, 0,      // Red
  128, 0, 255, 0,    // Green
  255, 0, 0, 255     // Blue
};

CRGBPalette16 myPalette1 = heatmap;

void setup() {
  FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
  FastLED.setBrightness(20);
}

void loop() {

  for (int i = 0; i < (sizeof(customLeds)); i++) {
   // Each i led get the correct color given their place in the array  - 0, 42.5, 85, 127.5, 170, 212.5, 255
    leds[customLeds[i]] = ColorFromPalette(myPalette1, (i * (255 / sizeof(customLeds))), 255, LINEARBLEND);
  }

  FastLED.show();

}

Sizeof doesn't give the number of elements but the amount of memory used by the array ..

what does this mean? ... colors displayed are not correct

The colors of the pixels needs to follow the pallete but while they are colors from the pallete they are right..they're all over the gradient and not folowing linearly.

I realized my problem...this:(i * (255 / sizeof(customLeds)) - doesn't work because the two arrays are of different lengths! I'm homing in on a solution.

Please replace sizeof(customLeds) with sizeof(customLeds)/sizeof(customLeds[0]) to actually get the numbers of elements in the array instead of the number of bytes

Yes, a slightly more elegant solution.  I just hard coded the total for ease of use.  Later in the project I plan to use this. But given my solution below, that method become moot as I use a boolean array of the total length.  Hence my use of the hard coded total and the increment variable. Thanks @chrisl

So here is the answer I came up with:
#include <FastLED.h>

// the whole strip
#define NUM_LEDS 9

#define LED_PIN 6

CRGB leds[NUM_LEDS];

// Define the indexes of the first and last 3 indexes of a 9 pixel strip
bool customLeds[9] = {1, 1, 1, 0, 0, 0, 1, 1, 1};
int customLeds_num = 6;

// My Palette
DEFINE_GRADIENT_PALETTE (heatmap) {
  0, 255, 0, 0,      // Red
  128, 0, 255, 0,    // Green
  255, 0, 0, 255     // Blue
};

CRGBPalette16 myPalette1 = heatmap;

void setup() {
  FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
  FastLED.setBrightness(5);

}

void loop() {

  FastLED.clear();

  //  Keep track of how many leds have been lit
  int customLedIndex1 = 0;

  for (int i = 0; i < NUM_LEDS; i++) {
    // Each i led get the correct color given their place in the array  - 0, 42.5, 85, 127.5, 170, 212.5, 255

    //lights a specific pixel only if it's in the customLeds truth table
    if (customLeds[i]) {
      // works out where on the gradient a specific pixel is
      leds[i] = ColorFromPalette(myPalette1, (customLedIndex1 * (255 / 5)), 255, LINEARBLEND);

      //increments the index for the next pixels value on the gradient
      customLedIndex1++;

    }

  }

  FastLED.show();

  customLedIndex1 = 0;

}

The solution involved using a boolean array that indicates which leds needed to be on (true / 1) and which off (false / 0) and then create a separate index (customLedIndex) which counted how many of the leds where lit so they could receive the correct color corresponding to their 'place' in the palette


text:
Breathing LEDs on single PWM pin?
I'm doing a project which is essentially a lighted cube, that communicates status through different colors, where I get this ides [it][1] (having code). So when the light goes below a certain level it turns a certain color, when temp goes above a certain level it turns another color, etc. I'm figuring I'll probably need anywhere from 2 to 4 LEDs per color to get a nice intensity, and the colors would breathe, which is pretty easy with PWM on the arduino.
What I'm thinking is that I'm going to leave all the colors in phase. So that the intensity ramp on red is the same as yellow, is the same as green, etc. That would require only a single PWM output and most importantly, a single section in the code, which would make writing easier.
The solution I've come up with is to have the PWM pin drive a MOSFET, and give it the modulation, and the MOSFET would repeat the "breathing" pulse to all the LEDs. Then each color gets switched on or off through a transistor by other pins on the arduino that simply go high or low.
I figure an IRF630, which has an insanely high drain current for this purpose should be more than enough for whatever I might plug into it. And for the switching of each color, maybe an N2222, 4 LEDs will go at about 80 mA max anyway.
So, why not just drive each color from a PWM output? Any thoughts on the circuit? Sound like it could work?
[1]: https://www.kynix.com/Blog/Arduino-Complete-Guide-for-Beginners-with-Examples.html Code Source

No reason why it wouldn't work. But the IRF630 is very very much overkill for this job.

From your description I think you are wanting this arrangement:

simulate this circuit – Schematic created using CircuitLab
There is no logical problem with that arrangement. However you must watch the total current being provided by each GPIO pin. You must not go above 40mA peak, and you should not go above 25mA sustained.
It may be better to provide the 5V to the LEDs through a P-channel MOSFET per bank to allow for higher current:

simulate this circuit
Note that here the operation of the GPIO is reversed: the gate of the P-channel MOSFET must be pulled LOW to turn it on.


text:
Store Integer Value of Money on an RFID Tag
I am working on making an Arduino based arcade. I want each user of the arcade to have an RFID card that stores the amount of credits (basically money) they have. I know that RFID tags have 1028 bytes of storage on them, but I don't know how to write an integer value to them.
The amount of credits each user has would be stored on the RFID, as well as their PIN.
The PIN would be 4 digits, with each digit an integer from 0-9, as is the standard with PINs. It would be stored as a single integer, between 0000 and 9999.
The credit would ALSO be stored on each card. This would be between 0 and 99 (Most that can be loaded at a time). This, too, would be treated as a single integer, for ease of use.
Both integers would be of the Arduino type int.
I am using the MFRC522 library with an RC522 reader/writer. I have an Arduino Uno, but can easily switch to an Arduino Nano.
Can someone tell me how to:
A. Write an integer value (stored as a variable in the sketch or accessed from the RFID memory) to an RFID card?
B. Access that information and retrieve it as an integer I could operate on (+,-,÷,×, etc)?
Thanks in advance!

You can read data with :
status = mfrc522.MIFARE_Read(blockNum, readBlockData, &bufferLen);

and write data by:
status = mfrc522.MIFARE_Write(blockNum, blockData, 16);

However, there's a lot more to it, so check examples of the RFID library, or this external articles:
https://www.electronicshub.org/write-data-to-rfid-card-using-rc522-rfid/
https://playground.arduino.cc/Learning/MFRC522/
When you read the data in a memory block, you can get the bytes out you need and convert them to an int, or the other way around for writing.

So blockNum would be replaced with the block number of the target, and blockData would stay the same?

I'm not 100% sure what you mean ... blockNum is an integer (value) number of the target, and block data is the buffer containing the content of that block (of the target), which is typically a 8 bit array (typically unsigned byte*)

I wasn't sure what in the above code was placeholders and what was meant to stay the same when I make the sketch

blockNum is an input parameter (meaning it doesn't change). readBlockData is changed (with the data that is read), as well as bufferLen which contains the number of bytes read (and to not overflow the read buffer).  blockData (for writing) does not change the buffer (but changes the actual RFID tag content).