text:
HELP with making code size smaller for Attiny13a
Iam making an awesome christmas present a custom pcb badge.
Everything works great with hooked up uno, but its heart is actually a Attiny13a, where I get ONLY around
1024bytes (mine code has 1944)
64bytes of variabels (I somehow managed to make few things copy on run so i barely get to it at 59 bytes)
The thing is how can I make this even smaller??
void setup() {
  pinMode(3, INPUT_PULLUP);
}

void charlie(int a[])
{

  if(a[0] < 0){

    pinMode(5, INPUT);
  }else
  {
    pinMode(5, OUTPUT);
    digitalWrite(5, a[0]);
  }
  if(a[1] < 0){

    pinMode(6, INPUT);
  }else
  {
    pinMode(6, OUTPUT);
    digitalWrite(6, a[1]);
  }
  if(a[2] < 0){

    pinMode(2, INPUT);
  }else
  {
    pinMode(2, OUTPUT);
    digitalWrite(2, a[2]);
  }
  if(a[3] < 0){

    pinMode(4, INPUT);
  }else
  {
    pinMode(4, OUTPUT);
    digitalWrite(4, a[3]);
  }
}

void copy(int* src, int* dst, int len) {
    memcpy(dst, src, sizeof(src[0])*len);
}
void resetP()
{
  pinMode(5, INPUT);
  pinMode(6, INPUT);
  pinMode(2, INPUT);
  pinMode(4, INPUT);
}
void loop() {

  int koz1[4] = {-2,LOW,HIGH,-2};
  //int koz2[4] = {-2,HIGH,LOW,-2};

  int koz2[4];
  copy(koz1, koz2, 4);
  koz2[1] = HIGH;
  koz2[2] = LOW;

  int koz3[4] = {LOW,HIGH,-2,-2};
  //int koz4[4] = {HIGH,LOW,-2,-2};
  int koz4[4];
  copy(koz3, koz4, 4);
  koz4[0] = HIGH;
  koz4[1] = LOW;

  int koz5[4] = {LOW, -2,-2,HIGH};
  //int koz6[4] = {HIGH, -2,-2,LOW};
  int koz6[4];
  copy(koz5, koz6, 4);
  koz4[0] = HIGH;
  koz4[3] = LOW;

  int cap[4] = {-2, HIGH,-2,LOW};

  int oko1[4] = {LOW, -2,HIGH,-2};
  //int oko2[4] = {HIGH, -2,LOW,-2};

  int oko2[4];
  copy(oko1, oko2, 4);
  oko2[0] = HIGH;
  oko2[2] = LOW;

  // put your main code here, to run repeatedly:

  static long oldTime = 0;
  long Ctime = millis();
  long diffT = Ctime - oldTime;
  oldTime = Ctime;

  static bool holdButt = false;
  static long holdTime = 0;
  static long shortPressATime = 0;
  //static long longPressATime = 0;
  static bool kozichOn = true;

  //charlie(oko1);
  //charlie(oko2);

  if(digitalRead(3) == LOW)
  {
    holdButt = true;
    holdTime = holdTime + diffT;
  }
  else if (holdButt && digitalRead(3) == HIGH){
    holdButt = false;
    if(holdTime > 1000){
      //longPressATime = 5000;
      kozichOn = !kozichOn;
    }
    else
    {
      shortPressATime = 5000;
    }
    holdTime = 0;
  }

  if(shortPressATime > 0)
  {
    shortPressATime = shortPressATime - diffT;
    /*charlie(koz1);
    charlie(koz2);
    charlie(koz3);
    charlie(koz4);
    charlie(koz5);
    charlie(koz6);
    charlie(cap);
    */
    if(((round(shortPressATime/100) / 2) & 1) == 0){
      charlie(oko1);
      charlie(oko2);
      resetP();
    }
    else{

    }

  }

  /*
  else if (longPressATime > 0)
  {
    longPressATime = longPressATime - diffT;
    charlie(oko1);
    delay(5000/longPressATime);

    charlie(oko2);
    delay(5000/longPressATime);

    longPressATime = longPressATime - 5000/longPressATime;
    longPressATime = longPressATime - 5000/longPressATime;
  }*/
  else{
    if(kozichOn){
      charlie(koz1);
      charlie(koz2);
      charlie(koz3);
      charlie(koz4);
      charlie(koz5);
      charlie(koz6);
      charlie(cap);
    }
    charlie(oko1);
    charlie(oko2);
  }
  resetP();
}

EDIT: Guys you are awesome together with those on arduino forums it looks like I finally achieved it, I will try to optimize little bit more as its 1010bytes 98%. But I thank you all. You teached me in 1 hour more practical things, than I could read in a week.
void setup() {
  pinMode(3, INPUT_PULLUP);
}

void charlie(byte a[])
{

  if(a[0] == 0x0F){

    pinMode(5, INPUT);
  }else
  {
    pinMode(5, OUTPUT);
    digitalWrite(5, a[0]);
  }
  if(a[1] == 0x0F){

    pinMode(6, INPUT);
  }else
  {
    pinMode(6, OUTPUT);
    digitalWrite(6, a[1]);
  }
  if(a[2] == 0x0F){

    pinMode(2, INPUT);
  }else
  {
    pinMode(2, OUTPUT);
    digitalWrite(2, a[2]);
  }
  if(a[3] == 0x0F){

    pinMode(4, INPUT);
  }else
  {
    pinMode(4, OUTPUT);
    digitalWrite(4, a[3]);
  }
}
/*
void copy(int* src, int* dst, int len) {
    memcpy(dst, src, sizeof(src[0])*len);

}
*/
/*
void resetP()
{
  pinMode(5, INPUT);
  pinMode(6, INPUT);
  pinMode(2, INPUT);
  pinMode(4, INPUT);
}
*/

void loop() {

  byte koz1[4] = {0x0F,LOW,HIGH,0x0F};
  //int koz2[4] = {null,HIGH,LOW,null};

  byte koz2[4];
  //copy(koz1, koz2, 4);
  memcpy(koz2, koz1, sizeof(koz1[0])*4);
  koz2[1] = HIGH;
  koz2[2] = LOW;

  byte koz3[4] = {LOW,HIGH,0x0F,0x0F};
  //int koz4[4] = {HIGH,LOW,2,2};
  byte koz4[4];
  //copy(koz3, koz4, 4);
  memcpy(koz4, koz3, sizeof(koz3[0])*4);
  koz4[0] = HIGH;
  koz4[1] = LOW;

  byte koz5[4] = {LOW, 0x0F,0x0F,HIGH};
  //int koz6[4] = {HIGH, 2,2,LOW};
  byte koz6[4];
  //copy(koz5, koz6, 4);
  memcpy(koz6, koz5, sizeof(koz5[0])*4);
  koz4[0] = HIGH;
  koz4[3] = LOW;

  byte cap[4] = {0x0F, HIGH,0x0F,LOW};

  byte oko1[4] = {LOW, 0x0F,HIGH,0x0F};
  //int oko2[4] = {HIGH, 2,LOW,2};

  byte oko2[4];
  //copy(oko1, oko2, 4);
  memcpy(oko2, oko1, sizeof(oko1[0])*4);
  oko2[0] = HIGH;
  oko2[2] = LOW;

  // put your main code here, to run repeatedly:

  static uint16_t oldTime = 0;
  uint16_t Ctime = millis();
  uint16_t diffT = Ctime - oldTime;
  oldTime = Ctime;

  static bool holdButt = false;
  static uint16_t holdTime = 0;
  static uint16_t shortPressATime = 0;
  //static long longPressATime = 0;
  static bool kozichOn = true;

  //charlie(oko1);
  //charlie(oko2);

  if(digitalRead(3) == LOW)
  {
    holdButt = true;
    holdTime = holdTime + diffT;
  }
  else if (holdButt && digitalRead(3) == HIGH){
    holdButt = false;
    if(holdTime > 1000){
      //longPressATime = 5000;
      kozichOn = !kozichOn;
    }
    else
    {
      shortPressATime = 5000;
    }
    holdTime = 0;
  }

  if(shortPressATime > 0)
  {
    shortPressATime = shortPressATime - diffT;
    if(((uint16_t(shortPressATime/128) / 2) & 1) == 0){
      charlie(oko1);
      charlie(oko2);

    }
    else{

    }

  }
  else{
    if(kozichOn){
      charlie(koz1);
      charlie(koz2);
      charlie(koz3);
      charlie(koz4);
      charlie(koz5);
      charlie(koz6);
      charlie(cap);
    }
    charlie(oko1);
    charlie(oko2);
  }
  pinMode(5, INPUT);
  pinMode(6, INPUT);
  pinMode(2, INPUT);
  pinMode(4, INPUT);
}

what is the desired functionality?

The first thing I would try is to get rid of the Arduino core, and program instead at the avr-libc level:

use direct port access instead of digitalRead()/digitalWrite()
setup a timer and measure time in units of timer overflows instead of using millis().

Also, use int8_t for all small ints (especially in arrays), and uint16_t for time management if you don't need to handle durations larger than 65,535 time units.

Edit: Here is my attempt at translating your code to plain C +
avr-libc. Note that, as I don't know the pinout of the core you are
using (what is pin 6?), I am making one up. I also implemented Michel
Keijzers suggestion about factoring duplicated code into a function,
which I called set_pin(). Completely untested:
#include <stdbool.h>
#include <string.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/atomic.h>

#define INPUT 0x0f
#define LOW   0x00
#define HIGH  0x01

// Configure Timer 0 to count milliseconds, assuming F_CPU = 8 MHz.
static void init_timer() {
  OCR0A  = 125 - 1;     // period = 125*64 = 8000 CPU cycles
  TCCR0A = _BV(WGM01);  // CTC, TOP = OCR0A
  TCCR0B = _BV(CS00)    // clock @ F_CPU/64
         | _BV(CS01);   // ditto
  TIMSK0 = _BV(TOIE0);  // enable timer overflow interrupt
}

volatile uint16_t millis_counter;

// Count a millisecond on each timer overflow.
ISR(TIM0_OVF_vect) {
  ++millis_counter;
}

// Read the milliseconds counter avoiding race conditions.
static uint16_t millis() {
  uint16_t millis_counter_copy;
  ATOMIC_BLOCK(ATOMIC_FORCEON) {
    millis_counter_copy = millis_counter;
  }
  return millis_counter_copy;
}

static void setup() {
  PORTB |= _BV(PB4);  // pullup on PB4
  init_timer();
  sei();
}

// Set a pin as either INPUT, LOW or HIGH.
static void set_pin(uint8_t pin_mask, uint8_t state) {
  if (state == INPUT) {
    DDRB &= ~pin_mask;     // INPUT
    PORTB &= ~pin_mask;    // no pullup
  } else {
    if (state)
      PORTB |= pin_mask;   // HIGH
    else
      PORTB &= ~pin_mask;  // LOW
    DDRB |= pin_mask;      // OUTPUT
  }
}

static void charlie(uint8_t a[])
{
  set_pin(_BV(PB0), a[0]);
  set_pin(_BV(PB1), a[1]);
  set_pin(_BV(PB2), a[2]);
  set_pin(_BV(PB3), a[3]);
}

