body:
I have been tying to print an element of a list with the same position as the number that it matches, but it does not seem to work and I can not figure out if I made some mistake, could someone please check it? Would really appreciate it

Here are the list declarations:

    int names[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
    char *users[10] = {"Josh", "John", "Frederic", "Mikael", "Anthony", "Charles", "Tom", "Chris", "Steve", "Mike" };

And this is what I am using to print the name I need:

    if (attempt != FINGERPRINT_OK) return -1;
 Serial.println ("Belongs to: ");
 if(data.fingerID == names[n]) {
  Serial.print(users[n]);
 }

Complete Code:

    #include <Adafruit_Fingerprint.h>
    #include <SoftwareSerial.h>

    SoftwareSerial mySerial(2, 3);
    pinMode (12, OUTPUT);
    pinMode (13, OUTPUT);

    Adafruit_Fingerprint data = Adafruit_Fingerprint(&mySerial);

    int names[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
    char *users[10] = {"Josh", "John", "Frederic", "Mikael", "Anthony",
    "Charles", "Tom", "Chris", "Steve", "Mike" };

    void setup() {
      Serial.begin(9600);
      while (!Serial);
      data.begin(57600);
      if (data.verifyPassword()) {
       Serial.println("Verified connection");
    }

      else {
     Serial.println("Unnable to verify connection, try again");
     while (1) { delay(2500); }
    }

    data.getTemplateCount();
    Serial.print("Waiting for one of the:"); Serial.print(data.templateCount);
    Serial.println("valid fingerprint");

    int getFingerprintIDez();
    uint8_t getFingerprintID();

    void loop() {
    for ( int i = 0; i <= 10; i++) {
     uint8_t attempt = data.getImage();
      switch (attempt) {
       case FINGERPRINT_OK:
       break;
     delay (2500);
    }

    attempt = data.image2Tz();
      switch (attempt) {
        case FINGERPRINT_OK:
          Serial.println("Image converted");
        break;
        case FINGERPRINT_IMAGEMESS:
          Serial.println("Image too messy");
        return attempt;
      }

     attempt = data.fingerFastSearch();
       if (attempt == FINGERPRINT_OK) {
        Serial.println("Found a print match!");
        digitalWrite (13, HIGH);
        delay(1250 );
        digitalWrite (13, LOW);
      }
       else if (attempt == FINGERPRINT_NOTFOUND) {
    Serial.println("Did not find a match");
    digitalWrite (12, HIGH);
    delay(1250 );
    digitalWrite (12, LOW);
    return attempt;
      }
    Serial.print("Found ID #"); Serial.print(data.fingerID);
    Serial.print(" with confidence of "); Serial.println(data.confidence);
    return data.fingerID;

    uint8_t attempt2 = data.getImage();
    if (attempt2 != FINGERPRINT_OK) return -1;
  attempt2 = data.image2Tz();
    if (attempt2 != FINGERPRINT_OK) return -1;
  attempt2 = data.fingerFastSearch();
    if (attempt2 != FINGERPRINT_OK) return -1;
  Serial.println ("Presents: ");
 if(data.fingerID == names[n]) {
  Serial.print(users[n]);
 }
    }
    }

I am attempting that when a fingerprint is verified, the position that matches it out of all the stored fingerprints gets stored as n so I can later print the name asigned to that same position. Thanks

title: Can not print an element in an specific position in an arduino list

Answers: 1

body:
How about you completely delete

    int names[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };

and instead do:

    if (attempt != FINGERPRINT_OK)
        return -1;

    Serial.println ("Belongs to: ");
    Serial.print(users[data.fingerID - 1]);


body:
I'm trying to call a class function that pulses an LED "x" number of times. I dont want to use a delay, which is making it tough. If I use a while loop, the LED just stays on. I attach an interrupt in the `begin()` - the location of the LED is pin `13`

I call the following in my sketch like so:

    robot.lights.pulse(0, 2000, 10000, 500); //in milliseconds

My goal is to pulse an LED "x" number of time at a rate I specify.

This is the code inside my class:

    void StatusLights::begin(int locations[]){
        for(int i=0;i<NUM_OF_LIGHTS;i++){
      this->locations[i]=locations[i];
      pinMode(locations[i], OUTPUT);
     }

        ledState = LOW;
        previousMillis = 0;
        attachInterrupt(0, pulse_ISR, RISING);

    };

    void StatusLights::pulse(int location, int interval, int count, int speed){

        int value = 0;
        previousMillis = 0;
        // while(pulsecnt<count) {
            long currentMillis = millis();

            if (currentMillis - previousMillis >= interval) {
                previousMillis = currentMillis;
                value = 128+127*cos(2*PI/interval*(speed-currentMillis));
                analogWrite(locations[location], value);
            };
        // };
        // digitalWrite(locations[location], LOW);
    };

    void pulse_ISR() {
        pulsecnt++;
    };

This is my first time using interrupts to do this - I'm really trying to avoid delays since i need other things to happen synchronously.

Thanks!

title: Trying to Pulse an LED a number of times outside of the main loop

Answers: 1

body:
You'll want a class function that decides whether 'now' is time to toggle the LED or not, and returns quickly. Call that function frequently from your loop function. Your other class functions will set or clear the whether the LED is to toggled, and when, how many times, etc.  Something like the following pseudo-code, which is not a full solution but should point out the essential details:

    void loop()
    {
       myStatusLights.updateLED();     // call this frequently
    }

    ...

    void StatusLights::updateLED(){
      if LED_active,
         if it's time to change the LED,
            toggle LED on/off;
            if LED has toggled enough times,
               set LED_active false;
            endif;
         endif;
      endif;
    }

Update:

>How would you refresh the count, track the pulses, and refresh the state of the status light without any parameters?

Some class-function must initiate the blinking, whether it knows to do it itself or it is called from your application code. That class-function will need to set those parameters. If it to be called from outside, perhaps the outside sets them - ? Only you know that. Either way, they will need to get saved in the class' private data so the .updateLED() function can have access to them. The .updateLED() function will, for instance, count down the remaining number blinks to display, keep track of whether the LED is on or off, actually turn it on or off, etc., until there is nothing left for it to do. In that case it just quickly returns without doing anything.


body: I have a problem with connecting my NodeMcu to gsm. I have bought GSM module but I have sim code on card which I can't and that is the problem because I've found some libraries but there are no examples how to connect with pin code. I have found one but not compatible with NodeMcu. How can I do It?

title: I want to connect my NodeMcu v3 to gsm

Answers: 0


body:
I have node mcu and i am trying to use the example code on github and pubnub blog to send a msg as an experiment but can't figure how to do it.

I used 2 example as the reference - https://github.com/pubnub/arduino , https://www.pubnub.com/docs/arduino/data-streams-publish-and-subscribe

Here is the code which i have. I modified it to include some libraries and my API keys. Let me know what changes i have to make:-

    #include <ESP8266WiFi.h>
    #define PubNub_BASE_CLIENT WiFiClient
    #define PUBNUB_DEFINE_STRSPN_AND_STRNCASECMP

    #include <PubNub.h>

    String pubkey = "pub-c-4a9cdbca-5688-4939-a852-f63cf6743980";
    String subkey = "sub-c-9b4067ae-1293-11e9-b4a6-026d6924b094";
    String pubchannel = "sec-c-NmFiYjliODYtMTc3Mi00YTMzLTg0OWMtMDgzYjE2ZGUwNzg5";

    void setup() {
        /* For debugging, set to speed of your choice */
        Serial.begin(9600);

        /* Start the Pubnub library by giving it a publish and subscribe
           keys */
        PubNub.begin(pubkey, subkey);
    }

    void loop() {
        /* Maintain DHCP lease. For other HW, you may need to do
           something else here, or maybe nothing at all. */

        /* Publish message. You could use `auto` here... */
        PubNonSubClient *pclient = PubNub.publish(pubchannel, "\"message\"");
        if (!pclient) return;
        PublishCracker cheez;
        cheez.read_and_parse(pclient);
        /** You're mostly interested in `outcome()`, and,
            if it's "failed", then `description()`.
        */
        Serial.print("Outcome: "); Serial.print(cheez.outcome());
        Serial.print(' '); Serial.println(cheez.to_str(cheez.outcome()));
        Serial.print("description: "); Serial.println(cheez.description());
        Serial.print("timestamp: "); Serial.println(cheez.timestamp());
        Serial.print("state: "); Serial.print(cheez.state());
        Serial.print(' '); Serial.println(cheez.to_str(cheez.state()));
        pclient->stop();

        /* Wait for news. */
        PubSubClient *sclient = PubNub.subscribe(subchannel);
        if (!sclient) return; // error
        String msg;
        SubscribeCracker ritz(sclient);
        while (!ritz.finished()) {
            ritz.get(msg);
            if (msg.length() > 0) {
                Serial.print("Received: "); Serial.println(msg);
            }
        }
        sclient->stop();

        delay(1000);
    }

    Error:-
    node_mcu_test_code:44:46: error: 'subchannel' was not declared in this scope

         PubSubClient *sclient = PubNub.subscribe(subchannel);

                                                  ^

    node_mcu_test_code:54:14: error: 'class PubSubClient' has no member named 'stop'

         sclient->stop();

                  ^

    exit status 1
    no matching function for call to 'PubNub::begin(String&, String&)'

title: How to publish on Pubnub with node mcu?

Answers: 1

body:
The pubchannel and subchannel can be defined as any values in char variable.

Here is the right code:-

    const char * pubkey = "publisher key from your account";
    const char * subkey = "subscriber key from your account";

    const char * pubchannel = "demo_keyset";
    const char * subchannel = "demo_keyset";

Then the error disappeared


body:
I am using this library https://github.com/miguelbalboa/rfid, and using **DumpInfo.ino** from it:

    /*
     * --------------------------------------------------------------------------------------------------------------------
     * Example sketch/program showing how to read data from a PICC to serial.
     * --------------------------------------------------------------------------------------------------------------------
     * This is a MFRC522 library example; for further details and other examples see: https://github.com/miguelbalboa/rfid
     *
     * Example sketch/program showing how to read data from a PICC (that is: a RFID Tag or Card) using a MFRC522 based RFID
     * Reader on the Arduino SPI interface.
     *
     * When the Arduino and the MFRC522 module are connected (see the pin layout below), load this sketch into Arduino IDE
     * then verify/compile and upload it. To see the output: use Tools, Serial Monitor of the IDE (hit Ctrl+Shft+M). When
     * you present a PICC (that is: a RFID Tag or Card) at reading distance of the MFRC522 Reader/PCD, the serial output
     * will show the ID/UID, type and any data blocks it can read. Note: you may see "Timeout in communication" messages
     * when removing the PICC from reading distance too early.
     *
     * If your reader supports it, this sketch/program will read all the PICCs presented (that is: multiple tag reading).
     * So if you stack two or more PICCs on top of each other and present them to the reader, it will first output all
     * details of the first and then the next PICC. Note that this may take some time as all data blocks are dumped, so
     * keep the PICCs at reading distance until complete.
     *
     * @license Released into the public domain.
     *
     * Typical pin layout used:
     * -----------------------------------------------------------------------------------------
     *             MFRC522      Arduino       Arduino   Arduino    Arduino          Arduino
     *             Reader/PCD   Uno/101       Mega      Nano v3    Leonardo/Micro   Pro Micro
     * Signal      Pin          Pin           Pin       Pin        Pin              Pin
     * -----------------------------------------------------------------------------------------
     * RST/Reset   RST          9             5         D9         RESET/ICSP-5     RST
     * SPI SS      SDA(SS)      10            53        D10        10               10
     * SPI MOSI    MOSI         11 / ICSP-4   51        D11        ICSP-4           16
     * SPI MISO    MISO         12 / ICSP-1   50        D12        ICSP-1           14
     * SPI SCK     SCK          13 / ICSP-3   52        D13        ICSP-3           15
     */

    #include <SPI.h>
    #include <MFRC522.h>

    #define RST_PIN         9          // Configurable, see typical pin layout above
    #define SS_PIN          10         // Configurable, see typical pin layout above

    MFRC522 mfrc522(SS_PIN, RST_PIN);  // Create MFRC522 instance

    void setup() {
     Serial.begin(9600);  // Initialize serial communications with the PC
     while (!Serial);  // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
     SPI.begin();   // Init SPI bus
     mfrc522.PCD_Init();  // Init MFRC522
     mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details
     Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
    }

    void loop() {
     // Look for new cards
     if ( ! mfrc522.PICC_IsNewCardPresent()) {
      return;
     }

     // Select one of the cards
     if ( ! mfrc522.PICC_ReadCardSerial()) {
      return;
     }

     // Dump debug info about the card; PICC_HaltA() is automatically called
     mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
    }

When I connect everything correctly and upload that sketch, this shows up in my Serial Monitor: [![serial monitor not working rfid][1]][1]

I have tried this with another cheap Arduino Uno, I connected it exactly the same and scanned one card, everything works perfectly fine: [![serial monitor working rfid][2]][2]

So I guess RC522 module is working fine, and there is probably issue with that Arduino Uno board.

What I tried next without any success is:

 - Copy bootloader from working Arduino Uno to this Arduino Uno that is not working.
 - Switch ATMEGA328P from working Arduino Uno to this Arduino Uno that is not working.

I tested all pins (on board that is not working) for PWM and Digital Output functionality with [Firmata Test][3], and everything is fine in this test.

You can take a look on images of this Arduino Uno board [here][4].

**So my question is: something is wrong with the board itself or I am doing something wrong?**

Thanks!

  [1]: https://i.stack.imgur.com/SSrvT.png
  [2]: https://i.stack.imgur.com/PazAD.png
  [3]: http://firmata.org/wiki/Main_Page#Firmata_Test_Program
  [4]: https://i.stack.imgur.com/NQMDS.jpg

title: RFID-RC522 not working with Arduino Uno clone

Answers: 1

body:
Try using this code:

    #include <SPI.h>
    #include <MFRC522.h>
    #include <Servo.h>

    #define SS_PIN 10
    #define RST_PIN 9

    #define SERVO_PIN 3
    Servo myservo;

    #define ACCESS_DELAY 2000
    #define DENIED_DELAY 1000
    MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.

    void setup()
    {
      Serial.begin(9600);   // Initiate a serial communication
      SPI.begin();          // Initiate  SPI bus
      mfrc522.PCD_Init();   // Initiate MFRC522

      myservo.attach(SERVO_PIN);
      myservo.write( 70 );
      delay(7500);
      myservo.write( 0 );
      Serial.println("Put your card to the reader...");
      Serial.println();

    }
    void loop()
    {
      // Look for new cards
      if ( ! mfrc522.PICC_IsNewCardPresent())
      {
        return;
      }
      // Select one of the cards
      if ( ! mfrc522.PICC_ReadCardSerial())
      {
        return;
      }
      //Show UID on serial monitor
      Serial.print("UID tag :");
      String content= "";
      byte letter;
      for (byte i = 0; i < mfrc522.uid.size; i++)
      {
         Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
         Serial.print(mfrc522.uid.uidByte[i], HEX);
         content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
         content.concat(String(mfrc522.uid.uidByte[i], HEX));
      }
      Serial.println();
      Serial.print("Message : ");
      content.toUpperCase();
      if (content.substring(1) == "69 C8 E2 2A") //change here the UID of the card
      {
        Serial.println("Authorized access");
        Serial.println();
       myservo.write( 70 );
     delay(7500);
      myservo.write( 0 );

      }

     else   {
        Serial.println(" Access denied");

        delay(DENIED_DELAY);

      }
    }


body:
I am working on a phase detection project in which i am trying to find the order in which the incoming signal comes. I converted the 240v 50hz Ac signal to a 7v 50hz square pulse. when i connect one(7v 50hz) of the three lines to a digital pin on arduino it is properly detecting, but the problem is if i check the unconnected pins via oscilloscope i am getting the same signal which i connected as input, so when i connect another line to any other pin the two signals are getting added.[![][1]][1]

  [1]: https://i.stack.imgur.com/w4Wap.jpg
[![][2]][2]
(Image 1)this is what i see in the DSO when i connect one line to the arduino pin and observe other pins
  [2]: https://i.stack.imgur.com/w3WR5.jpg
.(Image 2)this is what i get after i give another line as input to arduino and observe the pins.
i tried with 2 to 3 boards but i still get the same problem.

<!-- Begin schematic: In order to preserve an editable schematic, please
     don't edit this section directly.
     Click the "edit" link below the image in the preview instead. -->

![schematic](https://i.stack.imgur.com/lHG4t.png)

<!-- End schematic -->

this is the schematic i used for converting the sine wave into square wave, i used 4n33 optocoupler for this purpose.

title: Digital input on one pin is copied to other pins

Answers: 0


body:
I installed an Eclipse Version: 2018-12 (4.10.0) for Arduino.

I’ve got an ` CDT Core Builder error `  when I try to compile.

I’ve searched but cannot fix the problem.

[![enter image description here][1]][1]

  [1]: https://i.stack.imgur.com/RO652.png

title: Eclipse "CDT Core Builder" error

Answers: 0


body: On normal computers, heap will be cleaned as you close the program, but can I save data to Arduino's heap with `malloc` function. And will it be cleaned after I power off the Arduino?

title: Can you save data to heap section in Arduino memory?

Answers: 1

body:
Yes, you can use `malloc()` on the Arduino - however it is not something I would recommend you use since memory is at a premium and excessive use of `malloc()` and `free()` causes heap fragmentation which can eat your memory up and cause random crashes (`String` is the biggest culprit of this).

I am not sure what you mean by "clean" the memory.  When power is removed the content of the memory is lost. The whole of the SRAM forgets its contents if there is no power to maintain that state.  A bit like when you unplug your computer it "forgets" that Windows is loaded.

If you want to retain information with the power removed you need to use the [EEPROM](https://www.arduino.cc/en/Reference/EEPROM).


body:
I'm trying to use my Arduino Uno as an ISP to program an ATTiny85 and at the same time check my board by using the SoftwareSerial library to output the values I'm getting from my sensor.

Is this actually possible? Or does it require 2 different setups? Because I found a lot of tutorials and threads about one or the other, but never both. Which I find odd because once you send your program to the chip you might want to test it as well (or debug it).

Many thanks for your help and input! :)

title: Using Arduino as ISP and SoftwareSerial at the same time

Answers: 1

body: I'm not really sure, but in the Arduino ISP example there is an if that looks if the ISP is in program-mode. You could try adding in the else statement of that if the Software Serial part.


body:
I have a simple sketch working on arduino Uno and Nano sending data using an XBee.
However, if I run the project on an Arduino Mega it does not work.

What differences between Uno/Nano and the Mega could be causing issues?

Connection:  I just connect 3.3V->3.3V, Gnd->Gnd, and have tried various ports for DIN and DOUT (normally pins 2/4, but have tried A0/A1, 22/23 etc..).

Sketch: [pastebin][1]

Have brought a second Mega in case of hardware faults, but the problem persists.  Have stripped anything which might be tying up a timer.  Am choosing the right board type in the arduino IDE.

  [1]: https://pastebin.com/fKdK1r76

title: Arduino Nano, Uno and Mega - XBee connection difference

Answers: 1

body:
Not all arduino Mega pins support 'change interrupts', which is needed for Software Serial.  Only the following can be used for RX:

10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69).


body:
So I'm looking into having a TCP communication between 1 ESP8266 Chip (Station) and 2 ESP8266 (Clients) connected to that station. Every time I find a code including the TCP, they only include things like client.print(). But how can I write a message to a certain IP address in that network.

When I do client.print() it sends the message to ALL the clients. But I want to be able to do something like client1.print() and client2.print()

title: ESP8266 TCP/IP communication

Answers: 1

body:
WiFiClient object wraps a TCP socket. A normal TCP socket is connected to IP address and port. WiFiServer starts a listening socket on a port. If server on listening socket is contacted by a remote client socket, it creates a local socket connected with the remote client socket on a free port and returns a WiFiClient object wrapping the socket. Everything you write or print to a WiFiClient is send to that one remote socket.

If one of your client boards creates a WiFiClient and connects it to IP address and port of the WiFiServer on your 'server' board, then you get there a WiFiClient from server.available() and this two WiFiClient objects are connected. What you write/print on one side you read only from the WiFiClient object on the other side.

client socket

    if (client.connect(serverIP, PORT)) {
      client.print("request\n");
      String response = client.readStringUntil('\n');
      Serial.println(response);
      client.stop();
    }

server side

    WiFiClient client = server.available();
    if (client && client.connected()) {
      String request = client.readStringUntil('\n');
      Serial.println(request);
      client.print("response\n");
      client.stop();
    }


body:
How can I program my Pro Mini using the native RS232 Serial port on my Mainboard (aka com1).

Google-ing did not really help and a quick search here for "pro mini programming com1" did not deliver _any_ results.

I already have a MAX232 module connected between the Pro Mini and the PC.

I have already tested the com1 port for function by sending stuff to an Arduino mega via its usb-to-serial port and echo-ing that to com1.

Which succeeded (at least sort-of [receiving some random clutter in between characters or missing some characters at all])

I did try the obvious (i.e. selecting pro mini from the board menu and then selecting the com1 port and hit upload).

But that did just produce a timeout-error…

An Option to set the programmer to simple Serial Connection or something similar does not exist to my knowledge (well it does but only if we're talking about STM32 based boards like the blue pill).

title: How to program an Arduino pro mini using native serial port (on my mainboard)

Answers: 2

body:
To upload a hex file to Arduino over Serial interface, the bootloader must be active. The bootloader is active after reset. It waits a short time if a new application is uploaded. If not, it jumps to existing application.

To reset the MCU on Arduino boards with independent USB chip a circuit connected to DTR line of serial is used.

On a board like the Pro Mini there is no chip for USB neither an auto reset circuit. You must reset the board with the reset button right before avrdude sends the hex file. avrdude tries ten times, so you have 10 chances to time it right after you hit the Upload button.

Some USB-to-TTL-Serial adapters (or RS232 adapters) have the DTR line and it can be used to reset the board.

Or use ISP flashing over the ICSP header with a programmer or other board as programmer.

body:
Open the IDE, select File:Preferences and turn on Verbose Outputs.
Press & Hold Reset on the Promini.
Start the download. At the end of compilation you will see something like

>Sketch uses 960 bytes (2%) of program storage space. Maximum is 32256 bytes.

Then the IDE will try and download 3 times.

Release Reset when you see the line above - it may take a few tries to get the release timing correct.


body:
A number of questions ask about max possible in/out current on a GPIO pin, that's not my question here. I'm asking if it's possible to set a maximum current limit on a GPIO pin, such that any attempts to draw more than that current would result in the Arduino entering a constant current mode e.g. reducing the pin voltage?

I've read [this][1], [this][2], [this][3], and skimmed the [Curie datasheet][4], but I don't see a feature like this mentioned anywhere.

The only half-answer I have seen is on the [Ruggeduino website][5], which explains that they have added a fuse to each GPIO pin to avoid overcurrent draws due to short circuits.

For context - I have an external sensor that claims to be more reliable with a small amount of constant current. I didn't know if I could easily add that limitation (e.g. max 15mA at 3.3V) into the GPIO pin as a safety measure, so I went on a search to find out which has eventually led me here

  [1]: https://arduino.stackexchange.com/questions/38939/arduino-101-i-o-voltage-levels
  [2]: http://syncchannel.blogspot.com/2016/01/exploring-io-performance-of-arduino-101.html
  [3]: https://arduino.stackexchange.com/questions/21939/the-importance-of-i-o-pin-dc-current
  [4]: https://www.intel.com/content/dam/support/us/en/documents/boardsandkits/curie/intel-curie-module-datasheet.pdf
  [5]: https://www.rugged-circuits.com/10-ways-to-destroy-an-arduino/

title: Can you current-limit Arduino 101 GPIO pins?

Answers: 2

body:
No. I have never heard of a microcontroller with constant current or current limiting on the GPIO pins.

You may get a *drive strength* on the pins of an FPGA, but I have never seen such a thing on a microcontroller.

In general, if you have a need to reduce the voltage as the current increases you would just slip a resistor in the circuit. Or for more precise control using the GPIO pin to control a *constant current source* or *constant current sink* is the normal way of doing it.

GPIO pins are generally designed for communicating with other logic level devices. They require minimal current. Some microcontrollers provide a higher drive strength to work with larger *fanouts* (lots of devices connected to one pin, such as in SPI buses), but they are not intended for providing power to a device or giving control over their current.

body:
Typically port pins do have some current limiting inherent in the design of the chip. But it isn't something that should be used as protection. More line a fact that should be taken into account when implementing a design.

Say a 3.3 volt processor has a maximum rating of 12mA. With a 5 mA draw from the pin the high output voltage might be 3.0 volts. When 12mA is drawn from the chip the output voltage might only be 2.5 volts. It is important to check the data sheet to determine what you will get under the expected conditions.

A port with an internal pull up option may be considered more like (but not like) a constant current source. But that's stretching things a bit.


body:
I have a stack of TinyDuino boards including

[TinyZero][1] and [433MHZ Long Range Radio TinyShield][2].

I previously has this [processor][3] and had no problem compiling the sketch
and uploading it.

With the [TinyZero][1] now I get the following error.

    RadioHead.h:463:29: error: RHutil/atomic.h: No such file or directory
       #include <RHutil/atomic.h>

Obviously there is a file missing, when I tried to copy the file from the web
I got another error saying:

        sketch/RHHardwareSPI.cpp: In member function 'virtual void RHHardwareSPI::begin()':
    RHHardwareSPI.cpp:99:58: error: invalid conversion from 'uint8_t {aka unsigned char}' to 'BitOrder' [-fpermissive]
         _settings = SPISettings(frequency32, bOrder, dataMode);
                                                              ^
    In file included from sketch/RHGenericSPI.h:13:0,
                     from sketch/RHHardwareSPI.h:10,
                     from sketch/RHHardwareSPI.cpp:7:
    /home/ktsirakos/.arduino15/packages/TinyCircuits/hardware/samd/1.0.8/libraries/SPI/SPI.h:50:3: error:   initializing argument 2 of 'SPISettings::SPISettings(uint32_t, BitOrder, uint8_t)' [-fpermissive]
       SPISettings(uint32_t clock, BitOrder bitOrder, uint8_t dataMode) {
       ^

What the board does is to get Accelerometer values and send it to a receiver with the same RadioHead board.

I think it is because of the ARM of the TinyZero processor because the RadioHead.h header file includes these lines of code.

        // This is an attempt to make a portable atomic block
    #if (RH_PLATFORM == RH_PLATFORM_ARDUINO)
    #if defined(__arm__)
      #include "atomic.h"
     #else
      #include <util/atomic.h>
     #endif
     #define ATOMIC_BLOCK_START     ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
     #define ATOMIC_BLOCK_END }
    #elif (RH_PLATFORM == RH_PLATFORM_UNO32)
     #include <peripheral/int.h>
     #define ATOMIC_BLOCK_START unsigned int __status = INTDisableInterrupts(); {
     #define ATOMIC_BLOCK_END } INTRestoreInterrupts(__status);
    #else
     // TO BE DONE:
     #define ATOMIC_BLOCK_START
     #define ATOMIC_BLOCK_END
    #endif

Any suggestion if it is possible to run these 2 together? ([TinyZero][1] and [RadioHead][2])?

Thank you very much in advance.

  [1]: https://tinycircuits.com/products/tinyzero-processor
  [2]: https://tinycircuits.com/products/433mhz-long-range-radio-tinyshield
  [3]: https://tinycircuits.com/products/tinyduino-processor-board

title: TinyDuino RadioHead compile error with TinyZero

Answers: 0


body:
I've soldered a featherwing on my feather, then unsoldered it because it had stopped working: after the soldering of the featherwing, I was unable to upload new software to the board.

But now that the featherwing was removed, I still can't upload a software onto the board.

Here's the complete log I get:

    $ ~/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino9/bin/avrdude -C~/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino9/etc/avrdude.conf -v -v -v -v -patmega328p -carduino -P/dev/ttyUSB0 -b57600 -D -Uflash:w:/tmp/arduino_build_190205/Blink.ino.hex:i

    avrdude: Version 6.3, compiled on Jan 17 2017 at 11:00:16
             Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
             Copyright (c) 2007-2014 Joerg Wunsch

             System wide configuration file is "~/.arduino15/packages/arduino/tools/avrdude/6.3.0-arduino9/etc/avrdude.conf"
             User configuration file is "~/.avrduderc"
             User configuration file does not exist or is not a regular file, skipping

             Using Port                    : /dev/ttyUSB0
             Using Programmer              : arduino
             Overriding Baud Rate          : 57600
    avrdude: Send: 0 [30]   [20]
    avrdude: Send: 0 [30]   [20]
    avrdude: Send: 0 [30]   [20]
    avrdude: ser_recv(): programmer is not responding
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x00
    avrdude: Send: 0 [30]   [20]
    avrdude: ser_recv(): programmer is not responding
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x00
    avrdude: Send: 0 [30]   [20]
    avrdude: ser_recv(): programmer is not responding
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x00
    avrdude: Send: 0 [30]   [20]
    avrdude: ser_recv(): programmer is not responding
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x00
    avrdude: Send: 0 [30]   [20]
    avrdude: ser_recv(): programmer is not responding
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x00
    avrdude: Send: 0 [30]   [20]
    avrdude: ser_recv(): programmer is not responding
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x00
    avrdude: Send: 0 [30]   [20]
    avrdude: ser_recv(): programmer is not responding
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x00
    avrdude: Send: 0 [30]   [20]
    avrdude: ser_recv(): programmer is not responding
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x00
    avrdude: Send: 0 [30]   [20]
    avrdude: ser_recv(): programmer is not responding
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x00
    avrdude: Send: 0 [30]   [20]
    avrdude: ser_recv(): programmer is not responding
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00

    avrdude done.  Thank you.

I used to have this error from time to time before, but I always was able to make it work, either by using another USB port, choosing the right port for the arduino or rebooting Linux, but now nothing I do works.

So, I think I might have broken the board because of the soldering/unsoldering.

I attached the pictures of both sides of the board.

[![board top][1]][1]
[![board bottom][2]][2]

Three LEDs continue to blink: the red one when I connect the board to the USB, the battery one and the RX one when there is an attempt at transmission.

Can you tell me whether the board looks damage?

  [1]: https://i.stack.imgur.com/EbGQY.jpg
  [2]: https://i.stack.imgur.com/KaRpQ.jpg

title: Is my board broken by soldering?

Answers: 2

body:
It looks like you have soldering paste all over the circuit board. If enough paste bridges a gap between the ceramic resonator and the IC, it can attenuate the oscillator signal to the point where the board won't work.

I use an old tooth brush and Isopropyl alcohol to clean excess soldering paste. As the alcohol evaporates, a lot of moisture forms on the circuit board, so it's important to ensure it's completely dry before you power it up.

Try cleaning the circuit board and see if that fixes the problem.

**EDIT:**

I would like to show you how much soldering paste it takes to stop a 328P from working. The following image shows the bottom of a perfboard with 0.1" hole spacing. You can see the soldering paste bridging the gap between pins 8, 9, and 10 of a Atmega328P DIP IC. Pin 8 is ground, and pins 9 and 10 are connected to the crystal / capacitors. All three pins are connected together via the paste, and since I forgot to clean the board before "final assembly", it's possible other pins are connected together via the paste.

[![Excess soldering paste][1]][1]

The circuit board is from a "kitchen clock project", and was taken the day it stopped working. There are no mechanical connections to this circuit board except for the 328P's IC socket. This clock worked for 3 months, then it quit suddenly. I re-booted it once, it worked for an hour, then it quit again. The only factor that changed after the first three months was a change of seasons (the ambient temperature in the kitchen was reaching 90+ degrees F during the day). I don't know if the "blobs" of paste were touching each other when I assembled it, but they were when it failed. How does thick soldering paste start moving around on it's own? With some heat and [Capillary action][2] of course :)

Cleaning the board with Isopropyl alcohol fixed the problem, and the clock has been running for the past 6 months without issue.

**EDIT 2**

When I monitor pin 9 of a 328P on a 5V Arduino Uno, this is the waveform I see.

[![enter image description here][3]][3]

You can see the small amount of voltage change the oscillator has to make for the 328P to sense it, and function correctly (800mV peak to peak). If the soldering paste is conductive, capacitive or perhaps both, connecting this signal through the paste to ground, power or several other pins can disrupt the signal to the point where the IC fails to operate.

  [1]: https://i.stack.imgur.com/MjEUj.png
  [2]: https://en.wikipedia.org/wiki/Capillary_action
  [3]: https://i.stack.imgur.com/QwG7d.png

body:
There is flux on the board and that is **not** going to cause the problems you are seeing. At worst the flux may have an affect on the ability to get a proper lock at 2.5GHz, and that is unlikely.

Clean the board and use magnification to look for damage to the copper foil on the board and inside the plated holes. That will most likely be the problem.

This was from a question regarding no-clean fluxes but the information also applies to the use of regular flux as well.

> Today, one of the most common reasons to remove no-clean fluxes is to
> prevent malfunctions in circuits with clock speeds over 1 gigahertz.
> "When you get above 1 gigahertz, the electronscan conducted on the
> outer surface of the conductor. If you have flux on those conductors
> that have those high clock speeds, it can interfere with these fast
> signals."
http://www.circuitnet.com/experts/73284.html

Most electronics are not cleaned after soldering. The company I work for went to a no clean process 20 years ago.


body:
Im trying to get html response from server via esp01 module

when using the serial monitor in arduino studio everything works fine

here is the serial monitor output

    AT+CIPSTART="TCP","aaaa.aaaa",80

    CONNECT

    OK
    AT+CIPSEND=43

    OK
    >
    Recv 43 bytes

    SEND OK

    +IPD,227:HTTP/1.1 200 OK
    Date: Sat, 19 Jan 2019 18:42:58 GMT
    Server: Apache
    X-Powered-By: PHP/7.2.11
    Vary: Accept-Encoding,User-Agent
    Transfer-Encoding: chunked
    Content-Type: text/html; charset=UTF-8

    10
    Hello from server

    0

    CLOSED

but when im trying to do the same from the sketch my response is returned partially

    AT+CIPSTART="TCP","aaaa.aaaa",80

    CONNECT

    OK
    AT+CIPSEND=43

    OK
    >
    Recv 43 bytes

    SEND OK

    +IPD,227:HTTP/1.1 200 OK
    Date: S

it ends on the first letter of date for some reason

here is my sketch

    #include <SoftwareSerial.h>

    SoftwareSerial mySerial(10, 11); // RX, TX //serial for comunication with esp
    void setup() {
      // Open serial communications and wait for port to open:
      Serial.begin(9600);
      while (!Serial) {
        ; // wait for serial port to connect. Needed for native USB port only
      }

      // set the data rate for the SoftwareSerial port
      mySerial.begin(9600);
      mySerial.setTimeout(5000);//dont know if i need this

      delay(10000);

      //check wifi module
      mySerial.println("AT");
      delay(1000);
      if(mySerial.find("OK"))
      {
        Serial.println("Initializing");
      }else{
        Serial.println("Error initializing");
      }
    }

    void loop() { // run over and over

      Serial.println("go");
    mySerial.println("AT+CIPSTART=\"TCP\",\"aaaa.aaaa\",80");
    delay(1000);
        while(mySerial.available()){
        Serial.write(mySerial.read());
         delay(1);
      }
    mySerial.println("AT+CIPSEND=43");
    delay(1000);
        while(mySerial.available()){
        Serial.write(mySerial.read());
         delay(1);
      }
    mySerial.println("GET /load.php HTTP/1.1");
    delay(100);
        while(mySerial.available()){
        Serial.write(mySerial.read());
         delay(1);
      }
    mySerial.println("Host: aaaa.aaaa");
    delay(100);
        while(mySerial.available()){
        Serial.write(mySerial.read());
         delay(1);
      }
    mySerial.println("");
    delay(2000);

        while(mySerial.available()){
        Serial.write(mySerial.read());
         //delay(100);
      }

    delay(5000);

    }

what is the reason for this behavior?
how can i fix this?

title: Esp8266-01 AT Commands returns partially

Answers: 1

body:
found the solution
i had t wait for serial input without delay function

    String sendCommand(String command, const int timeout)
    {
      String res = "";
      mySerial.println(command); // send the read character to the wifi
      long int time = millis();
      while( (time+timeout) > millis())
      {
        while(mySerial.available())
        {
          // The esp has data so display its output to the serial window
          char c = mySerial.read(); // read the next character.
          res+=c;
        }
      }
      //Serial.print(response);
      return res;
    }


body:
[![enter image description here][1]][1]

I am using the Adafruit Flora, connected with a Max 4466 microphone sensor. When I read values from the pin numbered 12 (which is marked as a11 for analog input on the schematic of the flora) I get random characters in the serial monitor as shown in the attached image, with my code. Trying to read other pins that are connected to nothing doesn't read any information. My baud rate in the serial monitor and the code are the same as you can see in the image.

Looking at the max 4466 explanation on the Adafruit website it says you don't need a capacitor or anything and can just directly plug the out pin on the MAX 4466 to the analog pin on an Arduino. I'm not sure if a different protocol has to be followed for a Flora instead of an Arduino. It also says to convert the information to an actual signal I need to use the FFT libraries, but I don't think this input being read is even correct.

If the FFT library is the problem here, I would need help on how to use it because there is no clear value being read in the example code. I had to set up a delay in the code otherwise the IDE would crash from all the info.Additionally, the VCC on the max is connected to 3.3V, the GND to GND, and the OUT to the #12 pin on the Flora.

  [1]: https://i.stack.imgur.com/SwOk7.png

title: Strange values on Serial Monitor even with matched baud rate

Answers: 1

body:
You can't concatenate string and value inside `Serial.println()`.

Print them using two different `Serial.println()`.

    int pin12;
    int A12 = A12;

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

    void loop() {
      // put your main code here, to run repeatedly:
      pin12 = analogRead(A11);

      Serial.print("pin 12 is ");
      Serial.println(pin12);

      delay(5000);
    }


body:
i am using the elechouse PN532 RFID Module with an Wemos D1 mini in the Arduino IDE.
I use the ISO1443a_uid example from the elechouse library. All works fine if i plug the USB Cable into the wemos and the demo runs. But if i press the reset button on the Wemos D1 mini then the Serial brings this output:

    load 0x4010f000, len 1384, room 16
    tail 8
    chksum 0x2d
    csum 0x2d
    v0fd86a07
    ~ld
    Hello!
    Didn't find PN53x board

Sometimes it works fine but mostly comes this error.

Here is the sample code (i am using the I2C Mode):

    * When the number after #if set as 1, it will be switch to SPI Mode*/
    if 0
     #include <SPI.h>
     #include <PN532_SPI.h>
     #include "PN532.h"

     PN532_SPI pn532spi(SPI, 10);
     PN532 nfc(pn532spi);

    * When the number after #elif set as 1, it will be switch to HSU Mode*/
    elif 0
     #include <PN532_HSU.h>
     #include <PN532.h>

     PN532_HSU pn532hsu(Serial1);
     PN532 nfc(pn532hsu);

    * When the number after #if & #elif set as 0, it will be switch to I2C Mode*/
    else
     #include <Wire.h>
     #include <PN532_I2C.h>
     #include <PN532.h>
     #include <NfcAdapter.h>

     PN532_I2C pn532i2c(Wire);
     PN532 nfc(pn532i2c);
    endif

    oid setup(void) {
     Serial.begin(115200);
     Serial.println("Hello!");
     pinMode(D2,INPUT_PULLUP);
     pinMode(D1,INPUT_PULLUP);
     nfc.begin();

     uint32_t versiondata = nfc.getFirmwareVersion();
     if (! versiondata) {
       Serial.print("Didn't find PN53x board");
       while (1); // halt
     }

     // Got ok data, print it out!
     Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX);
     Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC);
     Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC);

     // Set the max number of retry attempts to read from a card
     // This prevents us from waiting forever for a card, which is
     // the default behaviour of the PN532.
     nfc.setPassiveActivationRetries(0xFF);

     // configure board to read RFID tags
     nfc.SAMConfig();

     Serial.println("Waiting for an ISO14443A card");

    oid loop(void) {
     boolean success;
     uint8_t uid[] = { 0, 0, 0, 0, 0, 0, 0 };  // Buffer to store the returned UID
     uint8_t uidLength;                        // Length of the UID (4 or 7 bytes depending on ISO14443A card type)

     // Wait for an ISO14443A type cards (Mifare, etc.).  When one is found
     // 'uid' will be populated with the UID, and uidLength will indicate
     // if the uid is 4 bytes (Mifare Classic) or 7 bytes (Mifare Ultralight)
     success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, &uid[0], &uidLength);

     if (success) {
       Serial.println("Found a card!");
       Serial.print("UID Length: ");Serial.print(uidLength, DEC);Serial.println(" bytes");
       Serial.print("UID Value: ");
       for (uint8_t i=0; i < uidLength; i++)
       {
         Serial.print(" 0x");Serial.print(uid[i], HEX);
       }
       Serial.println("");
       // Wait 1 second before continuing
       delay(1000);
     }
     else
     {
       // PN532 probably timed out waiting for a card
       Serial.println("Timed out waiting for a card");
     }

What is wrong? why is it not alltimes working after a reset?

title: Problem “Didn't find PN53x board” Arduino NFC Card Reader

Answers: 1

body:
EDIT:
Try using [Elechouse library][1], it worked better for me.

---

This might be irrelevant, but I wanted to share.

I had a similar issue, not related to the sketch code.

So make sure:

1. Connect wires to the NFC module at **90 degrees** - there should be angular headers included. Also the wires should be **above the antenna** - the white strip.

2. There shouldn't be any wires underneath the NFC module or they should on significant distance.

3. Soldered wires work better on the NFC module.

[![Stable working condition][2]][2]

  [1]: https://github.com/elechouse/PN532
  [2]: https://i.stack.imgur.com/YUf8q.jpg


body:
I have a JDY-30 bluetooth module and have it wired like this (except using an Arduino Uno): [![enter image description here][1]][1]

It is working, but I need to use it with a 115200 baud rate instead of the default one of 9600.
I also got that working.
Here is the code:

    #include <SoftwareSerial.h>

    SoftwareSerial mySerial (2, 3); // RX, TX

    // state | RXD | TXD | GND | VCC | EN

    void setup () {
      mySerial.begin(115200);
      Serial.begin(9600);
      Serial.println("Enter AT commands:");
    }

    void loop() {

      while (mySerial.available()) {
        delay(10);
        Serial.write(mySerial.read());
        delay(10);
      }

      while (Serial.available()) {
        mySerial.write(Serial.read());
      }

    }

But when I type things I often get badly formatted characters.

Some examples:

> 16:32:33.212 -> +VERSION=Firmware V3.0.6,Bluetooth V4.0 L⸮
>
> 16:32:38.990 -> +VERSION=Firmware V3.0.6,Bluetooth V4.0 LE

more:

> 16:33:27.144 -> +NAME=CC61-A
>
> 16:33:30.054 -> +NAME=CC41-A

If I also use 115200 baud rate for the Arduino, then it gets really worse.

Is there a solution for this?

See more about the JDY-30 here:
http://myosuploads3.banggood.com/products/20181203/20181203214419JDY-30-SPP-Bluetooth-Module.pdf

  [1]: https://i.stack.imgur.com/xGSAe.png

title: Badly formatted characters using JDY-30 bluetooth module

Answers: 1

body:
As @Majenko pointed out:

> It is impossible to reliably receive using SoftwareSerial at 115200
> baud. The UNO is just too slow for that.

I got results that where a lot better by first making a string when reading and then once we have a string send that. Instead of sending what we read all the time.
For example, when I tried `AT+VERSION` now it took me 16 attempts to get a wrong one, and only one character out of 42 was wrong that time.

    #include <SoftwareSerial.h>

    SoftwareSerial mySerial (2, 3); // RX, TX

    // state | RXD | TXD | GND | VCC | EN

    void setup () {
      mySerial.begin(115200);
      Serial.begin(115200);
      Serial.println("Enter AT commands:");
    }

    void loop() {

      String input_string = "";

      while (mySerial.available()) {
        input_string += (char)mySerial.read();
      }

      if (input_string != "") {
        Serial.write(input_string.c_str());
      }

      while (Serial.available()) {
        mySerial.write(Serial.read());
      }

    }


body:
First off. This is not in any way a class assignment. This is my own personal work and research. I just want to get that out of the way.

I am learning how to use Matlab with various Arduino projects. I am a seasoned Matlab user but I am fairly new to the entire Arduino space.

I am trying to send some numerical data from Matlab (via a GUI) to my Arduino Uno and have the Arduino write it to my micro SC card. This is a temporary step to my larger project. However, there is no need to go into those specifics as they are outside of the scope of my issues.

I am fairly confident that the Matlab code works and the Arduino code is slightly modified from another project I did where I wrote and read random numbers from my micro SD card.

However, as I run the Matlab code, the Arduino blinks as if it is receiving the data but after I check the micro SD card it remains blank.

I am confident that my Arduino is wired correctly to my micro SD card adapter since this remains the same from my prior project.

Therefore, I am sure I am missing something trivial to get it to work.

I have researched several websites on the subject and their method and mine seem to align very well.

I am fairly certain the problem is in the conditional statement:

    if (Serial.available() > 0) {

As you will see.

The Matlab code is below:

    arduinoCom = serial('COM3', 'BaudRate', 115200);
    sendData = 5;
    fopen(arduinoCom);
    fprintf(arduinoCom,'%i',sendData); %this will send 5 to the arduino
    fclose(arduinoCom);
    delete(arduinoCom);

The Arduino code is as follows:

    #include <SD.h> // load SD library

    int chipSelect = 4;  // Chip select pin for the MicroSD Card Adapter
    int incomingByte = 0; // for incoming serial data.
    File SDF; // Serial data received is saved here.

    void setup() {
         Serial.begin(115200); // start serial connection to print out debug messages and data
         pinMode(chipSelect, OUTPUT); // chip select pin must be set to OUTPUT mode
         if (!SD.begin(chipSelect)) { // Initialize SD card
            Serial.println("Could not initialize SD card."); // if return value is false, something went wrong.
         }
         while (!Serial) {
         }
    }

    void loop() {
            // Open file, Write data, Close file only when you receive data
            if (Serial.available() > 0) {
               incomingByte = Serial.read();
               SDF = SD.open("SerialDataFile.txt", FILE_WRITE); // open "SerialDataFile.txt" to write data
               SDF.println(incomingByte, DEC); // write ASCII-encoded decimal number to file
               SDF.close(); // close file
               }
    }

The expected result would be a file "SerialDataFile.txt" stored on my micro SD card with the value 5.

Thank you for your help!

title: What am I missing? Send data from Matlab to Arduino to Micro SD

Answers: 1

body: The board resets on new USB connection with fopen. Wait 2 secs between fopen and fprintf in Mathlab code.


body:
I want to turn on a pump that is running 12V and draws a current of max 1.7A with my Arduino Uno.

To do this, I bought the RFP30N06LE MOSFET and followed [these] instructions to wire it all up.

I connected the red wire from the pump to VIN of the Arduino and plugged a 12V 2A power brick into the Arduino. However, when I put the output pin to HIGH, the pump only pumps weakly and the MOSFET gets very hot.

When I connect the pump straight to VIN and GND, it works as expected, so the Arduino is able to provide the required current. I'm thinking that there is something to the MOSFET that I am not understanding correctly. I measured VGS at 4.5V, so the MOSFET should be able to handle the current. Is there anything I am missing?

  [these]: http://bildr.org/2012/03/rfp30n06le-arduino/

This is the wiring:
[![enter image description here][1]][1]

  [1]: https://i.stack.imgur.com/wx7Pq.png

This is the (very simple) sketch I'm using to test it all:

    #define PIN_PUMP_ON 7

    void setup() {
      pinMode(PIN_PUMP_ON, OUTPUT);
    }

    void loop() {
      digitalWrite(PIN_PUMP_ON, HIGH);
      delay(1000);
    }

title: Arduino Driving Pump via MOSFET

Answers: 3

body:
Rewire the motor power so that it is not using any Arduino Power or GND pins.  Only connect the MOSFET gate to an Arduino pin using a suitable resistor.  The MOSFET drain needs to go directly to your power supply ground.  This way you're not cooking your Arduino.  A relay instead of the MOSFET would prevent the MOSFET resistance from reducing the power of your motor.

The 3 big pins under the Arduino's power connector (2 GND and 1 +V) can be used to power your motor, just solder directly to them for Motor +V and GND for MOSFET drain.  This bypasses the Arduino's diode.

body:
Vin is only rated to supply at most 1A due to the reverse polarity protection diode in series from the barrel jack to the Vin pin.  You try and draw 1.7A thru that and you may smoke it.
The Vin header is also only rated for 1A.

Connect the motor to the supply directly. The Arduino Gnd must also connect to the supply.
R2 limits Arduino IO pin current to a safe level. R1 keeps the MOSFET off while the Arduino boots up. Diode dissipates motor generated current when the MOSFET goes from On to Off. The RFP30N06LE looks to be rated for full turn on with Vgs of 5V, and Rds of 47milliohm, that part should be ok to use.

Powering the Arduino from the same source as the motor may cause issues. If you can power the Arduino from USB or a seperate battery pack and not the same 12V that powers the motor, that will probably yield better results, especially if the 12V droops at all under heavy loads from the motor. That could cause Arduino resets.

<!-- Begin schematic: In order to preserve an editable schematic, please
     don't edit this section directly.
     Click the "edit" link below the image in the preview instead. -->

![schematic](https://i.stack.imgur.com/tM1Vh.png)

<!-- End schematic -->

body:
Under no circumstances should you connect the motor to VIN on the Arduino. A motor draws far too much current.

You want to have the ground on the arduino connected to the ground for the motor, but you want different positive supplies for the 2 different devices. You also need to make sure you have a properly sized protection diode wired in parallel with the motor, but pointing against the flow of current.


body:
I'm looking for a library helping me to connect from an Arduino to a MQTT Broker. Of course I want to secure the connection via TLS/SSL.

The "physical" connection is established via a **SIM800** module.
The Arduino itself should be as power efficient as possible (it's battery/solar powered).

In case the Arduino is too weak to perform such a task (SSL) is there any other suitable device? maybe a PyBoard?

Anyone can point me to the right direction?

title: Arduino and using a SSL secured mqtt broker

Answers: 0


body:
I need to print mentioned below byte array on the serial monitor screen of Arduino IDE

    char b[]= {'0x7E', '0x00', '0x1C','0x90', '0x00', '0x13', '0XA2', '0x00', '0x41', '0x58', '0x1C', '0xCB', '0xFF', '0xFE', '0xC1', '0x7C', '0x00','0x0F', '0x00', '0x01', '0x00', '0x00', '0x37', '0x46', '0x46', '0x46', '0x00', '0x00', '0x00', '0xE7' };
    void setup() {
    Serial.begin(9600);
    }

    void loop() {
    Serial.println(b[]);
    delay(500);
    }

But whenever I am trying a print, the error problem was there which was not resolved which is

    C:\Users\Misha\Desktop\test\Test_2\Test_2.ino: In function 'void loop()':

    Test_2:8:18: error: expected primary-expression before ']' token

     Serial.println(b[]);

                      ^

    exit status 1
    expected primary-expression before ']' token

Any suggestions on this will be great help.

title: Print Byte Array in Serial monitor screen of Arduino IDE

Answers: 1

body:
You can’t print an array in that way.

If you want to print an array of hexadecimal value (with two digits), you have to use `sprintf` function and change declaration of `b` array.

    uint8_t b[]= {0x7E, 0x00, 0x1C, 0x90, 0x00, 0x13, 0XA2, 0x00,
                  0x41, 0x58, 0x1C, 0xCB, 0xFF, 0xFE, 0xC1, 0x7C,
                  0x00, 0x0F, 0x00, 0x01, 0x00, 0x00, 0x37, 0x46,
                  0x46, 0x46, 0x00, 0x00, 0x00, 0xE7};
    int i;

    void printHex(uint8_t num) {
      char hexCar[2];

      sprintf(hexCar, "X", num);
      Serial.print(hexCar);
    }

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

    void loop() {
      for(i=0; i<sizeof(b); i++){
        printHex(b[i]);
     }

     Serial.println();
     delay(500);
    }

The output produced is:

> 7E001C900013A20041581CCBFFFEC17C000F0001000037464646000000E7
> 7E001C900013A20041581CCBFFFEC17C000F0001000037464646000000E7
> 7E001C900013A20041581CCBFFFEC17C000F0001000037464646000000E7


body:
I'm working on project which require to save some data into the EEPROM.
As I read online the ESP8266 has no real EEPROM, it use a section of FLASH just after the SPIFFS. Due to this read/write is quite different from standard Arduino, you need to call `EEPROM.commit()`. You also have to call `EEPROM.begin(size)` (I used size = 512) before start to use it.

I follow different tutorials online and I made some tests but it seems not working at all. When I try to save a value and then read it, values are different. I tried with

    EEPROM.write(..)
    ...
    EEPROM.read(..)

and with

    EEPROM.put(..)
    ...
    EEPROM.get(..)

but nothing change.

Is there any configuration on the board I need to set into Arduino IDE/Board Configuration?

EDIT: here's the code

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

     EEPROM.begin(512);
     EEPROM.write(0, 62);
     EEPROM.write(10, 103);
     //EEPROM.commit();
     EEPROM.end();
     Serial.print("Read at 0:"); Serial.println(EEPROM.read(0), DEC);
     Serial.print("Read at 10:"); Serial.println(EEPROM.read(10), DEC);
    }
I always read 0 in the output.

title: ESP8266 EEPROM seems not working, saved data are different when I try to read them

Answers: 2

body:
Here is some ESP8266 example code to store and read strings from EEPROM data:

    #include <EEPROM.h>

    void writeString(char add,String data);
    String read_String(char add);

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

      EEPROM.begin(512);  // Note::

      String data = "Hello World";

      Serial.print("Writing Data:");
      Serial.println(data);

      writeString(10, data);  //Address 10 and String type data
      delay(10);
    }

    void loop() {
      // put your main code here, to run repeatedly:
      String recivedData;
      recivedData = read_String(10);
      Serial.print("Read Data:");
      Serial.println(recivedData);
      delay(1000);
    }

    void writeString(char add,String data)
    {
      int _size = data.length();
      int i;
      for(i=0;i<_size;i++)
      {
        EEPROM.write(add+i,data[i]);
      }
      EEPROM.write(add+_size,'\0');   //Add termination null character for String Data
    }

    String read_String(char add)
    {
      int i;
      char data[100]; //Max 100 Bytes
      int len=0;
      unsigned char k;
      k=EEPROM.read(add);
      while(k != '\0' && len<500)   //Read until null character
      {
        k=EEPROM.read(add+len);
        data[len]=k;
        len++;
      }
      data[len]='\0';
      return String(data);
    }

body:
You can read the emulated EEPROM only between `begin` and `end`. It works with memory image.

 - `begin` allocates the in-memory image.
 - `commit` writes it to flash.
 - `end` commits and deletes the memory image.


body:
I have designed and built a transformer driver board for my spot welder. It is powered from mains electricity (230 V) and consists of the following segments: triac drive and protection, zero cross detection, controller input, connections. The board operates correctly when voltage is manually applied. However, I'm not able to make it work with Arduino.

[![Main board shematic. ][1]][1]
What I want it to do is:

 1. Read the potentiometer(R10), and assign to it value a phase angle, at which triac is going to receive pulse to turn on.
 2. Read Potentiometer (R9), and assigned to it value number of pulses(1-100) for a triac,
 3. Read switch (Power_pulse) that when high start triac firing procedure (angle and duration determined by pots)
 4. I have an I2C display 16x4 that(can be driven directly from SCL and SDA on Leonardo) I might use to display welding parameters(optional goal)
The code I found on "electronoobs.com"

           int detectado = 0;
            int valor=0;
             int last_CH1_state = 0;

           void setup() {

          PCICR |= (1 << PCIE0);    //enable PCMSK0 scan
          PCMSK0 |= (1 << PCINT0);  //Set pin D8 trigger an interrupt on state change. Input from optocoupler
          pinMode(3,OUTPUT);        //Define D3 as output for the DIAC pulse

        }

        void loop() {
           //Read the value of the pot and map it from 10 to 10.000 us. AC frequency is 50Hz, so period is 20ms. We want to control the power
           //of each half period, so the maximum is 10ms or 10.000us. In my case I've maped it up to 7.200us since 10.000 was too much

           valor = map(analogRead(A0),0,1024,7200,10);
            if (detectado)
            {
              delayMicroseconds(valor); //This delay controls the power
              digitalWrite(3,HIGH);
              delayMicroseconds(100);
              digitalWrite(3,LOW);
              detectado=0;
            }
        }

        //This is the interruption routine
        //----------------------------------------------

        ISR(PCINT0_vect){
          /////////////////////////////////////               //Input from optocoupler
          if(PINB & B00000001){                               //We make an AND with the pin state register, We verify if pin 8 is HIGH???
            if(last_CH1_state == 0){                          //If the last state was 0, then we have a state change...
              detectado=1;                                    //We haev detected a state change!
            }
          }
          else if(last_CH1_state == 1){                       //If pin 8 is LOW and the last state was HIGH then we have a state change
            detectado=1;                                      //We haev detected a state change!
            last_CH1_state = 0;                               //Store the  current state into the last state for the next loop
            }
        }

Finally the question: What do I need to add to this code to make it work in my application?

 PS.  Issues regarding safety are addressed by another board that have fuse and over voltage protection.

PPS. I have 5V supply dedicated to driving the board and Arduino.

  [1]: https://i.stack.imgur.com/P1DE5.png

    enter code here
    void setup() {

    }

     int faza=0;
     int cykle=1;
     bool wcisniety;

      void loop() {

        faza=20000 * analogRead(2) / 255;// Pot 1
        cykle=100 * analogRead(3) / 255; //Pot2

      if(digitalRead(4) && (! wcisniety))// if cheacks for button pres to activate function
        {zgrzewaj();}

       wcisniety=digitalRead(4);

       }

     void zgrzewaj(){

       while (digitalRead(0)){

        }

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

    delayMicroseconds(faza);

    digitalWrite(1,HIGH);

    delay(10-faza/1000);

    digitalWrite(1,LOW);// fireing TRIAC
     }
    }
 This is what i come up  with. While it looks simple and proprly build still dont hav any output.
All coments appreciated.

title: TRIAC Pulse driver for Spot Welder (help needed with programming)

Answers: 0


body:
    #include<LiquidCrystal.h>
    LiquidCrystal lcd(13,12,11,10,9,8);
    #define vibrate_sense 7

    char str[70];
    char *test="$GPGGA";
    char logitude[10];
    char latitude[10];

    int i,j,k;
    int temp;
    //int Ctrl+z=26;    //for sending msg
    int led=13;

    void setup()
    {
      lcd.begin(16,2);
      Serial.begin(4800);
      pinMode(vibrate_sense, INPUT);
      pinMode(led, OUTPUT);
      lcd.setCursor(0,0);
      lcd.print("..Initializing..");
      lcd.setCursor(0,1);
        lcd.print("....System...");
    delay(1000);
    lcd.clear();
    lcd.setCursor(0,0);
      lcd.print("Searching for");
        lcd.setCursor(0,1);
          lcd.print("Gps Signals");
      delay(2300);
    lcd.clear();
      lcd.setCursor(0,0);
        lcd.print("Setup Completed");
      delay(500);
      lcd.setCursor(0,0);
        lcd.print("Accident detect");
      lcd.setCursor(0,1);
        lcd.print("& Alert system");
      delay(1500);
      lcd.clear();
        lcd.setCursor(0,0);
        lcd.print("No accident");
            lcd.setCursor(0,1);
            lcd.print("occured");

    }

    void loop()
    {
      if (digitalRead(vibrate_sense)==0)
      {
        for(i=18;i<27;i++)          //extract latitude from string
        {
          latitude[j]=str[i];
          j++;
        }

        for(i=30;i<40;i++)          //extract longitude from string
        {
          logitude[k]=str[i];
          k++;
        }

    lcd.clear();
        lcd.setCursor(0,0);        //display latitude and longitude on 16X2 lcd display
        lcd.print("Latitude(N)");
        lcd.print(latitude);
        lcd.setCursor(0,1);
        lcd.print("Longitude(E)");
        lcd.print(logitude);
        delay(500);
        lcd.clear();
            lcd.setCursor(0,0);
        lcd.print("Accident has");
                lcd.setCursor(0,1);
        lcd.print("been Detected");
    delay(500);
    lcd.clear();
        lcd.print("Sending SMS");
        delay(500);
        lcd.clear();
        Serial.begin(9600);

        Serial.println("AT+CMGF=1");    //select text mode
        delay(10);
        Serial.println("AT+CMGS=\"7066128969\"");  // enter receipent number
        Serial.println("Vehicle Accident occured:");
        Serial.print("Latitude(N): ");             //enter latitude in msg
        Serial.println(latitude);                  //enter latitude value in msg
        Serial.print("Longitude(E): ");            //enter Longitude in Msg
        Serial.println(logitude);                  //enter longitude value in msg
        Serial.print("http://maps.google.com/maps?&z=15&mrt=yp&t=k&q=");
        Serial.println(latitude);
        Serial.println("+");
        Serial.println(logitude);
        Serial.write(26);                      //send msg  Ctrl+z=26

          lcd.setCursor(0,0);
        lcd.print("SMS Sent");
    delay(1000);
    lcd.clear();
              lcd.setCursor(0,0);
        lcd.print("Help Please");

        temp=0;
        i=0;
        j=0;
        k=0;
        delay(20000);                        // next reading within 20 seconds
        Serial.begin(4800);
      }
    }

    void serialEvent()
    {
      while (Serial.available())            //Serial incomming data from GPS
      {
        char inChar = (char)Serial.read();
         str[i]= inChar;                    //store incomming data from GPS to temparary string str[]
         i++;
         if (i < 7)
         {
          if(str[i-1] != test[i-1])         //check for right string
          {
            i=0;
          }
         }
        if(i >=60)
        {
         break;
        }
      }
    }

This is my code for my project.
It is accident detection system and it has to work like, when I press the sensor or limit switch, it has to show a message on an LCD that an accident occurred. But it shows the message on the LCD WITHOUT pressing the sensor button.

What to do?
I think there is a mistake in my program. Can anybody please tell me where it is?

title: LCD shows output without pressing the sensor

Answers: 1

body:
First off I edited indentation in your code because incorrect indentation is little bit confusing.
```
#include <LiquidCrystal.h>
LiquidCrystal lcd(13,12,11,10,9,8);
#define vibrate_sense 7

char str[70];
char *test="$GPGGA";
char logitude[10];
char latitude[10];

int i,j,k;
int temp;
//int Ctrl+z=26;    //for sending msg
int led = 13;

void setup(){
  lcd.begin(16,2);
  Serial.begin(4800);

  pinMode(vibrate_sense, INPUT);
  pinMode(led, OUTPUT);

  lcd.setCursor(0,0);
  lcd.print("..Initializing..");
  lcd.setCursor(0,1);
  lcd.print("....System...");
  delay(1000);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Searching for");
  lcd.setCursor(0,1);
  lcd.print("Gps Signals");
  delay(2300);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Setup Completed");
  delay(500);
  lcd.setCursor(0,0);
  lcd.print("Accident detect");
  lcd.setCursor(0,1);
  lcd.print("& Alert system");
  delay(1500);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("No accident");
  lcd.setCursor(0,1);
  lcd.print("occured");
}

void loop(){
  if (digitalRead(vibrate_sense) == 0){
    for(i = 18; i < 27; i ++){          //extract latitude from string
      latitude[j]=str[i];
      j++;
    }

    for(i=30;i<40;i++){          //extract longitude from string
      logitude[k] = str[i];
      k++;
    }

    lcd.clear();
    lcd.setCursor(0,0);        //display latitude and longitude on 16X2 lcd display
    lcd.print("Latitude(N)");
    lcd.print(latitude);
    lcd.setCursor(0,1);
    lcd.print("Longitude(E)");
    lcd.print(logitude);
    delay(500);
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Accident has");
    lcd.setCursor(0,1);
    lcd.print("been Detected");
    delay(500);
    lcd.clear();
    lcd.print("Sending SMS");
    delay(500);
    lcd.clear();
    Serial.begin(9600);

    Serial.println("AT+CMGF=1");    //select text mode
    delay(10);
    Serial.println("AT+CMGS=\"7066128969\"");  // enter receipent number
    Serial.println("Vehicle Accident occured:");
    Serial.print("Latitude(N): ");             //enter latitude in msg
    Serial.println(latitude);                  //enter latitude value in msg
    Serial.print("Longitude(E): ");            //enter Longitude in Msg
    Serial.println(logitude);                  //enter longitude value in msg
    Serial.print("http://maps.google.com/maps?&z=15&mrt=yp&t=k&q=");
    Serial.println(latitude);
    Serial.println("+");
    Serial.println(logitude);
    Serial.write(26);                      //send msg  Ctrl+z=26

    lcd.setCursor(0,0);
    lcd.print("SMS Sent");
    delay(1000);
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Help Please");

    temp = 0;
    i = 0;
    j = 0;
    k = 0;
    delay(20000);                        // next reading within 20 seconds
    Serial.begin(4800);
  }
}

void serialEvent(){
  while (Serial.available()){            //Serial incomming data from GPS
    char inChar = (char)Serial.read();
    str[i] = inChar;                    //store incomming data from GPS to temparary string str[]
    i++;
    if (i < 7){
      if(str[i-1] != test[i-1]){         //check for right string
        i = 0;
      }
    }
    if(i >= 60){
      break;
    }
  }
}
```

----------

Second thing is this line `if (digitalRead(vibrate_sense) == 0){` you are checking there vibrate_sense for value 0. Are you sure, that triggered value is 0 and not 1? Try this code to test which value is equal to triggered state.
```
#define vibrate_sense 7

void setup() {
  Serial.begin(9600);
  Serial.println("Sensor testing");
  pinMode(vibrate_sense, INPUT);

}

void loop() {
  Serial.println(digitalRead(vibrate_sense));
  delay(300);
}
```

----------

Last thing is connection of your sensor/button. For button you have to use also PULL_UP/PULL_DOWN resistor to have correct logic value on digital pin.


body:
i have been trying to set Builtin LED frequency from arduino and turn it on and off .

I have created an interface with knobs and buttons in processing . I want to set delay between ON and OFF with 1 knob and OFF and ON delay with another knob . And button blinks the led at given frequency

In arduino i have tried something like this :

    if(Serial.available() >0){
    char val=Serial.read();
    switch(val)
    {
      case 'c':
      theValue=Serial.read();
      break;
      case 'd':
      theValue1=Serial.read();
      break;

    case 'r':
    digitalWrite(13,HIGH);
    delay(theValue);
    digitalWrite(13,LOW);
    delay(theValue1);

    break;
    }

    }

In the processing :

      public void Blink(){
       myPort.write('r');
     }

     public void knobON(int theValue){
       myPort.write('c');
       myPort.write(theValue);
     }

     public void knobOFF(int theValue1){
       myPort.write('d');
       myPort.write(theValue1);
     }

Can you help me on what should i do ?

title: How to send chars and values at the same time from processing to Arduino

Answers: 1

body:
The Arduino code sample you've provided is incomplete, and does not compile. On the Processing side, I would combine the LED On time with the Off time, using a separator, then ending with a `\n`. Something like this: `myPort.write("1000:2000\n");`.

There are many ways to parse the serial data into `unsigned long` to be used in the `delay()` function. Here is a sketch illustrating one way to parse it. I am using the serial monitor to send the following test data **1000:2000** (LED on for 1 second, off for 2 seconds). The serial monitor is sending the `\n` character.

    char buffer[16];
    unsigned long onTime;
    unsigned long offTime;

    void setup(){
      Serial.begin(9600);
      pinMode(13, OUTPUT);
    }

    void loop(){

      if(Serial.available() > 0){

        Serial.readBytesUntil('\n', buffer, 13);

        char * pch;
        pch = strtok(buffer, ":");
        onTime = strtol(pch, &pch, 10);
        pch = strtok(NULL, ":");
        offTime = strtol(pch, NULL, 10);

        digitalWrite(13, HIGH);
        delay(onTime);
        digitalWrite(13, LOW);
        delay(offTime);
        memset(buffer, 0, sizeof(buffer));
      }
    }


body:
I'm trying to make a WiFi controlled Car from my old toy car which will be running on ESP8266. I'm using the L298N motor driver and have *one motor for left-right control* & *other for forward-backward direction control*.

Now the problem is I'm unable to use more than 3 pins at once. If I even try, likely my code **stops** working.

Below is my code :

    static const uint8_t enFront   = D0;
    static const uint8_t front_in1 = D1;
    static const uint8_t front_in2 = D2;
    static const uint8_t enBack    = D5;
    static const uint8_t back_in1  = D3;
    static const uint8_t back_in2  = D4;

    #include <ESP8266WebServer.h>

    const char* ssid = "espCar <^_^>";
    const char* password = "hacksAllowed";

      ESP8266WebServer server(80);

    void setup() {
      pinMode(enFront,OUTPUT);
      pinMode(front_in1,OUTPUT);
      pinMode(front_in2,OUTPUT);
     /* pinMode(enBack,OUTPUT);   <--Problem here
      pinMode(back_in1,OUTPUT);   <--Problem here
      pinMode(back_in2,OUTPUT);*/ <--Problem here

       Serial.begin(115200);
      WiFi.softAP(ssid, password);
      WiFi.mode(WIFI_AP);
      delay(500);
      server.on("/REQ",processRequest);
      server.begin();
      Serial.println("Server is UP!");
    }

    void loop() {
     // server.handleClient();
      analogWrite(enFront,1023);
      digitalWrite(front_in1,HIGH);
      digitalWrite(front_in2,LOW);
      delay(2000);
      digitalWrite(front_in2,HIGH);
      digitalWrite(front_in1,LOW);
      delay(2000);
    }

    void processRequest() {
     /* if (server.arg("move")!=""){
        if (server.arg("right")!=""){
          analogWrite(enFront,server.arg("right").toInt());
          digitalWrite(front_in1,HIGH);
          digitalWrite(front_in2,LOW);
          /*Debug*/
        /*  server.send(200, "200", server.arg("right"));
        }else if(server.arg("left")!=""){
          analogWrite(enFront,server.arg("left").toInt());
          digitalWrite(front_in1,LOW);
          digitalWrite(front_in2,HIGH);
          /*Debug*/
         /* server.send(200, "200", server.arg("left"));
        }
      }*/
    }

-------------------------------------------------------------------------

***All code working fine until I declare `pinMode(pin,OUTPUT)` for any 4th pin.*** (Everything is ok for every pin till 3rd one is declared)

I'm not so old with ESP or Arduino. So, please help by giving some clarification on this.

-------------------------------------------------------------------------------
**Schematic**:

<!-- Begin schematic: In order to preserve an editable schematic, please
     don't edit this section directly.
     Click the "edit" link below the image in the preview instead. -->

![schematic](https://i.stack.imgur.com/Bsybo.png)

<!-- End schematic -->

**Sorry for the mistake of making both motors tagged 2, → one is M1 & other is M2**

title: Is not it possible to use more than 3 output pins in ESP8266 at the same time?

Answers: 1

body:
I found out the problem & it has nothing to deal with ESP8266. It was something like voltage conflict (I don't know the deeper science, I agree).

*Actually, I was testing by plugging in the USB to ESP & at the same time I had a 11V lipo connected to L298N.*

I tested by using one single voltage source & everything worked fine.

It looked something like this (It → the wrong one here):

<!-- Begin schematic: In order to preserve an editable schematic, please
     don't edit this section directly.
     Click the "edit" link below the image in the preview instead. -->

![schematic](https://i.stack.imgur.com/NWxoA.png)

<!-- End schematic -->


body:
I'm wondering if anyone knows if it's possible to do a software reset using the watchdog timer on a microcontroller using the Micronucleus bootloader.  When I try it, it doesn't fully reset, as in when connected with USB to a computer, it doesn't appear as a libusb device for a short period of time.

I'm suspecting a watchdog timer reset isn't as early in the boot process as necessary for Micronucleus to wait for programming.

I'm using an ATTiny841 to make a small wrist watch for my son, and I wanted to keep it to a single button.  I've been resetting for programming with a pair of tweezers grounding the reset pin side of a pullup.  Not a huge deal if it's not possible, once I have the code set, there won't be much need to re-program.

Here's the watch so far:  https://www.youtube.com/watch?v=lkH16xzkSJM

Thanks in advance!

title: Software reset on Micronucleus possible?

Answers: 0


body:
I am totally beginner but I am trying to finish my project as school work :-(
but from the beginning, I am really stuck.

Could anyone help me out?

    #include <SoftwareSerial.h>
    SoftwareSerial BTserial(10, 11); // RX | TX

    void setup() {
      // initialize serial communication at 9600 bits per second:
      BTserial.begin(9600);
    }

    void loop() {
      // read the input on analog pin 0:
      int sensorValue1 = analogRead(A0);
      int sensorValue2 = analogRead(A1);
      BTserial.print(sensorValue1);
      BTserial.print('|');
      BTserial.println(sensorValue2);
      delay(50);
    }

The received value is here

    D/BluetoothConnectionSrv: InputStream: 955|108
    D/BluetoothConnectionSrv: InputStream: 9
    D/BluetoothConnectionSrv: InputStream: 46|51
    D/BluetoothConnectionSrv: InputStream: 9
    D/BluetoothConnectionSrv: InputStream: 47|57

I need only values from 2 sensors, it seems to be as
    D/BluetoothConnectionSrv: InputStream: 955|108
    D/BluetoothConnectionSrv: InputStream: 946|51
    D/BluetoothConnectionSrv: InputStream: 947|57

I've tried to send "How are you?", then the result in the app was this

    D/BF: o
    D/BF: u ?Are yo
    D/BF: u ?
    D/BF: H
    D/BF: ow Are you
    D/BF:  ?

Source code in my app

            bluetoothSocket = socket;
            InputStream tempIn = null;
            OutputStream tempOut = null;

            try {
                tempIn = bluetoothSocket.getInputStream();
                tempOut = bluetoothSocket.getOutputStream();
            } catch (IOException e) {
                e.printStackTrace();
            }

            inputStream = tempIn;
            outputStream = tempOut;
        }

        public void run(){
            byte[] buffer = new byte[1024];
            int bytes;

            while(true){
                try {
                    bytes = inputStream.read(buffer);
                    handler.obtainMessage(STATE_MESSAGE_RECEIVED, bytes, -1, buffer).sendToTarget();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

-------------------------------------------------------------------

                case STATE_MESSAGE_RECEIVED:
                    byte[] readBuff = (byte[]) msg.obj;
                    String tempMsg = new String(readBuff, 0, msg.arg1);
                    tvMessage.setText(tempMsg);
                    Log.d("BF",tempMsg);
                    break;

title: HC-05 sending data to Android a value but it cracked out of its form

Answers: 0


body:
I am new to arduino. I can import the acceleration data from a text file into arduino and I can also make the motor run at that acceleration with a distance calculated from an equation. I use the AccelStepper library but I notice that per acceleration data, the motor stops abruptly and moves  again in a very short delay, causing a lot of vibrations. Is there any easier way to make a stepper motor run with acceleration values from a text file?

The text file is also placed on an SD card, and I use the function Serial.parseFloat() to get the data from the file.

Here is my code:

    #include <SPI.h>
    #include <SD.h>
    #include <AccelStepper.h>
    int STP = 4;
    int DIR = 3;
    const int chipSelect = 53;
    double Acceleration = 0;
    double Previous_Acceleration = 0;
    double Velocity = 0;
    double Previous_Velocity = 0;
    double Distance = 0;
    double Previous_Distance;
    AccelStepper stepper(AccelStepper::DRIVER,STP,DIR);
    void setup(){
      pinMode(STP,OUTPUT);
      pinMode(DIR,OUTPUT);
      Serial.begin(38400);
      Serial.println("Starting Program");
      delay(1000);
      while (!Serial){
        ;
      }
      Serial.println("Initializing SD Card...");
      if (!SD.begin(chipSelect)){
        Serial.println("SD Card Error");
        while(1);
      }
      Serial.println("Card Initialized");

      File dataFile = SD.open("sinx.txt");

      if (dataFile){
        while (dataFile.available()){
          Acceleration = dataFile.parseFloat();
          Velocity = ((Previous_Acceleration + Acceleration)/2) + Previous_Velocity;
          Distance = ((Previous_Velocity + Velocity)/2) + Previous_Distance;
          stepper.setSpeed(Velocity);
          stepper.setAcceleration(Acceleration);
          stepper.runToNewPosition(Distance - Previous_Distance);

        }
      }
      else{
        Serial.println("Error");
      }
    }

    void loop(){

    }

title: How do you make a stepper motor move in accordance to earthquake data using arduino?

Answers: 0


body: When I make the motor move at a certain distance with setMaxSpeed(), setAcceleration(), and moveTo(), it always accelerates and decelerates. Is there a way to disable the deceleration?

title: AccelStepper Library: How do I go to a position without decelerating?

Answers: 1

body:
AccelStepper, as hinted by the name, uses acceleration always. By setting the acceleration high, you reduce the amount of time spent accelerating to the set speed.

`setAcceleration()` sets the rate in steps per second per second. If your MaxSpeed is 200 steps per second, then setting the acceleration to 200*10 means all acceleration is over in 1/10 second. You can go higher, etc.


body:
I use a 16x2 character lcd to display some text. What I want is first line will stay, but the second line should scroll text.

I wrote a program which works fine but the problem is after some time arduino does not respond. I suspect there might be a bug or memory leak in the code.

The relevant code is like this.

    void scrollTextFromRight(int line, char text[])
    {
        const char space[16] = "                ";
        char screen[16];
        char * longText;

        longText = malloc(sizeof(char) * (sizeof(text) + 17));

        memset(longText, '\0', sizeof(char) * (sizeof(text) + 17));
        memset(screen, '\0', sizeof(screen));

        for (int i = 0; i < 16; ++i)
        {
            longText[i] = space[i];
        }

        for (int j = 0; j < sizeof(text) + 17; ++j)
        {
            longText[16+j] = text[j];
        }

        for (int i = 0; i < sizeof(text) + 17; ++i)
        {

            lcd.setCursor(0, line);
            strncpy(screen, longText + i, 17 );
            lcd.print(screen);
            delay(350);
        }
    }

I call this function from main program like this:

    scrollTextFromRight(1, "Scrolling text");

title: Arduino scrolling text program freeze after some time

Answers: 1

body:
You malloc but don't free. Of course it's going to leak. Also `sizeof(text)` doesn't work like that. Instead you can do strlen to get the number of characters in a null-terminated char array.

You can do this without the `longText` buffer by doing partial copies into `screen`.

    const char space[16] = "                ";
    char screen[16];

    for (int i = 0; i < sizeof(text) + 17; ++i)
    {
        lcd.setCursor(0, line);
        strncpy(screen, space, i); // copy i spaces
        strncpy(screen+i, text, min(17-i, strlen(text))); // copy the rest of the string up to the end whichever is shorter.
        screen[17] = '\0'; // force null termination
        lcd.print(screen);
        delay(350);
    }


body:
I have a simple sample of code that i want to convent a time_t to char array in order to concatenate it after, in an other array.
Code:

    time_t unixt;
    char exm [40];

    unixt = RTC.get();
    Serial.println(unixt);
    dtostrf(unixt, 10, 0, exm);
    Serial.println(exm);

The problem that i face is that, the console is printing different the second one every time like this:

    1548258220
    1548258200

I tried also with unsigned long with no result either. Can someone point me what's wrong or an other way of doing this?

title: Wrong conversion of time_t to char

Answers: 1

body:
Use `ultoa()` instead of `dtostrf()`. The former is meant to serialize
unsigned long integers, while the later is for floating point numbers.
By using `dtostrf()`, you are implicitly converting `unixt` to a
floating point number. The Arduino Mega only supports single precision
floating point, so this conversion incurs some loss of precision, hence
the result you see.


body:
I'm using the `ble_client.ino` example and I can't figure out how to only show some of the `notifyCallback` data. I'm getting three different types of data from one service UUID.

    static void notifyCallback(
      BLERemoteCharacteristic* pBLERemoteCharacteristic,
      uint8_t* pData,
      size_t length,
      bool isNotify) {

      static unsigned long lastPrinted;
      const unsigned long printInterval = 100;
      if(millis() - lastPrinted >= printInterval) {
        lastPrinted = millis();
        Serial.println();
        }
        Serial.printf(" Data:%X", pData[16]);

    }

This is what get in the serial monitor

> Data:A9 Data:B9 Data:F5
Data:A9 Data:B9 Data:F5
Data:A9 Data:B9 Data:F5
Data:A9 Data:B9 Data:F5

I just want the

> Data:B9
Data:B9
Data:B9
Data:B9
Data:B9

 to be shown. How to?

title: How to remove or only show part of the data received?

Answers: 0


body:
I am trying to upload my sketch to an Arduino Mini Pro.
My programmer is the Arduino USB2Serial.
I am running the Windows store app on a Windows 10 machine.

I wired everything up according to the [Arduino Mini guide][1].

[![This is the setup I'm working with right now][2]][2]

I got different errors just stating something like "error while trying to upload the sketch" before but now I'm always getting this error message after the programmer takes a very long time trying to upload:

    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 1 of 10: not in sync: resp=0x68
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 2 of 10: not in sync: resp=0x68
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 3 of 10: not in sync: resp=0x68
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 4 of 10: not in sync: resp=0x68
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 5 of 10: not in sync: resp=0x68
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 6 of 10: not in sync: resp=0x68
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 7 of 10: not in sync: resp=0x68
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 8 of 10: not in sync: resp=0x68
    avrdude: stk500_recv(): programmer is not responding
    avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x68
    avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x00
    Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

I also didn't forget the capacitor. I added one that is well above the required 100nF and the reset seems to work as the mini came preloaded with the blink example and it briefly stops before the programmer tries to upload.
I did also try to manually reset at different times before and after klicking the upload button.

I also noticed the programmers RX LED lights up briefly flashing three times shortly after resetting the Arduino but the TX one never lights up.

I also checked if there was an error with the programmer but whenever send something through the serial console while connecting the RX and TX of the programmer it always returns what I typed and both LEDs light up so it should work.

I also manually installed the Arduino USB drivers. The programmer now shows up as "Arduino USB Serial Light Adapter" in the device manager.

I did set the arduino Mini board in the Arduiono IDE settings and also the right port. Though I am not really sure which programmer to choose. I tried pretty much all of them that made sense to me with exactly the same results in every case.

In my memory when playing with these components years ago I thought it was also possible to just connect an Arduino Mini "upside down" like this (I am so sure I remember this working but it won't when trying now):
[![I know this is not the intended way but it feels so right cause pretty much all the pins line up.][3]][3]

So right now I don't know what else to try. I even tried multiple different Arduino Minis from different manufacturers and tried resoldering all pins to make sure I didn't mess up.

I also tried pretty much everything from the troubleshooting guide mentioned in the error message.
Any suggestions what else I could try?

*Update: I now also tried using an old Arduino Uno as programmer like described in the Arduino Mini guide and I tried different versions of the Arduino IDE down to ver 1.0.1 all with the same results.
I even tried installing the drivers from the older versions but Windows 10 wouldn't let me and insisted that the default drivers were suited best.
I managed installing drivers from the newest Arduino IDE but it didn't change anything.*

*I read [in this question][4] That it might be an issue having to do with older Arduino Mini boards (mine are a few years old). But the fixes suggested there did nothing for me.
The only thing I can think of left to try would be using a machine running an older version of windows in order to be able to use older drivers. But I'm really not sure if it's worth the trouble.*

*I'm also starting to suspect that my programmer might be broken. But then again why did it work looping back serial messages?*

  [1]: https://www.arduino.cc/en/Guide/ArduinoMini
  [2]: https://i.stack.imgur.com/LbYnk.jpg
  [3]: https://i.stack.imgur.com/XiLoJ.jpg
  [4]: https://arduino.stackexchange.com/questions/22262/i-cant-get-code-transferred-to-my-arduino-mini-pro?rq=1

title: Arduino Mini and USB2Serial not uploading sketch

Answers: 0