void loop() {

  uint8_t koz1[4] = {INPUT,LOW,HIGH,INPUT};

  uint8_t koz2[4];
  memcpy(koz2, koz1, sizeof(koz1[0])*4);
  koz2[1] = HIGH;
  koz2[2] = LOW;

  uint8_t koz3[4] = {LOW,HIGH,INPUT,INPUT};
  uint8_t koz4[4];
  memcpy(koz4, koz3, sizeof(koz3[0])*4);
  koz4[0] = HIGH;
  koz4[1] = LOW;

  uint8_t koz5[4] = {LOW, INPUT,INPUT,HIGH};
  uint8_t koz6[4];
  memcpy(koz6, koz5, sizeof(koz5[0])*4);
  koz4[0] = HIGH;
  koz4[3] = LOW;

  uint8_t cap[4] = {INPUT, HIGH,INPUT,LOW};

  uint8_t oko1[4] = {LOW, INPUT,HIGH,INPUT};
  uint8_t oko2[4];
  memcpy(oko2, oko1, sizeof(oko1[0])*4);
  oko2[0] = HIGH;
  oko2[2] = LOW;

  static uint16_t oldTime = 0;
  uint16_t Ctime = millis();
  uint16_t diffT = Ctime - oldTime;
  oldTime = Ctime;

  static bool holdButt = false;
  static uint16_t holdTime = 0;
  static uint16_t shortPressATime = 0;
  static bool kozichOn = true;

  if (bit_is_clear(PINB, PB4))
  {
    holdButt = true;
    holdTime = holdTime + diffT;
  }
  else if (holdButt && bit_is_set(PINB, PB4)){
    holdButt = false;
    if(holdTime > 1000){
      kozichOn = !kozichOn;
    }
    else
    {
      shortPressATime = 5000;
    }
    holdTime = 0;
  }

  if(shortPressATime > 0)
  {
    shortPressATime = shortPressATime - diffT;
    if(((shortPressATime/128 / 2) & 1) == 0){
      charlie(oko1);
      charlie(oko2);
    }
  }
  else{
    if(kozichOn){
      charlie(koz1);
      charlie(koz2);
      charlie(koz3);
      charlie(koz4);
      charlie(koz5);
      charlie(koz6);
      charlie(cap);
    }
    charlie(oko1);
    charlie(oko2);
  }
  DDRB &= ~(_BV(PB0) | _BV(PB1) | _BV(PB2) | _BV(PB3));
}

int main(void) {
  setup();
  for (;;)
    loop();
}

Compiling with avr-gcc 5.4.0, I get 642 bytes of flash and 31 bytes of
RAM (data + BSS, not counting the stack).

I suggest ditching the ArduinoIDE and moving to Atmel Studio. I had good experience using it with USBasp and using avrdude (supplied as a part of Arduino IDE) to upload the program to ATTiny13a directly.

Made it thank you, thank for suggestion, ive heard of it, but it seems even harder to me, like i know c# and similiar bcz of game development, but idek what atmel studio uses, but i will give it a try in some upcoming project. Again big thanks.

I will try your translation, I was prototyping with arduino so it should have been
0,1,2,4 plexing
3 - pullup button

When I compile it, I get:
Sketch uses 2630 bytes (8%) of program storage space. Maximum is 32256 bytes.
Global variables use 64 bytes (3%) of dynamic memory, leaving 1984 bytes for local variables. Maximum is 2048 bytes.

I removed all commented lines, and changed the integers to bytes (according to Edgar Bonet's answer as a start.
Than I get the code (added at end) and the following results:
Sketch uses 2432 bytes (7%) of program storage space. Maximum is 32256 bytes.
Global variables use 24 bytes (1%) of dynamic memory, leaving 2024 bytes for local variables. Maximum is 2048 bytes.

According to the specs, an AtTiny85 has 8 KB Program memory and 512 bytes SRAM, so you should be safe.
Note however, if you want to count SRAM memory (24 bytes counted by the IDE), but also you have to add:

Bytes for the calling depth of functions (e.g. loop calls copy and this calls memcpy, the total memory is for copy:  + 2 (byte*) + 2 (byte*) + 1 (byte) bytes, and for memcpy:  + dst (2) + src (2) + sizeof (1) byte. You have to check the most 'worse' call (so check the deepest invocation with all arguments added). This is all added to the so-called stack.
Also you have to add the cost of local variables (once per function), because these are also added to the stack.
If you use dynamic variables (malloc) you also have to add them, but this is not used in your sketch.

The bytes used for items 1 to 3 are not mentioned (because these are allocated at runtime).
void setup() {
  pinMode(3, INPUT_PULLUP);
}

void charlie(byte a[])
{
  if(a[0] < 0){

    pinMode(5, INPUT);
  }else
  {
    pinMode(5, OUTPUT);
    digitalWrite(5, a[0]);
  }
  if(a[1] < 0){

    pinMode(6, INPUT);
  }else
  {
    pinMode(6, OUTPUT);
    digitalWrite(6, a[1]);
  }
  if(a[2] < 0){

    pinMode(2, INPUT);
  }else
  {
    pinMode(2, OUTPUT);
    digitalWrite(2, a[2]);
  }
  if(a[3] < 0){

    pinMode(4, INPUT);
  }else
  {
    pinMode(4, OUTPUT);
    digitalWrite(4, a[3]);
  }
}

void copy(byte* src, byte* dst, byte len) {
    memcpy(dst, src, sizeof(src[0])*len);
}

void resetP()
{
  pinMode(5, INPUT);
  pinMode(6, INPUT);
  pinMode(2, INPUT);
  pinMode(4, INPUT);
}
void loop() {

  byte koz1[4] = {-2,LOW,HIGH,-2};
  byte koz2[4];
  copy(koz1, koz2, 4);
  koz2[1] = HIGH;
  koz2[2] = LOW;

  byte koz3[4] = {LOW,HIGH,-2,-2};
  byte koz4[4];
  copy(koz3, koz4, 4);
  koz4[0] = HIGH;
  koz4[1] = LOW;

  byte koz5[4] = {LOW, -2,-2,HIGH};
  byte koz6[4];
  copy(koz5, koz6, 4);
  koz4[0] = HIGH;
  koz4[3] = LOW;

  byte cap[4] = {-2, HIGH,-2,LOW};
  byte oko1[4] = {LOW, -2,HIGH,-2};

  byte oko2[4];
  copy(oko1, oko2, 4);
  oko2[0] = HIGH;
  oko2[2] = LOW;

  static long oldTime = 0;
  long Ctime = millis();
  long diffT = Ctime - oldTime;
  oldTime = Ctime;

  static bool holdButt = false;
  static long holdTime = 0;
  static long shortPressATime = 0;
  static bool kozichOn = true;

  if(digitalRead(3) == LOW)
  {
    holdButt = true;
    holdTime = holdTime + diffT;
  }
  else if (holdButt && digitalRead(3) == HIGH){
    holdButt = false;
    if(holdTime > 1000){
      //longPressATime = 5000;
      kozichOn = !kozichOn;
    }
    else
    {
      shortPressATime = 5000;
    }
    holdTime = 0;
  }

  if(shortPressATime > 0)
  {
    shortPressATime = shortPressATime - diffT;

    if(((round(shortPressATime/100) / 2) & 1) == 0){
      charlie(oko1);
      charlie(oko2);
      resetP();
    }
    else{
    }
  }
  else{
    if(kozichOn){
      charlie(koz1);
      charlie(koz2);
      charlie(koz3);
      charlie(koz4);
      charlie(koz5);
      charlie(koz6);
      charlie(cap);
    }
    charlie(oko1);
    charlie(oko2);
  }
  resetP();
}

Iam actually using Attiny13a which has only 1024bytes, thru using some help from arduino forum i got to great 1218bytes which is super close to the goal, I will now try to implement this.
EDIT: With your improvement Iam at 1074bytes super close.

So you need to reduce the code size (Flash), not SRAM? These are two different things.

Sorry but iam back at the problem I need to diffirentiate 3 values and when I use bytes I need to change the function so it ifs(==2) but then Iam back at 1246

Not sure what you say (also you didn't give an answer I think) ... You could copy the duplicated code to a single function and call it with parameters, that saves you some Flash space.

Made it. Thank you

You're welcome ... if you think the answer is useful, upvote it (press the up-arrow next to the question); if you think the answers solved your problem, also accept it (press the check sign next to the answer). Good luck with your project.

@eternaldownvoter: please write what can be improved.


text:
Uno Wifi rev2 - after long time it disconnects
Given an Arduino Uno Wifi Rev2 with this small U-blox NINA wifi module.
All work great however after a long time (I can't be more exact but we talk here about weeks if not months), it suddenly disconnects.
This board is unattended, and the only way to recover is to reset the Arduino.
Here is my code:
WiFiServer server(PORT);

void setup() {
  connectToWifi();
  server.begin();
}

void connectToWifi() {
  // attempt to connect to Wifi network:
  while (status != WL_CONNECTED) {
    Serial.print("Attempting to connect to SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network. Change this line if using open or WEP network:
    status = WiFi.begin(ssid, pass);
    if (status == WL_CONNECTED) break;

    // wait 10 seconds for connection:
    delay(10000);
  }
}

void loop() {
  // check WiFi status
  if (WL_CONNECTED != WiFi.status()) connectToWifi();

  WiFiClient client = server.available();
  if (client) {
    while (client.connected()) {
      if (client.available()) {
        char c = client.read();

        ... (other wifi-unrelated code)

        // close the connection:
        client.stop();
      }
    }
  }
}

When it disconnects from wifi, the router's dhcp manager console shows it with "waiting" status.
Note: I'm the only client, and only one character is sent to the Arduino at once, then the socket is closed. It is very unlikely, that a client hangs, and the board is stuck in the while loop.
Is this a known problem, or I have to dig myself more into this?
Thank you!

do you use the newest versions of firmware and library?

I've updated that at the end of last year. Until then it is unattended, and this is the second time this situation happened. (after the first time we had to apply a power recycle to the board). So I'm not sure that's the latest, and I can not query it, as it is far away and lost the connection

As you have not given the details there are some things to check

is your Nina-Firmware > 1.2.4
If not update to the latest 1.3.0 via the WiFi101-FirmwareUpdater-Plugin 0.10.10 is included in the ArduinoIDE 1.8.12 or greater
Disconnect before you reconnect (in case of router drop-outs) and
Close any connection before sending/receiving. This will free the socket on the Nina module. Stop the client after doing the stuff needed with   client.stop();
If there is any server connection code in setup this should be run in a reconnect routine (as you did not include setup) just as a hint
Make sure that after a certain period the while (status != WL_CONNECTED) and while (client.connected()) are broken and error testing takes place e.g. if (status==WL_DISCONNECTED || status==WL_CONNECTION_LOST){.. do something to change that ..}
If all fails implement a routine that checks the signal and restarts the sketch if the router has dropped out (for whatever reason).

Disconnect code:
void connectToWifi() {
    // This new line is required to disconnect the previous connection otherwise
    // it will try to use the old connection and never reconnect if the connection fails
    status = WiFi.disconnect();

    // attempt to connect to Wifi network:
    while (status != WL_CONNECTED) {
    .... REST of your code ...
    }
}

Hint (as you did not show setup) if you have something like
client.connect(server, 80);

move it to the reconnection routine in the form of
if (client.connect(server, 80)) {
    Serial.println("connecting...");
.... REST of reconnect ...
}

Restart code if wifi signal is lost
void(* resetFunc) (void) = 0; // Declare reset function at address 0

void loop() {
  if (WiFi.RSSI() == 0) // Checks if Wifi signal lost.
  { resetFunc(); // Calls Reset
  }
// Rest of code goes here.
}

This should altogether ensure a long and stable running client

Thank you, points 1-2-3 I can check once I return to the board. client.stop(); is actually called, I've updated the Q. server.begin is called only once in setup - Q is updated. I need to call server.begin after every connectToWifi call?

No not server.begin()  thats ok as it is - please give infos to your schematic of the network. Are there clients connected to the UNO (server.begin indicates that) and the UNO acts himself as client to anothrer server. Or is the UNO the only server ? . Its hard to work with bread crumbs (what libs are you using, is String clas called, what is attached to the UNO, ... The more info the more precise the answers you get

UNO functions as a server. One client very rarely (once/week) connects to it, sends 1 character as a command, then UNO responds with client.print("response"); (always 1 line only). Very simple logic: UNO reads some GPIO and put it into response.

I had 1.2.4 version on the NINA, now upgraded to 1.3.0. Also added the status = WiFi.disconnect(); line to the connectToWifi routine. Keeping my fingers crossed.

source: Stack Exchange

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

sort: votes


text:
just get my mkr1000 in macOS Sierra 10.13 and no way to connect
I have connected the device via USB, downloaded the latest version of Arduino IDE (1.8.5) installed (automatically offered) the drivers for the mkr, and there's nothing in the serial port selector besides the bluetooth. I've also installed the FTDI drivers but the same scenario.
What else can I try?
Error message:
Arduino: 1.8.5 (Mac OS X), Board: "Arduino/Genuino MKR1000"

Sketch uses 9624 bytes (3%) of program storage space. Maximum is 262144 bytes.
Couldn't find a Board on the selected port. Check that you have the correct port selected.  If it is correct, try pressing the board's reset button after initiating the upload.

Seems like it is trying the bloutooth port
PORTS {/dev/cu.Bluetooth-Incoming-Port, /dev/tty.Bluetooth-Incoming-Port, } / {/dev/cu.Bluetooth-Incoming-Port, /dev/tty.Bluetooth-Incoming-Port, } => {}

UPDATE this is a system report screenshot:

Also the FTDI kext is loaded
sudo kextload /Library/Extensions/FTDIUSBSerialDriver.kext
kextstat | grep FTDI
  194    0 0xffffff7f85e62000 0x7000     0x7000     com.FTDI.driver.FTDIUSBSerialDriver (2.4.2) E16D9540-AF63-36AD-94C4-B1164FBD6078 <109 55 5 4 3 1>

Does plugging and unplugging the USB device cause any messages in the kernel debug messages to appear (dmesg -w, see https://discussions.apple.com/thread/4170078)?

007942.764202 Bluetooth USB Host Controller@14300000: IOUSBHostDevice::forcePowerGated: allowing power level to float
007942.764217 Bluetooth USB Host Controller@14300000: IOUSBHostDevice::forcePowerGated: kPowerStateSuspended completed with 0x00000000 after 0ms

the device is correctly listed in USB devices in settings

Which device is correctly listed? Can you edit your main question include logs and or a screenshot? Above messages indicate that you're seeing something about your Bluetooth controller? Or are those really the messages you get at the exact moment you plug/unplug the Arduino? (I'm trying to figure out here if the USB device is recognized at all, maybe your board is dead.)

@MaximilianGerhardt I've added a screenshot

So the MKR1000 gets listed somewhere in your Mac, but you cannot select it as a port in the Arduino IDE? Can you edit your question to include the output of ls /dev/. Also, maybe https://arduino.stackexchange.com/a/13825/30175 is relevant?

well ls /dev/ is a very long result, a lot of ttyuX devices, I've already tried with FTDI drivers also

After rebooting, have no idea why, the device is listed on the list and I'm able to use it

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


text:
Is there a bridge needed to connect Pro Mini 3.3v to HC-05 (level 3.3v)?
I can't understand how to connect my arduino pro mini https://www.amazon.in/gp/product/B071ZCHW5P/ref=oh_aui_detailpage_o00_s00?ie=UTF8&psc=1
To my HC-05 Bluetooth module https://www.ebay.in/itm/HC05-Wireless-Bluetooth-RF-Transceiver-Module-Serial-TTL/182970488321?ssPageName=STRK%3AMEBIDX%3AIT&_trksid=p2057872.m2749.l2649
There is a guide to connect them given here : http://www.instructables.com/id/Bluetooth-Serial-Adapter-for-Pro-Mini/
I am trying to follow this guide but it is for 5V version and involves shorting the diode on the pro mini plus a divider circuit.
Here is the circuit:
Apparently, there is an obvious difference in the circuit according to my components.
Please help me connect them correctly.
Thanks :)

Double check that your pro mini is a 3.3V (the comment on Amazon states it is NOT 3.3V version). If it is, and you confirm that the HC is 3V3 too, you don't need the voltage divider (just use the wires). As for the diode, you just have to check that the power arrives to the HC; if it doesn't, try getting it from another VCC pin (or short circuit the diode as suggested in the instructable). Just note that the author says that you have to connect TX with TX and RX with RX; if your solution doesn't work try swapping them

If both devices are 3,3 volt, there is no need for the 10K/15K voltage divider. The Rx pin on the HC-05 is only receiving 1.98volt as a logical 1 and thet is way to low.

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


text:
Can't power HC-05(5v) with Arduino Pro mini (3.3v)?
I am trying to use HC-05 (5V) with Arduino Pro Mini (3.3v) but I have had little success.
I am using a coin cell to power the pro mini which powers it on and is working fine.
But, my HC-05 doesn't power on. I am trying to power it externally using two 3.7v Lipo-batteries that gives a total of 7.4v but I have tried numerous changes and nothing seems to work.
Circuit Diagram attached below.

Also, HC 05 has an onboard regulator for levelling it to 3.3v

Please Help!!!

It seems like 7.4V DC is greater than the 5V regulator input range on the HC-05.
For example, in the Core Electronics tutorial for the HC-05 (the tutorial PDF calls it a JY-MCU. I can't find any major differences), the pinout table says the voltage should be from 3.6V to 6V DC:

These same values are confirmed by a back-of-the-circuit-board photo from arduino-info.wikispaces:

Components101 says the range is 4V to 6V.
Unfortunately your coin cell voltage is too low. That leaves you with the following options to drop your voltage (if you must use the 7.4V DC battery). Your choice will probably depend on the Wh capacity of your battery, and how efficient you need the voltage drop circuit to be.

Zener diode (few components, inefficient use of power)
Voltage divider with resistors (few components, inefficient use of power)
Linear regulator (few (IC) or many (discrete) components, inefficient use of power)
Switching regulator (many components, efficient use of power (because it does not use a resistor to drop the voltage)

Further details on each of these options are at Lower Voltage Methods Other than Voltage Dividing.

My module is 5~7v version unfortunately which is the cause of all of my problem. I have added the module image to the original question.

Also note that 3.7 Volt is the nominal values. It's more like 4.2 when fully charged. So you'd end up with 8.4 Volt when both batteries are full.

@HardikSharma did you choose a technique to reduce your voltage, or are you just going to use a 5V power supply? Also, please upvote my answer if useful or vote it as the answer if it answered your question (https://stackoverflow.com/help/privileges/vote-up)

My GND was loose and using a single battery worked after fixing that. So thanks for the information anyway.


text:
Serial Monitor stops printing data
I have an IMU sensor (MPU 6050) connected with arduino UNO. Pin maps are as follows:
MPU6050 --> Arduino
Vcc --> Vcc
Gnd --> Gnd
SCL --> A5
SDA --> A4
(Not using any pull up resistors)
I am using jeff rowberg's MPU6050 library to get data from sensor. To test the sensor, I am using the raw value example sketch from the library. I am getting readings for both the accelerometer and the gyroscopes.
The problem is after some time the serial monitor just stops printing data. I have tried to figure it out but have not succeeded in solving the problem. It could be due to one of two reasons:

The MPU6050 stops giving sensor values
There is a problem with the serial monitor

As far as I have figured, the sensor is giving values because when I restart the serial monitor, the data starts to print again on the serial monitor and stops printing after same duration of time as it did before restarting the monitor.
I have tried the serial monitor of the arduino IDE and hyperterminal. In both cases the data stops printing after some time.
Any idea, what causes the serial monitor to stop printing data? Is it the sensor or the serial monitor?
Help would be greatly appreciated. Thanks in advance.

Chances are it's I2C locking up whilst reading from the MPU6050. Re-opening the serial monitor resets the Arduino. Check your wires (I2C doesn't like long wires), and add 3.3KΩ pullups to the I2C wires (if not provided by the MPU6050 board). Internal Arduino pullups are not adequate for I2C.

Please post the sketch. It could also be a String/memory allocation problem.

@Majenko It worked. I can't believe it but changing the wire length actually worked. I was using really long wires before, I shortened the length but it didn't worked so I shortened the length even more. This time the serial monitor didn't  stop.
I can't understand what cause the wire length has on the communication process though. Seems illogical.
Thanks again for helping out.

Au contraire - it's perfectly logical. Long wires = big antenna = picks up noise. Weak pullups = noise easy to interfere with communications. Combine the two and you have a recipe for disaster. Fix one or both and you get it working.

Note that even with good wiring, I2C code that lacks a "give up and try over" timeout is risky - if it waits eternally for a slave acknowledgement, one single misinterpreted bit will hang the system.

@AhmadTariq What was the initial length of your cabling and what was the final one?.

@ChrisStratton I have a similar problem: when I connect two I2C devices to Arduino Mega, after some long execution time (several days), serial monitor stops working. Is there anyway to log an error message to check if the problem comes from this timeout thing?

I had exactly same situation.
I initially started to inspect on FIFO overflow of MPU6050, then experimented setting different clock speed for I2C communication, tried to tweak with pullup resistors as recommended.
Finally, here is the solution which worked for me. Basically, I just disconnected INT pin from MPU6050.
Now the schema is:
(MPU) -> (Arduino)
AD0 -> GND
SDA -> A4 (No pullup)
SCL -> A5 (No pullup)
GND -> GND
VCC -> 3.3V
I used this code as an example:
https://github.com/jarzebski/Arduino-MPU6050/blob/master/MPU6050_gyro_pitch_roll_yaw/MPU6050_gyro_pitch_roll_yaw.ino
from this library:
https://github.com/jarzebski/Arduino-MPU6050

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


text:
Does this code work as a PWM?
I'm working on an Arduino project and I need to write some code that controls the frequency and duty cycle of a square wave signal (pulse width modulation). I'm not allowed to use the PWM function, I have to write my own code.
I've tried this code on Proteus (virtual Arduino) but there are two problems:

The frequency is always high (hundreds of Hz) even if the input voltage is zero. It never reaches 0.5 Hz or 1 Hz.
The duty cycle is very high or very low. I never see 50% or 75% duty cycle on an oscilloscope. When I change the position of the potentiometer it becomes 90% or 10% (I think) and there are no other values.

Would you tell me what's wrong with this code please? I can not find my mistake:
unsigned long Time = 2000000; unsigned int Volt; float dutyCycle = 0.5;
void setup() {
  pinMode(13, OUTPUT); //set Pin 13 or On-board LED to output
}

// the loop function runs over and over again forever
void loop() {

  Volt = analogRead (1);    // Frequency: input voltage is through potentiometer at analong pin 1
  dutyCycle = analogRead (0) / 1023;    // dutyCycle potentiometer is at analong pin 0
  Time = ( 2000954 / (1 + Volt) )- 954; //This equations is linear. When input voltage is zero, frequency = 0.5Hz. When input voltage is 5v, f=1000Hz.

  digitalWrite(13, HIGH);   // turn the LED on
  delayMicroseconds(Time * dutyCycle );              // wait
  digitalWrite(13, LOW);    // turn the LED off by making the voltage LOW
  delayMicroseconds(Time * (1-dutyCycle) );          // wait
}

dutyCycle = analogRead (0) / 1023;    // dutyCycle potentiometer is at analong pin 0

Dividing a small integer by a bigger integer leaves you with 0. If analogRead() returns 1023 you will get a result of 1. Everything else will give you 0. You need to divide by a floating point number - either 1023.0 or 1023f.
analogRead() is slow. Because it is happening between every single cycle of your square wave you can expect to never get to anywhere near 100% duty cycle. There will always be a LOW period where the analog input is being read.
You should:

Fix your integer division problem
Make the ADC "free running" or interrupt driven so it doesn't interfere with your PWM generation

... Or ...

Fix your integer division problem
Make your PWM generation timer driven, either using the OC peripheral or manually with interrupts, so it doesn't interfere with the analog reading.

... Or ...
You could even do both. Make everything as asynchronous as possible leaving your loop() free to just do the heavy work of calculating the values.


text:
Cannot compile code from Arduino WIFI shield example
I'm trying to launch the piece of code in this Wifi example:
https://www.arduino.cc/en/Reference/WiFiConfig
via Arduino.cc online editor, but I'm getting those errors:
/home/ubuntu/opt/libraries/latest/wifinina_1_2_0/src/utility/spi_drv.cpp:87:24: error: 'PINS_COUNT' was not declared in this scope

and
/home/ubuntu/opt/libraries/latest/wifinina_1_2_0/src/utility/spi_drv.cpp:97:15: error: 'NINA_GPIO0' was not declared in this scope

Do someone has an idea of how to solve this?

Those kinds of errors are usually caused by the selection of an incorrect hardware in the IDE.
Choosing a correct board in the IDE will solve the compilation issue.
Since you said that you used the Arduino.cc online editor, I pasted your code into the editor.
You did not say which Arduino board or which WiFi module you are using, so I chose Arduino Uno WiFi board as a starting point.
Compiling the code produced the same errors as in the post.
Next I chose Arduino Uno WiFi Rev2 board, and compiled without errors.


text:
Problem Uploading to the Arduino Nano board
]2I am using an Arduino Nano board. It has an ATmega 328P processor. For running the codes I use Arduino 1.8.6 Software. The issue is that when I am uploading my sketch to the board it shows me the following errors:
 Using Port                    : COM7
         Using Programmer              : arduino
         Overriding Baud Rate          : 115200
avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x9b
avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x9b
avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x9b
avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x9b
avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x9b
avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x9b
avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x9b
avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x9b
avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x9b
avrdude: stk500_recv(): programmer is not responding

avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x9b

avrdude done.  Thank you.

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

I have turned on the show verbose output option turned on.
Also, sometimes the following errors pop up:
collect2.exe: error: ld returned 255 exit status

Using library SoftwareSerial at version 1.0 in folder: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.14.0_x86__mdqgnx93n4wtt\hardware\arduino\avr\libraries\SoftwareSerial
exit status 1
Error compiling for board Arduino Nano.

I have referred the following links to solve my issue:

collect2.exe: error: ld returned 5 exit status
Why I can't upload my programs to the Arduino board?

I am making an application wherein I have to control two DC motors via Bluetooth module HC-05
In one of the troubleshooting questions, the solutions contained the possibility of the bootloader not being installed where the problem can be verified by pressing the reset button and checking the bootloader LED to blink. Can someone help me with this?
Also, there are two processors shown for ATmega328P:

The ATmega328P
The ATmega328P (old bootloader)

I tried using then both options for uploading the sketch but still, the errors pop up.
I have also downloaded and installed the latest FTDI drivers from their site.

Can you tell which nano board you have? You can give a link to it or a photo of both sides.

Has this PC->cable->Nano combination ever worked, or is any of those components new? If these are new & untested, have you confirmed the settings: Tools > Board, Tools > Port, and Tools > Programmer? And if they once worked and now don't work, have you tried substituting each of them for known working ones? Will this Nano upload a Blink program from a different PC?

No, I tried for upload blink programme also but didn't work. Also, the components used are tested and are working or have been directly taken from the manufacturer website

The ch340g usb-serial chip is not officially supported by Arduino. You need an extra driver for your nano clone. For windows try this: http://www.wch.cn/downloads/CH341SER_EXE.html

A common solution is to actually switch the board type to the Arduino Uno. It is a known problem but I have yet to see any other viable fix.

the 'new' bootloader option is the same as changing board option to Uno


text:
How to read resistive buttons with Arduino Pro Micro?
I am trying to read some resistive buttons presses on a PCB like this:

This is the full sketch I am using:
#include <Keyboard.h>

byte ZbuttonPin = 3;

void setup() {
 // initialize the button-reading pins
  pinMode(ZbuttonPin, INPUT_PULLUP);
}

void loop() {
  if (digitalRead(ZbuttonPin) == 0) {
    // if the button goes low
    Keyboard.write('z'); // send a 'z' to the computer via Keyboard HID
    delay(100); // delay so there aren't a kajillion z's
  }
}

If I short the Arduino pin 3 and GND directly it outputs the "z" letter correctly.
But when I connect M16 and GND on the PCB it outputs "z" continuously even if the button if not pressed with the rubber pad.

I would suppose that showing the circuit would help others help you. Shorting this or shorting may mean a lot to you hurt exactly zero to those who may be of help to you. Help others help you.

Use a multimeter to test the resistance when the button is pressed and when it is not pressed. Perhaps adjusting the voltage level with a pullup resistor is enough to make it work.

the resistance is about 1.5M ohms when not pressed and 170ohms when pressed... should i change the read logic?

Those values seem okay. It should work. Perhaps you can try with an extra pullup resistor of about 1k to 10k from pin 3 to 5V.

i've tried adding a 10K resistor in series with the pin 3, but still not working as expected. do you think using the 5v pin and wiring like this may solve the problem?

The button at GND and the pullup at 5V or vice versa, that is the same for an Arduino Uno, and almost the same for an Arduino Pro Micro. The Arduino Pro Micro has lower voltage levels for HIGH and LOW for a digital input. You can get the same result by adjusting the value of the pullup resistor. Do you have more resistors to try ? Do you use a breadboard or something else with bad contacts ? If nothing works, you could try an analog input and check at which analog value a pressed button is.

I am using crocodile clips and no breadboard. I've also tried connecting to a momentary pushbutton and it worked fine. Probably i am going to try with analogRead and see what happens...


text:
Directly powering a single 32x16 RGB LED matrix (without external PSU)
All the guides I've found suggest to use an external PSU to power an RGB matrix like this.
However I know it is possible to blink the LEDs at high rates (eg. 2ms) and still give the impression to the eyes they are fully on. I've verified this myself on a small 4x4 matrix, but I am not sure if the same can be done with these bigger matrices.
In my case I could tolerate reduced brightness and color space, but I'd like to power the matrix with the Arduino's 5V pin directly.

give it a try, you won't break anything. probably won't break anything. that said, 512 LEDs is a lot to power from an MCU...

@dandavis: I will power only 1 led at a time, not all 512 at the same time! btw i've also found this monocromatic matrix that can also be powered directly by an arduino. In this case they suggest to not connect the 5V pin at all.  Maybe i should do the same with my RGB matrix?

Don't those matrices already have bypass capacitors on the backside?

I've received yesterday the 32x16 LED matrix I've ordered from AliExpress and I've done some measurements with a multimeter in series with the power wire.
LED multiplexing does not seem a good idea as the matrix is already doing that internally.
Instead I've found that using the minimum color intensity helps a lot reducing the current usage.
E.g. for blue use matrix.Color333(0, 0, 1) instead of matrix.Color333(0, 0, 7); for white use matrix.Color333(1, 1, 1) instead of matrix.Color333(7, 7, 7), etc.
With the minimum brightness I've measured:

All blue LEDs lit = ~170mA
All LEDs lit as white (red+blue+green) = ~400mA

In the average case (not all LEDs are lit) I am getting around 250mA, so I should definitely be fine powering the matrix directly from the 5V pin if I keep the brightness as low as possible.

When powered through USB, the total current consumption is limited to 500mA by the USB interface. If you are using the power connector, the total current is limited by the on board 5V regulator to 1A.
The board will also require some current, so you can draw around 400mA, if powered through USB or 900mA, if powered through the connector; from the 5V pin.
While the matrix on average may not draw than 300 - 400mA, the voltage regulator can overheat and shut off temporarily, and you will never be able to reach 900mA. The regulator is linear, so any extra voltage you supply will result in waste heat.
It is best to get a buck converter or power the matrix externally. You won't be wasting as much power, and avoiding possible thermal shutoff.

but, as you said, if i power the whole thing via a single usb port i can skip the regulator, so there is no risk of shutoff. And if the matrix ICs takes less than 400mA i should be fine because i will have max 1 led on at a time. Now the big question is if the arduino can refresh all the 512 leds at acceptable speed to avoid flickering.

based on my "charger doctor" readings, few USB sources provide only 500ma; 0.8-1.6A is common.

authors: Владимир Эккерт


text:
Wiring an IR blaster+receiver board
I've salvaged this small IR blaster+receiver board from an old computer toy:

As you can see the board was connected to the main unit via a 4-wire cable labelled like this:

LED (yellow) (I guess this is the IR LED/blaster)
IR (white) (I guess this is the IR receiver)
VCC (red)
GND (black)

I'd like to use this board with an Arduino library like IRremote, but I am not sure about the VCC voltage and whether I need to add more components on the Arduino side.
UPDATE:
I've checked the LED with a multimeter and indeed it is a visible bicolor LED, so there is no IR blaster in this board. At this point, is there any good reason to keep the IR receiver on the board rather than just cutting it and reusing as a standalone component?

The receiver (the 3 pin part inside the metal case) appears to be a common IR receiver.  It is likely you can pull that part and use it as the IR receiver in many of the Arduino examples found on line.  The LED (3 pin part made up of only plastic???) is unexpected.  Most of the time IR LED are only 2 pin devices.  As IR LED are inexpensive it might be better to simply buy a new IR LED.

it should be ready to go, that the same stuff you find on new modules

I think the led on the left is just a (visible) indicator led. Since it's a three pin package, it's probably a bi-color one. Could you add a photo of the board, where the wires aren't obscuring part of the PCB? The MELF-diode is puzzling to me, as I was expecting it to be near the top/Vcc side.

5V is most likely fine. I've only seen datasheets for IR-receiver  that  accept a voltage of  5V or more.


text:
Use of additional i/o ports in Arduino Mega
I'm a newbie in Arduino and I bought an Arduino Mega instead of the Uno. I want to know what the so-called additional i/o pins do. Are they the same with PWM and SPI? What can they do?

Do a google image search for "arduino mega pinout" - there's thousands of results that show you exactly what each and every pin can do.

When asking "obvious" questions it helps to explain what you've done to find an answer for yourself – then explain why you are still confused. That way we have a better idea about your question.

Firstly some background info on the Arduino Mega:
I haven't used the Mega, but I've used the Uno, and have worked with a variety of ATmega microcontrollers.
First thing you need to know is that the Arduino Mega (or any other Arduino) is a board that uses the Atmel ATmega microcontrollers. The specific microcontroller used on the Mega is the ATmega1280 ATmega2560.
So if you are keen to learn more about your Arduino, a good place would be to look at the datasheet of the microcontroller itself. Just google ATmega1280 ATmega2560 datasheet.
However this might be a fair bit complicated, since you are new to the Arduino and microcontroller world.
A good place to start would be the Arduino website itself (but I suppose you've already looked at it).
Now, regarding your question:
I'm not sure what you are referring to as "additional i/o pins", but here's a quick rundown on what I/O pins are and used for.
As you may know I/O pins are used by the microcontroller to talk to the outside world. On the ATmega chips, most of these are GPIOs (General Purpose I/Os) that can be programmed to receive or send digital signals. Of these GPIOs some are used for PWM, and some may be used for some communication protocol. And of course there are analog input & reference pins, voltage supply, ground etc.
You can find all this information in the datasheet I linked above.
If you are curious how Arduino has routed the pins, you can have a look at the schematic of the Arduino Mega here.
If you also have a look at the Arduino website, they have a very good description on what each pin does: Arduino Mega.
Look at "Inputs and Outputs".

Even though the poster said he bought an "Arduino Mega", what he almost certainly bought is an Arduino Mega 2560, so the microcontroller in question is an ATmega2560 (Identical to the ATmega1280, except that it has twice the flash capacity).


text:
Arduino and hard drive
So in a laptop you have a CPU and a hard drive. The hard drive feeds data to the CPU and the CPU executes it. In Arduino you flash the CPU and the "hard drive" is built into it. Is it possible to have a hard drive or SD card feed data into the Arduino to be executed and then feed more data in and so on? If it is possible how is it done?

Is it possible to have a harddrive or sd card feed data into the Arduino to be executed and then feed more data in and so on. If it is possible how is it done?

A harddrive would be difficult to connect, but an SD card will work just fine.
You can write a sketch that reads data from an SD card. There is library support for both SD and FAT16/32 file systems.
Another interpretation of your question is; is it possible to load a sketch from an SD card. The answer is yes; there are a number of projects that have done that.
Cheers!

will loading sketches take long and will it reduce the lifespan of the chip?

Depends on how often you want to update the sketch? It is not a very good idea to load the sketch from SD every time. There should be some logic to when the sketch is updated and should be loaded.


text:
Can we detect a magnet using Arduino? If so how?
If so, please tell me and also tell me if any interfacing of other microcontroller needed?

Please read How do I ask a good question?. More details give you a better answer. Is this something slow (eg. detecting a window opening) or something fast (eg. a magnet on a bicycle spoke)? What are you trying to achieve?

I can't comment yet but you probably are looking for a hall effect sensor.
Something like this is a simple version of the sensor. https://www.sparkfun.com/products/9312
You can then do a digitalRead on the DO pin to detect if a magnet is near the sensor.
You would connect the Vdd to 5v arduino supply and GND to the GND of the board.

Just note that there are different kind of hall-effect sensors. Some respond only to one polarity (i.e. only North or only South). Some will give a on-off value (i.e. magnet present/magnet not present), while others can give an analog value proportional to the magnetic field present. Choose the one most suitable to your project.

If you don't care about measuring the strength of the magnetic field, you can use a magnetic switch (sometimes called a reed switch). A magnetic switch closes when a magnet is put up to it and opens when there is not. The only problem with this is that the magnet has to be within about one inch from the switch. The magnetic switch works just like a normal switch and usually has two contacts. Here is an example.


text:
Ublox GPS with Arduino Mega 2560 not working
Recently I bought a GPS module (ublox neo-6M-0-001) for my Arduino Mega 2560. I connected Vcc and Gnd (LED at GPS module glows blue and sometimes blinking).
GPS module RX port is connected to the Arduino's TX3, Port 14.
GPS module TX port is connected to the Arduino's RX3, Port 15.
As a first step I just want to print the serial data received from the GPS module:
#include "SoftwareSerial.h"

SoftwareSerial mySerial(15, 14); // RX, TX

void setup() {
  Serial.begin(9600);
  Serial.println("uBlox Neo 6M Test");
  mySerial.begin(9600);
}

void loop() {
   if (mySerial.available())
     Serial.write(mySerial.read());
}

Saldy, there is no data received from the GPS module. According to the datasheet the baud rate 9600 seems to be correct.
Do I need to configure the GPS module somehow before it delivers data? Do I need to buy an external antenna?
Thanks for your help.

The Arduino Mega 2560 has three additional hardware serial ports. Why not use one of them instead? Serial1 on pins 19 (RX) and 18 (TX).
void setup()
{
  Serial.begin(9600);
  Serial.println("uBlox Neo 6M Test");
  Serial1.begin(9600);
}

void loop() // run over and over
{
  if (Serial1.available())
     Serial.write(Serial1.read());
}

Cheers!

Wow. Very good. If I use the keyword Serial1 instead of the library SoftwareSerial it works perfect. But I don't understand whats wrong with the library.

Actually I think it is simply an invalid pin for SoftwareSerial RX. The source code says "Not all pins on the Mega and Mega 2560 support change interrupts,
so only the following can be used for RX: 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69".

You could use Serial3 on pins 15 (RX) and 14 (TX).

I am also using the sam setup i.e Arduino Mega and NEO6VM2. The GPS module works perfectly fine with a Arduino Uno but when using Mega there are no CharsRX received i.e the Mega is not receiving anything. Please I need help urgently.

If you want help, then first of all you should ask a proper question and not post it as an answer to another question. Please learn how to use this site: https://arduino.stackexchange.com/tour


text:
Why do I need to connect a potentiometer to a +5V source in 1602 tutorial?
I'm getting starter with the Arduino and I'm going through the classic tutorial, it says to connect the VO to a pot's wiper, and pot itself to +5v and ground, so I did.
I tuned it and it worked, but then I thought, why do I need a pot if I don't plan to move it from this value? Why don't I just replace it with a resistor? But I'm still very new to electronics, Ohm's law, etc, and I got confused.
Why do I need to connect a potentiometer to +5v source, if the resistor between VO and the GND will do? I unplugged the +5v from the pot and it still worked. I had to adjust the position, but it works just fine without it, so my question is, if it works without, why all tutorials tell us to connect it to a +5v?

VO controls the contrast of the LCD, which is quite temperature-dependent.
You can get away with a fixed resistor between VO and GND because of the built-in resistor between VCC and VO, producing a voltage divider.
In many cases you can also use a direct connection between VO and GND, resulting in a voltage of zero at VO.
However, be aware that the contrast changes if the ambient temperature leaves your "comfy zone". Depending on where you want to use the LCD, you need to check that out "in the field."

I may be wording my question unclear but what I am actually interested in is why most tutorials say to comnnect a VCC to a +5 as opposed to leave it disconnected, it works either way so what might be a benefit of connecting it to the Vcc

@YouCare I don't understand what you mean by "comnnect a VCC to a +5". would you mind to elaborate? I thought we were talking about V0.

why do I need to connect, a potentiometer to +5v source, if the resistor between VO and the GND will do?

That's because the 1602 board itself (usually) has a resistor between VO and VCC. So to make voltage divider you only need to add one extra resistor from VO to Gnd (ca. 1-2K probably).
So, yes, you can go with only one resistor (or with the pot disconnected from VCC) if the board already has another resistor pre-soldered.


text:
SD card fails to initialize
I know this question has be asked before on this site. However it was never really answered. I have an Arduino Uno. I am trying to get it to read a 2 GB SDHC Micro SD card. The problem is, the SD card never intializes. I am not sure if there is something wrong with the wiring (which I think is NOT the issue) or the SD card/shield. I have formatted the SD card, but perhaps I did use the wrong settings to do so. Additionally, this SD card is quite old, probably several years. It can still be managed on my PC however.
I bought the following Micro SD shield off Amazon. It has the pins VCC, GND, MISO, CS, MOSI, and SCK, for which I figured the following:
MISO = D0
CS = D1
MOSI = CLK
SCK = D3

I have the circuit wired in the following way:
SCK to Pin 10 on Arduino
CS to Pin 11 on Arduino
MISO to Pin 12 on Arduino
MOSI to Pin 13 on Arduino
VCC to 3.3V source on Arduino
GND to Arduino Ground

The image below is a compilation of the closeup of the shield and my wiring. Not that I am also using Pin 9 in the picture. However this is used for a different portion of the circuit.

The code that I am trying to run comes from the SdFat library. Though the Amazon page says the device can be used without this library, I prefer to have it. I am running the SdInfo.ino example located in SdFat/SdFat/examples/SdInfo/. I have changed the coding so that:
const uint8_t SD_CHIP_SELECT = 10;

I have also tried running the Basic.ino example in the TMRpcm library, located at: TMRpcm/examples/basic, but this doesn't work either. Below is the code:
#include <SD.h>                      // need to include the SD library
//#define SD_ChipSelectPin 53  //example uses hardware SS pin 53 on Mega2560
#define SD_ChipSelectPin 10  //using digital pin 4 on arduino nano 328, can use other pins
#include <TMRpcm.h>           //  also need to include this library...
#include <SPI.h>

TMRpcm tmrpcm;   // create an object for use in this sketch

void setup(){
  tmrpcm.speakerPin = 9; //5,6,11 or 46 on Mega, 9 on Uno, Nano, etc
  Serial.begin(9600);
  if (!SD.begin(SD_ChipSelectPin)) {  // see if the card is present and can be initialized:
    Serial.println("SD fail");
    return;   // don't do anything more if not
  }
  tmrpcm.play("music"); //the sound file "music" will play each time the arduino powers up, or is reset
}

void loop(){
  if(Serial.available()){
    if(Serial.read() == 'p'){ //send the letter p over the serial monitor to start playback
      tmrpcm.play("music");
    }
  }
}

In short. My SD card does not initialize, and I cannot seem to figure out why.

The first thing to try is to use the 'proper' pins for the SPI:
SCK to Pin 10 on Arduino ---> Pin 13
CS to Pin 11 on Arduino ---> Pin 10
MISO to Pin 12 on Arduino ---> Pin 12
MOSI to Pin 13 on Arduino ---> Pin 11
VCC to 3.3V source on Arduino
GND to Arduino Ground

Try that first and see how you get on.

By the way, just thought I'd mention, probably worth just following the Adafruit example word for word as I'm guessing your board is pretty much a good fit for this tutorial:
https://learn.adafruit.com/adafruit-micro-sd-breakout-board-card-tutorial
good luck getting it rockin' ;)

That breakout board includes a 3.3V regulator and level shifter.  It should be powered from 5V for proper operation.
Also, as @Andology mentions: use the correct SPI pins.

Thanks, I'm at work right now. I'll give it a try later today!

If you have checked everything (wiring, coding your correct pin etc), AND you have already formatted the new card with the correct sd formatter and/or fat32 formatter, and it still does not work; I have found the following worked on some cards:  Simply create an empty (0 bytes) file on the new card.  Cards that were returning all kinds of funny errors (like they are too small - or simply won't initialize)  magically start working !

The solution to this problem, is that you have to let digital Pin 10 as output (for the SD library to work) and put out a logic HIGH by adding “digitalWrite(10,HIGH);”. For Arduino Mega you have to do exactly the same ignore pin 53 completely though the comment asks you to change it to 53.
pinMode(10, OUTPUT); // change this to 53 if you are using arduino mega
digitalWrite(10, HIGH); // Add this line


text:
Need a component to connect a 9v water pump
I have a 9v water pump that i want to turn on\off from the arduino,
What module should i use to turn it on and off?
I am using now a mosfet for my 5v pump, can a mosfet be used for 9v as well? Or is there some better solution?

Yes, a MOSFET, that can be used with 9V (as most of them do). Refer to the datasheet of your MOSFET

Is there any suggestion?

There are many possible MOSFETs that you can use. Look at the maximum values for the drain-source-voltage and check, that the threshold voltage lies around 2.5V or lower, so that the MOSFET is fully conductive, when you turn the Arduinos output on. Also look, if the maximum current lies over the current, that your pump needs. You can provide a link or at least a part number to your MOSFET in your question. Then we could say, if you can use it for the 9V pump. (You also need to provide the needed current value).

More useful information about MOSFETs can be found here: https://electronics.stackexchange.com/questions/29065/how-to-control-a-12v-solenoid-valve-with-a-mosfet

Yes, a MOSFET should work just fine. As others have said in the comments, you just need to make sure that it's rated for your desired voltage and current, and that it's threshold voltage is low enough (around 2.5V) that the Arduino is able to drive it to saturation with a logic level 1 (5V).
I've used this one (rated at 60V and 30A) in various projects:
https://www.sparkfun.com/products/10213


text:
I think I just bricked my Arduino. Any ideas how?
I think I have a short circuit in my Arduino Uno R3. The symptoms are:

It does not seem to be responding as before.
The orange "L" LED does not blink on boot-up, but just stays on continuously.
If I plug in a 12V source, then the voltage between the 5V and GND pins starts out around 5V, but then starts dropping rapidly. In the meantime, the underside of the board heats up a lot. If I plug in the USB source, the voltage between the 5V and GND pins stabilizes at around 4.28V ... but again, nothing seems to work.
After all this, I also checked continuity between the 5V and GND pins, and heard a beep. However, subsequent reading told me that this is not a reliable (or well-advised) test.

It seems like I have a short on my Arduino, right?  Any idea of how this could have happened?  I can only think of the following possibilities:

I was running the Arduino off a lead-acid 12V battery. At some point, the negative terminal wire disconnected and there was some sparking at the battery when I reconnected it (the pattery was also powering other things). Could this have damaged the Arduino?
I am using the Arduino to run 3 IR LED . To minimize wiring, I had wires these LED in series, rather than in parallel, which (at least at first) seemed to work. Is there any possibility this would have damaged it?

Thanks for any help.

Did these 3x IR LEDs have current limiting resistors?

Yes, there was one resistor in series with them.

the pattery was also powering other things - what other things?

A couple of video projectors, drawing about 4.5 amps total.

See my answer here. A 12V battery doesn't necessarily provide you with 12V any more than a 1.5V battery provides 1.5V.
See here for example. A 12V lead-acid battery may well provide 12.7V which is out of spec for the Uno.
See the page about the Uno.
You have too much voltage going into the voltage regulator, it tries to dissipate it, it gets hot and either shuts down or fails.
I suggested in the answer above to use a buck converter to down-convert the voltage, and my answer (which was accepted) said that "it is working like butter".

"Working like butter" is an idiom I have never come across before. How does butter work?

Smoothly. Like butter spreading on a nice warm piece of toast, where you have the marmalade ready to go on top. :)

I don't eat toast... too many carbs...

https://www.urbandictionary.com/define.php?term=like%20butter

The voltage limits for the Arduino are 6-20V. I know that 12V is max "recommended" but I thought the issue was heating (I'm running very few watts through the things, so I don't think it should be an issue normally).

See my answer about have I bricked my Arduino.

@NickGammon Thanks for the pointer to your other answer -- that is a great resource! I will keep in mind those diagnostics, though probably I won't use them now as my Arduino seems so obviously toast (L light doesn't blink, just starts getting hot when plugged into either 12V or USB power, etc.)

Nonetheless, I am still confused by the situation I encountered. All specs I have found for Arduino Uno R3 say 20V is the max (not 12V), and I previously ran it without problems for many hours off the Lead Acid battery. I'm trying to understand what happened. I suspect there might have been a large voltage spike when connecting to the battery, but I don't know if that something that actually happens. In any case, when rebuilding I will definitely add a buck converter .

If I plug in a 12V source, then the voltage between the 5V and GND pins starts out around 5V, but then starts dropping rapidly. In the meantime, the underside of the board heats up a lot. If I plug in the USB source, the voltage between the 5V and GND pins stabilizes at around 4.28V ... but again, nothing seems to work.

That sounds like the LDO is overheating and going into thermal shutdown.

After all this, I also checked continuity between the 5V and GND pins, and heard a beep. However, subsequent reading told me that this is not a reliable (or well-advised) test.

If it's just a brief "pip" then it's just a capacitor charging or discharging. To qualify as a short it has to be a continuous "beeeeeeeeeeeeeeeeeeeeeee".

I was running the Arduino off a lead-acid 12V battery. At some point, the negative terminal wire disconnected and there was some sparking at the battery when I reconnected it (the pattery was also powering other things). Could this have damaged the Arduino?

It sure could. If other things are connected both to the battery -ve and the Arduino then the power could have passed through the Arduino in many strange ways killing things internally.
Chances are it's dead, yes. It may just be the main MCU which (if it's a DIP version) you could pop off and replace (with one with the bootloader already installed). But there's no guarantee it's only that chip that's gone. The USB chips are also a common failure point, especially the cheap Chinese CH340G.
In the long run it's safer just to replace the entire board unless you've got plenty of spare components and the skills to diagnose and replace them as needed.

Thanks! It was definitely beeeeeeeeeeeeeeee-type continuity. Can you elaborate "If other things are connected both to the battery -ve and the Arduino then the power could have passed through the Arduino in many strange ways killing things internally."? I have a large 12V battery powering the Arduino, plus some projectors (drawing about 5 amps) which run running through a relay on the Arduino. Is this a dangerous setup?

It sounds safe enough, but without seeing a full schematic I can't really say for sure.

If you have the Arduino connected to ground but not 5V, but other things are connected to 5V, then power can be fed into GPIO lines on the unpowered Arduino, whicih is bad. Similarly, when you did connect the battery and saw a spark you might have sent a spike into places a spike should not go. (Which is pretty much everywhere. The voltage regulator is only designed for 12V max, if memory serves, so pushing more than that into it might have fried it.)

Thanks for the suggestions. The voltage regulator is designed for 20V max. Is there a voltage spike that occurs when a battery sparks?


text:
Voice receiver arduino
I have the following situation.
    I would like to develop a bracelet prototype that identifies when a person is on the go and also issue a question to the person for that bracelet and get an answer, depending on the status of the response by sending a notification to a mobile app. I am interested in what Arduino technologies to use.

Do you talk about speech recognition?

that's right...

You won't do that with an Arduino. There are VR and sound playing modules that you can add to Arduino, but they're crude and bulky. You won't want that in a bracelet.  You would be better looking at the K210 and MicroPython instead.

I see, but if you were using arduino, can you tell me which components would be needed?

I only want one prototype for my course work.

Some voice recognition module (which one depends on how you want it to work). Some audio playback module (which one depends on what you want to play back). Some device that will tell you if you are "on the go" (what that is depends on your definition of "on the go"). Some device that will communicate with your mobile app (which one depends on how you want to communicate). And of course an Arduino that can coordinate the whole lot.

Is there any component to check if the body is moving?

An AVR-based Arduino is woefully underpowered for something like this. It has an 8 or 16 mHz 8 bit processor without hardware floating-point support. They are too slow, have too little memory, and too little I/O bandwidth. There are some ARM based Arduino compatible boards that might be a decent foundation for something like this, but you should probably look at using a Raspberry Pi or other platform instead.

The K210 dual core 400MHz RISC-V with embedded AI processor is really what you want. You can get them as "MAix BiT" boards with MicroPython installed on them. Easy to program (if you like Python...) and does voice recognition natively. I guess they can do audio playback too if you have a DAC attached. We can't help you with them though since they're neither Arduino hardware nor using Arduino software (though there is Maixduino to allow you to program using the Arduino IDE...)

Isn't the Sparkfun EasyVR 3 Plus Shield exactly what you want? https://www.youtube.com/watch?v=z5Fgraby1Rk

@MaximilianGerhardt That's fine for doing the VR side of things if an Arduino is chosen, but like I said... bulky... and prototyping bulky with no prospect of shrinking it (how would you shrink that?!) is not good. Start small (though on a big board) and go from there. A MAix BiT module with built in ESP8266 could be good (if WiFi is wanted) for the final product, and a MAix BiT board for prototyping.

Instead of letting the end concept run the project into the ground due to extreme complexity, why not consider alternative user interfaces better suited for an Arduino.  OTOH, consider almost any Android phone contains the hardware you are looking for (accelerometer, microphone, speaker) and would be much smaller than an Arduino with a battery and a few shield boards mounted on it.

@DarlanCandiotto, would you be interested in a solution that does not involve voice recognition or speech play back?


text:
First time using Kuman 3.5" TFT screen model SC3A-NEW-UK with Arduino
I bought online this LCD Touchscreen Kuman SC3A-NEW-UK. It uses ILI9486 drivers, but it didn't include any instructions manual, and kumantech.com seems to be devoid of complete technical documentation about SC3A-NEW-UK model.
I am trying to figure out:

Which are the minimum connections I have to make between Arduino UNO and the LCD screen.
Which "Arduino's C++" (AKA G++ ?) library I need to use in order to display stuff programatically

To summarize
Just in case it wasn't noticable: I am trying to make a "Hello World" for my SC3A-NEW-UK's LCD Touchscreen from an Arduino UNO board. In other words: just print "Hello World" to see if it works.
What I tried so far
Searching on the Internet wasn't enough. Searching "ILI9486" on Google led me to this Github project:
https://github.com/schreibfaul1/ESP32-TFT-Library-ILI9486
To see if I can use it, I tried downloading a whole ZIP from this Github project, and inside the Arduino IDE, I tried adding the downloaded library using the option "Include .ZIP library". If I copy-paste the code example provided within README.md (the following) and compile:
#include "Arduino.h"
#include "SPI.h"
#include "tft.h"

// defaults can be changed in tft.begin
// CS=22, DC=21, MOSI=23, MISO=19, SCK=18

TFT tft;
//-------------------------------------------------------------------------------------
void setup() {
    SPI.begin();
    tft.begin();
    tft.setRotation(1); //landscape
    tft.fillScreen(TFT_BLACK);
    tft.setFont(Garamond34x42);
    tft.setTextColor(TFT_CYAN);
    tft.setCursor(20,30);
    tft.print("Hello World!");
}
//-------------------------------------------------------------------------------------
void loop(void) {
    for(uint8_t rotation=0; rotation<4; rotation++) {
        tft.setRotation(rotation);
        tft.fillScreen(TFT_BLACK);
        tft.setCursor(20,30);
        tft.print("Hello World!");
        delay(3000);
    }
}
//-------------------------------------------------------------------------------------

...it results in this compile error:
In file included from C:\Users\MyUser\ArduinoProjects\test_external_library\test_external_library.ino:3:0:

C:\Users\MyUser\Documents\Arduino\libraries\Arduino-TFT-Library-ILI9486-master\src/tft.h:5:16: fatal error: FS.h: No such file or directory

compilation terminated.

exit status 1
Error compiling for board Arduino/Genuino Uno.

Line 5 at tft.h says:
#include "FS.h"

...and I have no idea what this FS library is supposed to be, so I don't think I can use that Github project at all... I am tempted to assume that Github's project is dead.
So, perhaps I am fine just using the IDES's built-in TFT library, perhaps like this? I don't know...:
#include <SPI.h>
#include <TFT.h>
#define CS   10
#define DC   9
#define RESET  8

#define TFT_CYAN    0x07FF
#define TFT_BLACK   0x0000

// Initialization inspired in code example found at
// https://www.arduino.cc/en/Guide/TFT
TFT tft = TFT(CS, DC, RESET);
int dummy_second_cnt = 0;

void setup() {
    // I don't know what's SPI for, anyway...
    // just found it in the code example present at GitHub's library's README.md
    // ...(which I am not trying to use at this point, so it's useless in this code example... commented-out for reference, just in case)
    //SPI.begin();

    tft.begin();
    tft.background(0,0,0);
    tft.setRotation(1);
    tft.fillScreen(TFT_BLACK);
    tft.setTextColor(TFT_CYAN);
    tft.setCursor(20,30);
    tft.print("Hello LCD Screen");

    delay(3000);
}

void loop() {
    tft.fillScreen(TFT_BLACK);
    tft.setCursor(20,30);
    tft.print("Seconds: ");
    tft.print(dummy_second_cnt);
    dummy_second_cnt++;
    delay(1000);
}

This compiled in Arduino IDE, no problem, but I still don't know if it will work well with my screen. I am also confused about initialization of the TFT object and how would I have to wire the LCD screen to the Arduino depending on this initialization:
TFT tft = TFT(CS, DC, RESET);

...i mean, my LCD screen has CS and RESET pins, but what is DC supposed to be here? (in this context, I don't think it stands for "Direct Current"... but there's no DC pin reference in my LCD screen written "AS IS"... ?? This brings me more confusion...
...specially having in mind that I don't know how am I supposed to wire the LCD screen to the Arduino yet. It seems the LCD pins have been designed to fit in directly to the Arduino board without thinking too much about it (like the shape is the same), but that would make the screen getting all the Arduino UNO's pins for itself, so I don't think so...
These are the LCD_* pins present at my LCD screen:

LCD_RST (Reset I guess)
LCD_CS
LCD_RS
LCD_WR (Write I guess)
LCD_RD (Read I guess)

(and the following I guess are 8-bit digital pins):

LCD_D0
LCD_D1
LCD_D2
LCD_D3
LCD_D4
LCD_D5
LCD_D6
LCD_D7

It also has 5V, 3V3 and GND pins (Which I guess are for power)
...so, powering the screen shouldn't be a big deal, but, how am I supposed to connect everything else? I am completely misguided about how am I supposed to interact with the screen from Arduino code... what is RS pin for? Should I use 4-bit or 8-bit mode? (I think 4-bit would imply connecting 4 digital pins for the screen, and 8-bit the whole 8 pins from screen to the Arduino UNO board)? Should I use LCD_RD and LCD_WR? Well you have a picture of my confusion.
Searching for documentation in the internet only leads me to partial examples. Not even using the model Ref ( SC3A-NEW-UK ) or the driver's ref ( ILI9486 ) as keywords for searching in Google leads me to clear documentation about howto wire stuff, or which specific libraries should I use...
Even though I know how to control Input/Output in Arduino code to interact with analog/digital input and output pins at will with C++ in Arduino code (but even so, I think I'm still an Arduino n00b), this LCD screen's physical interface is very confusing to me...
Can you help me to overcome this confusion, please? I'd rather have my mind clear before making any physical wiring and fry something...
PD: I have read somewhere that this SC3A-NEW-UK Touchscreen is made to shield Arduino MEGA boards (by fitting the PINs directly into it), but mine is an Arduino UNO Board! (perhaps I shouldn't have bought This LCD model, then?)... but I have sets of wires, pinboards and stuff... I don't want to give up the idea of harnessing this LCD screen using an Arduino UNO. I don't care about shielding feature, I just want to wire it and make it work. I will figure out how to shield electronics later on.

EDIT:
Based on VE7JRO's answer, I managed to map the connections by seeing where the connections would go if I just fit the connections shielding the Arduino UNO, the way VE7JRO suggested:
+--------------+------------------+
| Arduino UNO  |    LCD Screen    |
+--------------+------------------+
|     GND      |        GND       |
+--------------+------------------+
|      5V      |         5V       |
+--------------+------------------+
|     3.3V     |       3.3V       |
+--------------+------------------+
|      A0      |      LCD_RD      |
+--------------+------------------+
|      A1      |      LCD_WR      |
+--------------+------------------+
|      A2      |      LCD_RS      |
+--------------+------------------+
|      A3      |      LCD_CS      |
+--------------+------------------+
|      A4      |      LCD_RST     |
+--------------+------------------+
|      A5      |       NONE       |
+--------------+------------------+
|       8      |      LCD_D0      |
+--------------+------------------+
|       9      |      LCD_D1      |
+--------------+------------------+
|    2 TO 7    | LCD_D2 TO LCD_D7 |
+--------------+------------------+
|      10      |       SD_SS      |
+--------------+------------------+
|      11      |       SD_DI      |
+--------------+------------------+
|      12      |       SD_DO      |
+--------------+------------------+
|      13      |      SD_SCK      |
+--------------+------------------+

I put NONE for A5 input, because that pin of LCD screen doesn't have any name on it. There are another ones without name as well, that I didn't include in this table. I believe (perhaps I'm wrong believing it, I don't know) that those pins without name have no use.
The bad thing about this layout is that it consumes almost all the Arduino pins, so I would not be able to attach additional circuits. However, perhaps I should not be worrying about earning connections yet, before testing the screen.
I still don't know much of the details about what pins do what for the screen, but I have read somewhere that LCD_D0 to LCD_D7 are meant to receive digital data in some kind of 8-bit parallel mode. But I also heard that there is a 4-bit mode. If I could use that mode with this screen, I would be able to have 4 free digital pins for anything else...
Ok, I got the connections mapped. Next step would be trying those three libraries that VE7JRO suggested.

EDIT2:
I tested VE7JRO's code. LCD Screen did draw the interface as expected. But buttons didn't respond. I found out the code sample needs further calibration.
So, I started printing through the Serial the coordinates of the object TSPoint p, to find out if there was something wrong with the z coordinate. And indeed, there was: setting MINPRESSURE and MAXPRESSURE according to what I saw in Serial Monitor while I pressed and I didn't pressed, fixed this. However, there's another more issue...
...when I tell Serial to print if the boolean operation down && on_btn.contains(pixel_x, pixel_y) results in either true or false, it prints it is false... while I am touching ON button. down is true for sure (after I calibrated MINPRESSURE and MAXPRESSURE constants); so that must mean on_btn.contains(pixel_x, pixel_y) is returning false for some reason. If I figure out why, I will be able to accomplish that the ON Button does what it's supposed to when I press it. And that will mean I will have completed calibration process. I would bet perhaps pixel_x and pixel_y need calibration as I already did with pressure detection based on z; or perhaps contains method is not reliable and I have to figure out some other methodology... I will tell you after I try
All stroken through is based on assumption that Z is depth, and Y is height; Actually, it seems to be the other way around...
After somemore trial-and-error research, it seems that Z is height, and Y is depth (at least within the TSPoint object's properties x, y and z, which values seem way more reliable than the pixel_x and pixel_y values, which purpose seems to be if the pixel is contained in the button's squares and nothing else)... I still don't get why is there the need to use this within the function Touch_getXY(void):
if (pressed) {
    pixel_x = map(p.x, TS_LEFT, TS_RT, 0, tft.width()); //.kbv makes sense to me
    pixel_y = map(p.y, TS_TOP, TS_BOT, 0, tft.height());
}

...because their values when I touch the screen with the touchpen are very weird. I tried to guess which ranges they go, and they don't make sense when I move around the screen. Perhaps it's because this strange "Z instead of Y" mapping from the TSPoint object. Perhaps pixel_x and pixel_y don't need to make an intuitive sense, perhaps it's just some intrincated in-bound logic that only makes sense within electronics' low-level scope, or within Adafruit_GFX_Button.press method, I don't know... but x, y and z readings from TSPoint object seem very accurate, despite Y being Z and Z being Y...
...perhaps reading any documentation I can find about Adafruit_GFX_Button class, its properties and methods (specially contains) will lead me to comprehend clearly what's wrong...
...also, it might be time to focus on searching those test sketches that VE7JRO talked me about:

There are 22 test sketches that come with the MCUFRIEND_kbv library. One of them scans your display and outputs configuration information (sorry, it's been a while since I tested my screen). Another sketch will draw little boxes in each corner and sides. This is used to get the x y coordinates of the edges of your particular screen (it might be called TouchScreen_Calibr_native.ino).

EDIT3
X is Y? Y is Z? Z is X? I don't know what to think anymore! The last I tried, changing the formula for pixel_x and pixel_y to:
pixel_x = map(p.x, 1023, 0, 0, tft.width());
pixel_y = map(p.y, 1023, 0, 0, tft.height());

...and the constants for the pins:
const int XP = 6, XM = A2, YP = A1, YM = 7;

This seems to make z the pressure axis within TSPoint object, but ends up in strange behaviours:

x seems numb (no matter if I press the touchscreen with touchpen or not, neither it's position: it always prints 65 to 70!
z seems indeed sensitive to touch pressure, but it's like its sensitivity is different depending on the touchpen's position on screen (altough I'm not a robot, I think I was using more or less the same amount of force with my hand). It prints 0 when i do not touch the screen.
y seems sensible to both horizontal and vertical position at the same time! This blows my head.

I don't know what to think anymore...

Did I short-circuit something for not paying attention to the script's constants in my previous tests?
Was the screen broken from the begginning?
Is it a calibration error with values in the script?
Might the libraries I am using be broken, or have some kind of bug with my TFT?

This is becoming overwhelmingly more difficult than I thought...
...according to some article I found(in Spanish, sorry), the Touchscreen's initialization's params:
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

XP is supposed to be the pin for LCD_D6: 6 in the Arduino.
YP is supposed to be the pin for LCD_WR: A1 in the Arduino.
XM is supposed to be the pin for LCD_RS: A2 in the Arduino.
YM is supposed to be the pin for LCD_D7: 7 in the Arduino.
The fifth parameter is supposed to be the resistance measured between LCD_D6 and LCD_RS with the screen unplugged. Unfortunately, my multimeter can't measure it for some reason (I put it in 2000 Ohms mode for reading resistance: I always get '1', the same than when I don't connect anything... like if multimeter's contacts aren't working well, I don't know)... so I left the default 300 value.

I did initializate it well, as far as I know... except the fifth parameter. Would a wrong resistence value make such a big difference in calibration, up to the point this strange behaviours I have seen do happen?
Damn, I am so close... what am I doing wrong?

Well, I suceeded compiling @VE7JRO♦ 's code example. Could I just plug the screen shielding the Arduino, load the sketch into the Arduino, and test it right away? Or perhaps it requires a bit more preparations (like resistances or other stuff)? Perhaps should I check the constants for the PINs match my screen before loading the sketch and power everything up?

One more thing. This is the first time I'm gonnna test sketches in a physical Arduino. I have done some scripts in a simulator similar to the one in tinkercad.com (this one doesn't let you write the code for Arduino simulation, but lets you sketch some logic with a WYSIWYG interface, and retrieve the code later; there was another as good for electronic simulation years ago on the web, but it seems it's not anymore), but first time I'm gonna plug a real Arduino. If I have the Smart USB serial connected to my computer, do I need the 220AC-DC power unit for testing, or rather not?

Well, about the powering while testing stuff: I have read at some forum website, that Arduino's electronics are smart enough to choose which power source to use (either Smart USB or AC converter) by itself. So it can use Smart USB as power source... idk if that power will be enough to power as well the LCD screen, but in case it's not, I guess I can add extra power plugging in the AC Power Unit (but perhaps it's not that simple; specially having in mind the overheating issue)...

Perhaps I should stop overthinking it,  just plug the screen in, load the compiled code and see what happens? I think I am hesitating too much...

What I said about tinkercad.com didn't let you write the script, was wrong. At first it shows the annoying begginner-friendly WYSIWYG logic, but there was an option to switch to scripting mode. Wow, actually tinkercad.com has an awesome electronics/Arduino simulator...

Which are the minimum connections I have to make between Arduino UNO
  and the LCD screen.

The TFT screen plugs right on top of your Arduino Uno. I have a "cheaper" model with the same size screen and identical pins as your screen (exact same text printed beside the pins).
Before you plug it in, I have a few pieces of advise.

It's possible to install the screen one or 2 pins "out of proper
alignment", so plug it in before you apply power. Verify the correct
pins are in the correct "holes", using the location of the 5V,
3V3 and GND pins as a guide.
This screen used lots of power, especially when you are using a test
sketch that turns all the pixels on / off and cycles through various
graphics / text output to the screen. My Uno's voltage regulator was
getting pretty warm after 10 minutes, and I was suppling it with 8
VDC to the barrel jack power input. Using a 12 VDC supply would
exacerbate the heat issue, so please be careful.

Which "Arduino's C++" (AKA G++ ?) library I need to use in order to
  display stuff programatically?

I used the MCUFRIEND_kbv library, Adafruit_GFX library and the Adafruit TouchScreen library, all available in the Arduino IDE Library manager.
There are 22 test sketches that come with the MCUFRIEND_kbv library. One of them scans your display and outputs configuration information (sorry, it's been a while since I tested my screen). Another sketch will draw little boxes in each corner and sides. This is used to get the x y coordinates of the edges of your particular screen (it might be called TouchScreen_Calibr_native.ino).
Getting the screen to display anything is step 1. Step 2 is to calibrate the edges of the screen. Step 3 is to get the touch screen part of it to work.
Here is a sketch I used to test the screen by changing the color of a "box". Touching each of the 2 buttons on the screen changes the "box" color. I've left in all the config data I saved (see the end of this sketch). Your screen is different than mine, so running the test sketches from the library first is where I would start.
// SEE BOTTOM OF SKETCH FOR MORE DATA / test results.
#include <Adafruit_GFX.h>
#include <MCUFRIEND_kbv.h>
MCUFRIEND_kbv tft;
#include <TouchScreen.h>
#define MINPRESSURE 200
#define MAXPRESSURE 1000

// ALL Touch panels and wiring is DIFFERENT
// copy-paste results from TouchScreen_Calibr_native.ino
// OEM: const int XP = 6, XM = A2, YP = A1, YM = 7; //ID=0x9341
// OEM: const int TS_LEFT = 907, TS_RT = 136, TS_TOP = 942, TS_BOT = 139;
// MINE - WORKS.
const int XP = 7, XM = A1, YP = A2, YM = 6; //320x480 ID=0x9488
const int TS_LEFT = 929, TS_RT = 204, TS_TOP = 963, TS_BOT = 213;

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

Adafruit_GFX_Button on_btn, off_btn;

int pixel_x, pixel_y;     //Touch_getXY() updates global vars
bool Touch_getXY(void)
{
    TSPoint p = ts.getPoint();
    pinMode(YP, OUTPUT);      //restore shared pins
    pinMode(XM, OUTPUT);
    digitalWrite(YP, HIGH);   //because TFT control pins
    digitalWrite(XM, HIGH);
    bool pressed = (p.z > MINPRESSURE && p.z < MAXPRESSURE);
    if (pressed) {
        pixel_x = map(p.x, TS_LEFT, TS_RT, 0, tft.width()); //.kbv makes sense to me
        pixel_y = map(p.y, TS_TOP, TS_BOT, 0, tft.height());
    }
    return pressed;
}

#define BLACK   0x0000
#define BLUE    0x001F
#define RED     0xF800
#define GREEN   0x07E0
#define CYAN    0x07FF
#define MAGENTA 0xF81F
#define YELLOW  0xFFE0
#define WHITE   0xFFFF

void setup(void)
{
    Serial.begin(9600);
    uint16_t ID = tft.readID();
    Serial.print("TFT ID = 0x");
    Serial.println(ID, HEX);
    Serial.println("Calibrate for your Touch Panel");
    if (ID == 0xD3D3) ID = 0x9486; // write-only shield
    tft.begin(ID);
    tft.setRotation(0);            //PORTRAIT
    tft.fillScreen(BLACK);
    on_btn.initButton(&tft,  60, 200, 100, 40, WHITE, CYAN, BLACK, "ON", 2);
    off_btn.initButton(&tft, 180, 200, 100, 40, WHITE, CYAN, BLACK, "OFF", 2);
    on_btn.drawButton(false);
    off_btn.drawButton(false);
    tft.fillRect(40, 80, 160, 80, RED);
}

/* two buttons are quite simple
 */
void loop(void)
{
    bool down = Touch_getXY();
    on_btn.press(down && on_btn.contains(pixel_x, pixel_y));
    off_btn.press(down && off_btn.contains(pixel_x, pixel_y));
    if (on_btn.justReleased())
        on_btn.drawButton();
    if (off_btn.justReleased())
        off_btn.drawButton();
    if (on_btn.justPressed()) {
        on_btn.drawButton(true);
        tft.fillRect(40, 80, 160, 80, GREEN);
    }
    if (off_btn.justPressed()) {
        off_btn.drawButton(true);
        tft.fillRect(40, 80, 160, 80, RED);
    }
}

/*
Read Registers on MCUFRIEND UNO shield
controllers either read as single 16-bit
e.g. the ID is at readReg(0)
or as a sequence of 8-bit values
in special locations (first is dummy)

reg(0x0000) 00 00  ID: ILI9320, ILI9325, ILI9335, ...
reg(0x0004) 00 54 80 66 Manufacturer ID
reg(0x0009) 00 00 61 00 00  Status Register
reg(0x000A) 00 08 Get Power Mode
reg(0x000C) 00 06 Get Pixel Format
reg(0x0061) 00 00 RDID1 HX8347-G
reg(0x0062) 00 00 RDID2 HX8347-G
reg(0x0063) 00 00 RDID3 HX8347-G
reg(0x0064) 00 00 RDID1 HX8347-A
reg(0x0065) 00 00 RDID2 HX8347-A
reg(0x0066) 00 00 RDID3 HX8347-A
reg(0x0067) 00 00 RDID Himax HX8347-A
reg(0x0070) 00 00 Panel Himax HX8347-A
reg(0x00A1) 00 93 30 93 30  RD_DDB SSD1963
reg(0x00B0) 00 00 RGB Interface Signal Control
reg(0x00B4) 00 02 Inversion Control
reg(0x00B6) 00 02 02 3B 3B  Display Control
reg(0x00B7) 00 06 Entry Mode Set
reg(0x00BF) 00 00 00 00 00 00 ILI9481, HX8357-B
reg(0x00C0) 00 0E 0E 0E 0E 0E 0E 0E 0E  Panel Control
reg(0x00C8) 00 B0 B0 B0 B0 B0 B0 B0 B0 B0 B0 B0 B0  GAMMA
reg(0x00CC) 00 03 Panel Control
reg(0x00D0) 00 00 00  Power Control
reg(0x00D2) 00 00 00 00 05  NVM Read
reg(0x00D3) 00 00 94 88 ILI9341, ILI9488
reg(0x00D4) 00 97 00 00 Novatek ID
reg(0x00DA) 00 54 RDID1
reg(0x00DB) 00 80 RDID2
reg(0x00DC) 00 66 RDID3
reg(0x00E0) 00 00 07 0C 05 13 09 36 AA 46 09 10 0D 1A 1E 0F GAMMA-P
reg(0x00E1) 00 00 20 23 04 10 06 37 56 49 04 0C 0A 33 37 0F GAMMA-N
reg(0x00EF) 00 00 00 00 00 00 ILI9327
reg(0x00F2) 00 58 04 12 02 22 22 FF 0A 90 14 88 Adjust Control 2
reg(0x00F6) 00 00 00 00 Interface Control

-----

TouchScreen.h GFX Calibration
Making all control and bus pins INPUT_PULLUP
Typical 30k Analog pullup with corresponding pin
would read low when digital is written LOW
e.g. reads ~25 for 300R X direction
e.g. reads ~30 for 500R Y direction

Testing : (A1, D7) = 23
Testing : (A2, D6) = 34
Diagnosing as:-
XM,XP:  (A1, D7) = 23
YP,YM:  (A2, D6) = 34
ID = 0x9488

cx=904 cy=951 cz=418 LEFT, TOP, Pressure
cx=907 cy=584 cz=535 LEFT, MIDH, Pressure
cx=910 cy=229 cz=504 LEFT, BOT, Pressure
cx=554 cy=948 cz=608 MIDW, TOP, Pressure
cx=563 cy=230 cz=674 MIDW, BOT, Pressure
cx=228 cy=947 cz=946 RT, TOP, Pressure
cx=228 cy=583 cz=1038 RT, MIDH, Pressure
cx=225 cy=230 cz=929 RT, BOT, Pressure
MCUFRIEND_kbv ID=0x9488  320 x 480

const int XP=7,XM=A1,YP=A2,YM=6; //320x480 ID=0x9488
const int TS_LEFT=929,TS_RT=204,TS_TOP=963,TS_BOT=213;
PORTRAIT CALIBRATION     320 x 480
x = map(p.x, LEFT=929, RT=204, 0, 320)
y = map(p.y, TOP=963, BOT=213, 0, 480)
Touch Pin Wiring XP=7 XM=A1 YP=A2 YM=6
LANDSCAPE CALIBRATION    480 x 320
x = map(p.y, LEFT=963, RT=213, 0, 480)
y = map(p.x, TOP=204, BOT=929, 0, 320)
*/

Well, I did test the program... the screen works, nice! It draws the ON and OFF buttons and a red rectangle. Looking closer to your code, it seems that buttons ON/OFF are supposed to draw GREEN/RED rectangles respectively. I tried it out (taking off the plastic protector first) even with the plastic pen, it didn't work for some reason...

...from the Serial Monitor, I got: TFT ID = 0x9486  Calibrate for your Touch Panel

...the more I try, the more confused I get. I have been tweaking variables here and there in your script, hoping to be able to calibrate everything up. But the results I get from Serial Monitor are too weird in any experiment I try, it blows my imagination. I though I would succeed with exhaustive trial-and-error, but no... do I actually need to compile and execute TouchScreen_Calibr_native.ino to get the correct constants?

I am seriously thinking on opening another question for the Touchscreen sensors issue (see EDIT3 in my question)... to give it a more focused approach...

You sound very much the same as me when I got this screen, it took me a while,
There is one of 'Dronebot's sessions on Youtube where he is connecting this screen which may get you started. I got drivers and information on lcdwiki.com with examples in the library folder.
I believe you get either a Uno to Mega version of this screen as the pinout is different for each, if you have the box for the screen, under the bar code it has the item description tell you which version you have.Uno or Mega.
On the lcdwiki site you'll find drivers for  both under the pics of each screen and for  of loads of  other screens LCD OLED and TFT's.
there is in the library folder when you download /install a fair few examples to have a play with and get the hang of this
DRONEBOT, and LCDWIKI sites have a fair bit of info and both worth a visit.
As of yet I can't get any of Adafruits examples going because of driver differences