texts: Controlling 3 stepper motors simultaneously

texts:
I have three stepper motors connected to the drv8825 drivers to an arduino uno.

I am using the example code below (from here), which works fine for moving multiple stepper motors at the same time BUT they all move for the same number of steps and in the same direction. I would like to tweak the code so that all of them move at the same time but each one for a different number of steps and in different directions. The motor with the least steps would probably have to wait for the motor with the most steps to finish its movement before going again.

int dirPin = 8;
int stepperPin = 7;
int bdirPin = 6;
int bstepperPin = 5;

void setup() {
 pinMode(dirPin, OUTPUT);
 pinMode(stepperPin, OUTPUT);
 pinMode(bdirPin, OUTPUT);
 pinMode(bstepperPin, OUTPUT);
}
 void step(boolean dir,int steps){
 digitalWrite(dirPin,dir);
 digitalWrite(bdirPin,dir);
 delay(50);
 for(int i=0;i<steps;i++){
 digitalWrite(stepperPin, HIGH);
 digitalWrite(bstepperPin, HIGH);
 delayMicroseconds(800);
 digitalWrite(stepperPin, LOW);
 digitalWrite(bstepperPin, LOW);
 delayMicroseconds(800);
 }
}
void loop(){
 step(true,1600);
 delay(500);
 step(false,1600*5);
 delay(500);
}

Thank you in advance for your help!


texts: ESP8266-12E as WiFi interface for Arduino Mega

texts:
I have an Arduino Mega 2560 that I would like to connect to the internet using an ESP8266-12E.

Searching the internet for relevant keyphrases only yielded one type of result: The articles all explain how to program the ESP using the Arduino. Been there, done that.

Does anybody know of a way to use the ESP as a "wifi interface" for an Arduino, e.g. using a Serial interface from the Arduino?

Basically, I'd want to use the library ESP8266Wifi transparently on my Mega 2560, and maybe in conjunction with something like WifiManager - all of that running on the Mega.

The only thing I found was this: https://www.hackster.io/jeffpar0721/add-wifi-to-arduino-uno-663b9e. But this uses AT commands only.

Any hint is appreciated.


texts:
I have created a gui in python that allows an arduino controlled mecanum wheel cart to move around.
The cart allows for 8 different move directions and can rotate left and right. Commands are sent over a serial connection between the laptop(w10, python) and the arduino.
I have an Enum class in python representing the different move directions.
I have a corresponding enum in the arduino to interprete the commands from the python task.
What is an easy way to share a single common enum definition for both coding environments?


texts: Arduino SDFat Libray overwrites last value

texts:
I'm trying to create a comma delimited file using this SDFat library
Calling this code creates my file
const char Header[24]="Desired RPM,Output RPM\n";
...
foo()
{
  SpeedCache.open("/Speed_Cache.txt",O_CREAT | O_RDWR | O_APPEND);
  SpeedCache.write(Header);
  SpeedCache.sync();
}
...

After running, I have a file containing

Desired RPM,Output RPM'\n'

When I call the following function, I want it to add int target and int reference to the bottom of the file.
bool SDClass::SetLine(SdFile Cache,int target, int reference)
{
  bool good = false;
  char NewLine[32];
  Cache.seekEnd();
  sprintf_P(NewLine,(PGM_P)F("%d,%d\n"),target,reference);
  Serial.println(good=Cache.write(NewLine));
  Cache.sync();
  return good;
}

On the first call, this works so for an input of SpeedCache,50,100 I get

Desired RPM,Output RPM'\n'
50,100'\n'

However, if I then write an input of SpeedCache,5,10 I get

Desired RPM,Output RPM'\n'
5,10'\n'

How do I adjust my function so that I will get:

Desired RPM,Output RPM'\n'
50,100'\n'
5,10'\n'


texts: Can't get actual output when, both input logic is high

texts:
I want
When,

light=0, ir=0 then output will pin 8 high & pin 12 low.
light=0, ir=1 then output will pin 8 high & pin 12 high.
light=1, ir=0 then output will pin 8 low & pin 12 low.
light=1, ir=1 then output will pin 8 low & pin 12 low (This statement
does not work).

Please find the code & suggest me, if any modification is needed.

void setup() {

    pinMode(8,OUTPUT); //logic output.
    pinMode(12,OUTPUT); //logic output.
    pinMode(2, INPUT); //value input.
    pinMode(4, INPUT); //value input.

    Serial.begin(9600);
}

void loop() {

    int light = digitalRead(2); //value input.
    int ir = digitalRead(4); //value input.

    if (light == LOW && ir == LOW)
    {

      digitalWrite(8, HIGH);
      digitalWrite(12, LOW);
      delay(2000);

    }

    if (light == LOW && ir == HIGH)
    {

      digitalWrite(8, HIGH);
      digitalWrite(12, HIGH);
      delay(2000);

    }

    if (light == HIGH && ir == LOW)
    {

      digitalWrite(8, LOW);
      digitalWrite(12, LOW);
      delay(2000);

    }

    if (light == HIGH && ir == HIGH) //This condition does not work.
    {

      digitalWrite(8, LOW);
      digitalWrite(12, LOW);
      delay(2000);

    }

    digitalWrite(8, LOW);
    digitalWrite(12, LOW);
    delay(2000);

}


texts: Question: how to join two different codes

texts:
I’m dabbling in Arduino and having trouble running two sketches on my Arduino UNO simultaneously. The first is about a program that reads temperature and relative humidity and the second is a program that reads barometric pressure. Both programs work independently, but when I try to combine the two, No
help
this is the code for temperature and relative humidity:

#include <Adafruit_Sensor.h>
#include <LiquidCrystal.h>
#include <DHT.h>
#include <DHT_U.h>

//VARIABLES
//Asignación de los pines digitales
int SENSOR = 2; //Este es el pin #2
int RS = 4;
int E = 5;
int D4 = 6;
int D5 = 7;
int D6 = 8;
int D7 = 9;
//Variables de lectura de tempratura y humedad
int temp;
int hume;
//Creación de variables para el sensor y el display
DHT dht(SENSOR,DHT11);                    //Formato general: DHT <var_name>(PIN, MODELO DEL SENSOR)
LiquidCrystal lcd(RS, E, D4, D5, D6, D7); // Formato general: LiquidCrystal <var_name>(RS, RW, ENABLE, D0, D1, D2, D3, D4, D5, D6, D7)
//Variable para salida del abanico
int motor = 12;

void setup(){

  //Iniciar el sensor de temp
  dht.begin();
  //Iniciar el LCD
  lcd.begin(16,2); //(tipo 16 columnas, 2 líneas)
  //Setea el Pin 12 como salida
  pinMode(motor,OUTPUT);

}

void loop(){ //Este es el buclé principal del programa

  //Lee valores físicos
  hume = dht.readHumidity();
  temp = dht.readTemperature();

  //Limpia el LCD
  lcd.clear(); //esta instrucción coloca el cursor en la pos 0,0 (columna, fila)
  lcd.setCursor(0,0); //(no necesaria porque la linea de arriba ya lo hace)
  //Escribe los valores leídos en el LCD
  lcd.print("TEMPERATURA: ");
  lcd.print(temp);
  lcd.print("C");
  lcd.setCursor(0,1); //esta instrucción coloca el cursor en la pos 0,1 (columna, fila)
  lcd.print("HUMEDAD: ");
  lcd.print(hume);
  lcd.print("%");

  //Activa el motor si la temperatura pasa el valor deseado
  if(temp>=30){ // Compara si la temp ya es 30 grados
    digitalWrite(motor,HIGH); //Si lo es manda un 1 lógico a teavés del pin digital #12
  }
  else{
    digitalWrite(motor,LOW);// sino, manda un 0, lo que apagaría el motor
  }

  delay(2000);//valor en milisengundos para que repita el ciclo

}

and this is the barometric pressure code:
#include <Wire.h>
#include <Adafruit_BMP085.h>

// Connect VCC of the BMP085 sensor to 3.3V (NOT 5.0V!)
// Connect GND to Ground
// Connect SCL to i2c clock - on '168/'328 Arduino Uno/Duemilanove/etc thats Analog 5
// Connect SDA to i2c data - on '168/'328 Arduino Uno/Duemilanove/etc thats Analog 4
// EOC is not used, it signifies an end of conversion
// XCLR is a reset pin, also not used here

Adafruit_BMP085 bmp;

void setup() {
  Serial.begin(9600);
  if (!bmp.begin()) {
    Serial.println("Could not find a valid BMP085 sensor, check wiring!");
    while (1) {}
  }
}

void loop() {
    Serial.print("Temperature = ");
    Serial.print(bmp.readTemperature());
    Serial.println(" *C");

    Serial.print("Pressure = ");
    Serial.print(bmp.readPressure());
    Serial.println(" Pa");

    // Calculate altitude assuming 'standard' barometric
    // pressure of 1013.25 millibar = 101325 Pascal
    Serial.print("Altitude = ");
    Serial.print(bmp.readAltitude());
    Serial.println(" meters");

    Serial.print("Pressure at sealevel (calculated) = ");
    Serial.print(bmp.readSealevelPressure());
    Serial.println(" Pa");

  // you can get a more precise measurement of altitude
  // if you know the current sea level pressure which will
  // vary with weather and such. If it is 1015 millibars
  // that is equal to 101500 Pascals.
    Serial.print("Real altitude = ");
    Serial.print(bmp.readAltitude(101500));
    Serial.println(" meters");

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


texts:
I want to send a file from an Arduino to the server or another Arduino.

I wrote a code that's open the file then write the content of the text on an array and then send it.

That would work if the data is small, but when i try to send, .wav it will takes lots of time if i do it that why (storing each byte in array).
I want to send the whole file at on time.
Is there a way or a library helps ?

#include <SPI.h>
#include <Ethernet.h>
#include <EthernetUdp.h>
#include <SD.h>

const int push1 = 2;

File myFile;
char a[400];
int c= 0;

// network parameters
byte mac[] = { 0x90, 0xA2, 0xDA, 0x0E, 0x05, 0x02 };  // ethernet interface MAC address
IPAddress localIp(10,131,41,72);    // local ip address
IPAddress destIp(10,131,41,74);      // destination ip address
unsigned int port = 9631;               // destination port

// EthernetUDP to send and receive messages.
EthernetUDP Udp;

// timing

// setup the arduino and shields
void setup() {

    pinMode(push1, INPUT);

  //Initialize serial and wait for port to open:
  Serial.begin(9600); // 19200
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  }

  Serial.print("Initializing SD card...");

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    while (1);
  }
  Serial.println("initialization done.");

  // start ethernet and udp
  Ethernet.begin(mac, localIp);   // static ip version
  //if(Ethernet.begin(mac) == 0) {     // dhcp version
  // report failure to obtain network parameters
  // Serial.println("DHCP error");

  // no point in carrying on, loop indefinitely:
  // while(true)
  // ;
  //}

  // open UDP port
  Udp.begin(port);

  // show the local ip address (useful for dhcp)
  Serial.print("Local IP: ");
  Serial.println(Ethernet.localIP());

  // initialize previous millis variables

}

// do tasks
void loop() {

if(digitalRead(push1) == LOW){

   myFile = SD.open("R.wav" , FILE_READ);

  if (myFile) {
    // read from the file until there's nothing else in it:
    Serial.println("i will send now");
    while (myFile.available()) {
        a[i] = myFile.read();
        i++;
        }
      Udp.beginPacket(destIp, port);
     Udp.write(a);
      Udp.endPacket();
      Serial.println("Sending UDP message");
      Serial.println();
    }
    // close the file:
    myFile.close();
  } else {
   // if the file didn't open, print an error:
    Serial.println("error opening test.txt");
  }  } }


texts: Copy the upper 3 bits from one PORT to another

texts:
I am stuck in this assignment and I don't really know how to begin.
I would appreciate any help or guidance to the following problem:


texts:
I'm trying to display a scrolling number on my MAX7219 display using the LedControl library, but can only ever get the first digit (digit 0) updating. When I reference digits 1-7 the 7 segments don't light up.

This also happens even with the example sketch LCDemo7Segment. Is there an issue with my display unit perhaps?

Using an Uno board and this module. Using pin 11 for DataIn, 13 for CLK, and 12 for Load.


texts:
I bought new Uno yesterday, i made my programme, and i compile it. it was good compiled. however, when i upload the programme to my Uno, it cannot be uploaded and there was a message like this

avrdude: stk500_getsync() attempt 10 of 10: not in sync: resp=0x1b
Problem uploading to board.  See http://www.arduino.cc/en/Guide/Troubleshooting#upload for suggestions.

Help me please


texts: Arduino Due & Spec gas sensor - how to choose specific information from a stream of incoming bytes to store

texts:
I'm trying to build an air pollution sensor for a college project, with an Arduino Due and a series of Spec Sensors digital gas detectors. However, I'm having a little trouble getting the first one of them (Carbon Monoxide, https://www.spec-sensors.com/product/digital-co-sensor/) to behave, before I can run multiple. As they're all the same sensor setup but for different gasses, once I get the first one working, the rest should follow easily.

The code's very simple, as it uses Spec's own command system - sending the letter "c" to the sensor forces it to take one reading per second for as long as the sensor is powered, and then the serial monitor displays whatever comes back:

    void setup() {
      // sensor running via Serial1
      Serial.begin(9600);
      Serial1.begin(9600);
      Serial1.print("c");
    }

    void loop() {
      if(Serial1.available()!=0)
      {
        Serial.write(Serial1.read());
      }
    }

My problem comes with the data that's being returned. The gas reading is present, but so is a lot of superfluous information that I don't need. According to the sensor's tech document, the information returned is: serial number, reading (ppb), temperature, humidity, raw voltages, and amount of time the sensor has been running for. In the serial monitor, it looks like this:

Right now, all I want is the reading in ppb (the second value), either as the only data coming through or being stored, so that it can then be used in calculations like averages per hour. The trouble I have is that this information appears to be coming through as a stream of individual bytes, and in this format I'm having difficulty working out an effective way to specify which information I want to store, and which I want to ignore.  I've been trying, for example, to come up with a way to specify that the first 14 bytes (serial number, comma, space - as this will always be the same length) should be ignored, and then the next series (up until the next comma - as this reading could be 4-6 digits) be stored as an int, or something, but I just can't seem to get anywhere no matter what I try. Does anyone have any suggestions?


texts: Local variable usage in SRAM not counted

texts:
I use the following code to print the currently used SRAM space:

// this function will return the number of bytes currently free in RAM
// written by David A. Mellis
// based on code by Rob Faludi http://www.faludi.com

#include "TypeDefs.h"

int availableMemory()
{
  extern int __heap_start, *__brkval;
  int v;
  return (int) &v - (__brkval == 0 ? (int) &__heap_start : (int) __brkval);
}

int printAvailableMemory(uint32 location)
{
  Serial.print(F("Available Memory at "));
  Serial.print(location);
  Serial.print(F(": "));
  Serial.println(availableMemory());
}

My main application (stripped) looks like:

...
void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  printAvailableMemory(1);

  printAvailableMemory(2);

  test();
  printAvailableMemory(3);
}

void test()
{
  Preferences _prefs2;
  _prefs2.Set();
  printAvailableMemory(4);
}

While preference (.h) looks like:

#include "TypeDefs.h"

class Preferences
{
   private:
      uint8 _startChannel;
      uint8 _endChannel;
      uint8 _startNote;
      uint8 _endNote;
      uint8 _startCc;
      uint8 _endCc;
   ...
};

The output is:

Available memory at 1: 1065
Available memory at 2: 1065
Available memory at 4: 1065
Available memory at 3: 1065

I would expect the numbers (1065) would change, since a local variable (_prefs2) is made so at location 4 I would expect more space to be used.

Also, if I remove the _prefs2 code like below, the numbers stay the same.

void test()
{
    printAvailableMemory(4);
}

Why is the local variable not counted?


texts: Storing data from Arduino without Serial print- High Sample rate

texts: For my work, I need to acquire data at a high sample rate (>100kSa/sec) using Arduino Portenta H7, which has 3 X 16-bit ADCs. Portenta H7 has STM32H747XI microcontroller. I don't want to use Serial.print command as I came to know that this command takes much time to execute, which makes achieving the targeted sample rate impossible.  What are the other possible ways to store the data from Arduino while maintaining this high sample rate? For example, saving the data and then printing them all at once at the end of testing( 3-5 second testing period). e.g. using an SD card or through saving in Arduino internal memory? Can you suggest techniques employed for high-sample rate data acquisition from Arduino?


texts: Can I use an external power supply and still communicate with my computer over Serial?

texts:
I read the following online:
If you plug in both USB power (say from a pc) and external power via the 2.1mm jack, the Arduino chooses power source automatically.

If the external 2.1mm DC is providing greater than 6.6V, the Arduino will take power from it instead of the USB.

Firstly, is this accurate?

Secondly, my real question:
If I am powering my Arduino via external DC, can I still communicate with my Raspberry Pi using serial via the USB?


texts: How to access parse cloud functions using arduino?

texts:
I have created rest service using .js file on Parse.com.
I want to access cloud function from arduino.

i tried this

client.get(https://myAppID:javascript-key=myJavaScriptKey@api.parse.com/1/functions/hello");

i am getting error "Method not allowed".

Solution :
Somehow i got the answer which is as follows.I hope it will help others.

 ParseCloudFunction cloudFunction;
 cloudFunction.setFunctionName(function_name);  //string ("hello")
 cloudFunction.add("light_sensor", light); //pass parameter to cloud

 ParseResponse response = cloudFunction.send();
 Serial.println(response.getJSONBody());


texts: Can we have 2 HC12 on a single Arduino (1 to receive and other to transmit)?

texts:
I'm working on a project and I need to send 2 datas and receive them at the same time.
My question is: Is it possible to have 2 Arduinos both have 2 HC12 (total 4), because I want each Arduino to send and receive data at the same time.
It's hard for me to have 4 Arduinos.


texts: Why is my boards.txt file not being found?

texts:
I'm using the ino command line tool for the first time. When attempting to build my first sketch I run:
ino build in the project directory.

I get the following error:

Searching for Board description file (boards.txt) ... FAILED
Board description file (boards.txt) not found. Searched in following places:
  - /Applications/Arduino.app/Contents/Resources/Java/hardware/arduino
  - /usr/local/share/arduino/hardware/arduino
  - /usr/share/arduino/hardware/arduino

What's going wrong here?

I've found an open issue here: https://github.com/amperka/ino/issues/240
But I'm wondering if anyone has a workaround.


texts: Redirecting Arduino Serial Output to a File

texts:
I am integrating the MPU-6050 Accelerometer + Gyro sensor into a large project that contains 12 Arduino boards and 6 Raspberry Pis. At some point, I will have to load the output of my MPU-6050 sensor into another application through command line. The process is to be all done with Python and Bash (on the Raspberry Pi side), and so what I need is a way to store the output of my Arduino boards.

What I am currently looking at is the python program ino. I have used the product for about a year now, and as far as I am aware of, the only way to exit out of serial mode in ino is by closing the command-line window!

Is there a way I can achieve what I've discussed above? Essentially, all I want is a way to hold the output of my Arduino serial output so I can use it later in other parts of my project.


texts: Read ISO/IEC 14443B (NFC Type B) with PN532

texts:
I bought a PN532 from Elechouse (documentation here) because I need to read IDs from Type B NFC cards.

My problem is that even if they say the hardware supports Type B, the official libraries an examples they provide are not made to.

I have not problem reading Type A cards, but nothing happends when I tap Type B cards.

After long searchs on internet I found that absolutely every PN532 sellers have chosen to support only Type A cards in their libraries because according to them, a librari supporting both types would have taken too much space in Arduino's memory.

So today my problem is as simple as that: how to read Type B NFC cards using PN532 on an Arduino UNO?

I'm a bit new in Arduino so after many hours of searching and trying I couldn't figure out how to do it.


texts: Where is the documentation for the Emoro GLAM pro module?

texts:
My 11-year-old son recently brought out an Emoro robot he got for his birthday. We had some temporary confusion with the robot, but got it to work.
He is now trying to connect to his computer via Bluetooth from the Emoro, but cannot find any documentation on Emoro Bluetooth.

Where is the documentation for Emoro Bluetooth?


texts: Arduino to Arduino Communication using HC05

texts:
I have been working on a project for work ( I'm a waiter :/ ) I was tasked to build a food wait time display that receives input from the kitchen and echoes the time via bluetooth to another display.
So that we are all on the same page I will describe what I have built and where I am stuck.

Before I do, I would like to state that I have:

been planning and prototyping this thing for over a month
googled/crawled all over the web looking for answers
read the entire manual on the HC05 module
Bound both of the bluetooth modules via AT commands One as Master the  other as Slave

Now with that out out the way here is what I have so far:

2x Arduino uno R3
2x 16x2 LCD Display
2x HC05 Bluetooth Modules (1 set as Master the other as Slave & bound using AT Commands)
2x 10K Potentiometers for adjusting the contrast
3x Momentary push Button switches on Master with pull-up resistors (timeUp, timeDown, sendButton)

Here is where I am stuck. UPDATE

I was able to get the master and slave to communicate. RX and TX on master were crossed... SMH! However now the issue is that the slave is writing both digits it receives on top of itself. First writing one digit then clearing it and then the second digit...

Enough with the prologue here is the a code:

Master

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2); //sets up LCD pins
int waitTime = 10; //if food comes quicker than there is no need for a display ;)
const int timeUp = 6;
const int timeDown = 7;
const int sendButton = 8;
int timeUpState = 0;
int timeDownState = 0;
int sendButtonState = 0;

void setup() {
  Serial.begin(115200);
  pinMode(timeUp, INPUT);
  pinMode(timeDown, INPUT);
  pinMode(sendButton, INPUT);
  lcd.begin(16, 2);
  lcd.print("  Sam Kullman's"); //Splash screen on start up
  lcd.setCursor(0,1);
  lcd.print("      Diner"); //Splash Screen
  delay(2000);        // Delay intended to allow the device to pair prior to use.
  lcd.clear();
  lcd.print("Essen Dauert:"); //German for "Food takes":
  lcd.setCursor(0,1);
  lcd.print("   Minuten"); // xx minutes
  }

void loop(){
  lcd.setCursor(0,1);
  timeUpState = digitalRead(timeUp);
  timeDownState = digitalRead(timeDown);
  sendButtonState = digitalRead(sendButton);
  if (timeUpState == LOW) {
  waitTime += 5;
  delay(500);  //debounce button
  lcd.print(waitTime);
  }

  if(waitTime > 90){ // Max limit for wait time
    waitTime = 10;   //default wait time
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Essen Dauert:");
    lcd.setCursor(0,1);
    lcd.print("   Minuten");
   }

 if (timeDownState == LOW){
  waitTime -= 5;
  delay(500);
  lcd.print(waitTime);
  }

  if(waitTime < 10){ //Min value waiting time
    waitTime = 10;
    lcd.clear();
    lcd.setCursor(0,0);
    lcd.print("Essen Dauert:");
    lcd.setCursor(0,1);
    lcd.print("   Minuten");
   }

  if(Serial.available()){  // **This is where I am stuck**
   if(sendButtonState == LOW){
   Serial.write(waitTime);
   delay(500);
  }
 }
}

Slave

#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  Serial.begin(9600);
  Serial.flush();
  lcd.begin(16, 2);
  lcd.print("  Sam Kullman's");
  lcd.setCursor(0,1);
  lcd.print("      Diner");
  }

void loop(){

  if (Serial.available()) {
   int waitTime = Serial.read();
    delay(200);
    lcd.clear();
    lcd.print("Essen Dauert:");
    lcd.setCursor(0,1);
    lcd.write(waitTime);
    lcd.print(" Minuten");
     }
  }

Thanks in advance,
Jonathan


texts: Arduino ESP8266 Ticker interrupted by DallasTemperature/OneWire?

texts:
I have been using the Ticker to blink a led successfully.
However, now I am fetching temperature from a DS18B20 in the main loop (which is using the OneWire library) and the blink is now erratic.

Is the Ticker suspended by the DallasTemperature/OneWire library?

It this suspending interrupts or something?

Maybe using the same interrupt?


texts: Extend program space by getting rid of bootloader on NANO

texts:
I just have a complex program that runs on a NANO. Now when I use my printlns for debugging I am running out of memory.
I read about using a programmer to get rid of the bootloader that uses 2K space on a NANO. I bought an USBTinyIsp and got it to work successfully... almost I can program the nano as I wanted, but I do not get any additional space.
When programming with debug printlns I run into the same message as before which states the same maximum space within (I guess it was 30700).
Why is this the case? I thought the bootloader gets overridden when using a programmer and so frees 2K of programmable space.
Please note: I am not asking how to optimize my program code! Thank you for taking notice ;)
Thank you very much.


texts:
When I was programming an arduino uno with atmel studio via usb cable, everything worked fine. Now I am trying to upload a code via usbasp programmer, it works, whereas arduino keeps restarting and L labelled pin flashes even when I have not activated it by code. After a bit searching I've found that,I should unprogram watchdog timer by adding this command:

C:\Users\Eldar>avrdude -c usbasp -p m328 -P COM5 -b 19200 -U lfuse:w:0xEF:m -U hfuse:w:0xD9:m
output of that:

 avrdude: warning: cannot set sck period. please check for usbasp firmware update. avrdude: AVR device initialized and ready to accept
    instructions Reading |
    ################################################## | 100% 0.03s avrdude: Device signature = 0x1e950f avrdude: reading input file
    "0xEF" avrdude: writing lfuse (1 bytes): Writing |
    ################################################## | 100% 0.01s avrdude: 1 bytes of lfuse written avrdude: verifying lfuse memory
    against 0xEF: avrdude: load data lfuse data from input file 0xEF:
    avrdude: input file 0xEF contains 1 bytes avrdude: reading on-chip
    lfuse data: Reading |
    ################################################## | 100% 0.01s avrdude: verifying ... avrdude: 1 bytes of lfuse verified avrdude:
    reading input file "0xD9" avrdude: writing hfuse (1 bytes): Writing
    | ################################################## | 100% 0.02s
    avrdude: 1 bytes of hfuse written avrdude: verifying hfuse memory
    against 0xD9: avrdude: load data hfuse data from input file 0xD9:
    avrdude: input file 0xD9 contains 1 bytes avrdude: reading on-chip
    hfuse data: Reading |
    ################################################## | 100% 0.02s avrdude: verifying ... avrdude: 1 bytes of hfuse verified avrdude:
    safemode: Fuses OK avrdude done.  Thank you.

I changed  0xD9 to 0xC9 but it`s still the same.Moreover,when i try to program arduino with usb cable again,avrdude gives this error:

avrdude.exe: stk500_getsync(): not in sync: resp=0x00
avrdude.exe done.  Thank you.

This is my code that I try to upload just for testing

#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
int main(void)
{
    DDRD |= 0B11111111;
    DDRB |= 0B11111111;
    while(1)
    {
    PORTD |= 0B00110000;
    PORTB |= 0B00110000;
    _delay_ms(1000);
     PORTD ^= 0B00000000;
     PORTB ^= 0B00000000;
    }
}

Ive also tried unprogram watchdog timer inside the program itself,its still the same.There are attempts below.
Attempt1

#define F_CPU 16000000UL
    #include <avr/io.h>
    #include <util/delay.h>
    #include <avr/wdt.h>
     int main(void)
    {
    MCUSR = 0;
    wdt_disable( );
     while(1)
     {
        //nothing
     }
     }

Attempt2

#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <avr/wdt.h>
 int main(void)
{

    wdt_reset();
     MCUSR=0;
     WDTCSR|=_BV(WDCE) | _BV(WDE);
     WDTCSR=0;
     while(1)
     {
        //nothing
     }
     }

Also,why it does not work when i configure the chip with avrdude directly via command line either?


texts: Serial communication between two microcontrollers w/ separate power supplies

texts:
Fair warning: I'm an electronics n00b.

I'm trying to get an Arduino Uno R3 to send data over 9600 baud serial to a Wemos D1 Mini Pro.

What worked (mostly):

Powering (5V) Arduino off a 4 AA barrel jack battery pack.  Measured voltage between Vin and GND as ~4.5V (the batteries were somewhat old).  4.5V is low enough to be safe as 5V input for the (3.3V) Wemos, which can be powered off its 5V pin (it's the input to the board's 3.3V regulator).  I tied the Arduino's GND and Wemos's, took the Arduino's Vin pin to Wemos's 5V pin (providing it ~4.5V), and connected Arduino's TX to Wemos's RX via a voltage divider (a 2.2 kΩ resistor and a 4.7 kΩ; verified <3.3V with a multimeter).

And, everything worked, for a few brief, glorious minutes.  Arduino sent 1 byte over serial every 3 seconds, alternating the builtin LED each time.  Wemos read them and served up a web page showing the latest values.  But, after a few minutes, the Wemos started to read data the Arduino shouldn't be sending (0x00 bytes; the Arduino program was only sending uppercase ascii letters).  I noticed that the Arduino builtin LED, that's supposed to be alternating every 3s, was blinking rapidly.  I think I drained the batteries too far to provide both the Wemos and the Arduino with enough power, and the Arduino got stuck in a boot cycle (and I suppose it's sending 0x00 over its TX pin while booting).

What didn't work:

Since changing batteries frequently would be a pain, I tried plugging the Wemos into a micro USB wall adaptor, and the Arduino into a 12V 1A barrel jack wall wart, and unplugging Arduino's Vin from Wemos's 5V (leaving GND tied together).  Plugged both adaptors into a single power strip, and turned it on.  Both boards powered up, and were running their programs (I could connect to the Wemos over WiFi and it would serve me a page; the Arduino builtin LED was alternating every 3 seconds as expected).  A multimeter read the voltage between Wemos RX and GND as 3.34V, but the Wemos wasn't receiving any serial data.

After that experiment, I switched back to the battery pack, wired Arduino Vin to Wemos 5V again, swapped out 2 of the 4 batteries, and everything works.

TLDR:

I powered a 5V Arduino off 12V and a 3.3V Wemos off 5V, and the Wemos couldn't read serial data being transmitted by the Arduino.  When I powered them both off a 4.8V battery pack, everything worked.  Why didn't it work when they had separate supplies and a common ground?

Sorry for the wordy question; I'm confused enough to not know which details are relevant!


texts: Using Arduino libraries with ARM based microcontroller

texts:
A week ago I started messing with LoRa. I got my STM32L151 IM880A kit.

Company that provided SX1272 LoRa modem chip (used in kit), provided some libraries, but lots of functionalities are still not implemented and is still not suitable for use in multi P2P aplications.

After googling I came across Libelium company which used SX1272 chip in their products design and they provided useful set of libraries that provides lots of functionalities and also implements some sort of LoRa frame protocol stack ideal for use in P2P applications.

The problem is that I'm using STM32 in my project and Libelium libraries are written for Arduino. So I was wondering if there is a smart way to port Arduino libraries so I could use them in my STM32 Keil projects, since the libraries seems huge.

Tips, hints, links would be appreciated (I don't have experience in using Arduino and I'm not familiar with Arduino library structure).


texts: Wemos mini pro switch power from servo with mosfet bs170

texts:
I got a servo connected to a wemos/arduino with a capacitor(470uf). Before I didn`t use a cap.

Now with the cap the device use to much power while sleeping(capacitor on the servo). I want to switch off the power to the servo with a MOSFET. I tried this with a BS170 N channel MOSFET. There is a youtube movie with the same settings except for the mainboard. They use an Arduino uno instead a wemos.

When I test the circuit with a led everything is working. When I use a servo instead a led, nothing happen. There is a little sound from the servo(I think not enough voltage).

When I check the voltage without anything hooked on the drain of the mosfet the output is perfect(5V). If I connect a led or a servo the voltage will drop to 3v.

Wemos mini pro has 3.3v output on the gpio pins.

Can someone explain me what I doing wrong? I saw and read some articles about Mosfet. I think it`s not clear enough for me.


texts: Trouble with Arduino Nano Every and radio transmission using RH_RF69.h

texts:
I give some help for students working on the Cansat Contest.
I am trying to connect a RFM69 Radio Module to an Arduino Nano Every.
Nothing works : compiling the simpliest program:
#include <RH_RF69.h>

void setup() {}

void loop() {}

gives the answer:
[BlaBlaBla...]
exit status 1
Erreur de compilation pour la carte Arduino Nano Every

while everythings works on arduino M0 Feather Express or Arduino Uno.
Is there a specific problem with the Nano Every?
Thank you for your help.
Jean-Luc Ottinger


texts:
My circuit:

My code:

// Pin 13 has a LED connected on most Arduino boards.
// give it a name:
int led = 13;
const int buttonPin = 2; // pushbutton connected to pin 2.

// the setup routine runs once when you press reset:
void setup() {
  // initialize the digital pin as an output.
  pinMode(led, OUTPUT);
  pinMode(buttonPin, INPUT);
}

// the loop routine runs over and over again forever:
void loop()
{
  bool buttonState = digitalRead(buttonPin);
  while (buttonState == HIGH) // check while the button is pressed
  {
   digitalWrite(led, HIGH);   // turn the LED on (HIGH is the voltage level)
   delay(1000);               // wait for a second
   digitalWrite(led, LOW);    // turn the LED off by making the voltage LOW
   delay(1000);               // wait for a second
  }
}

What I wish to do is that when I press the button, the Led's start flashing and when I press them again, they stop blinking (like a fire alarm). Right now they do nothing and I dont know why. Is it something with the circuit or the code?


texts: I2C communication between Arduino Due and Nano

texts:
I'm trying to communicate between two Arduino Due and Nano. Nano as Master and Due as a slave. As given in the library description Wire Lib

When the master request for data from the slave, first it goes to Request ISR. Wire.onRequest(requestEvent)    But when compile the program for Arduino Due I get following errors.

In file included from C:\Users\\Slave_Test3.ino:14:0:

C:\Users\..\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.11\libraries\Wire\src/Wire.h:59:7: error:   initializing argument 1 of 'void TwoWire::onRequest(void (*)())' [-fpermissive]

 void onRequest(void(*)(void));

       ^

But If I change from Arduino Due to any other board this error does not come.

Thank you


texts: I'm running a pretty basic setup. When I run a small program just doing some serial.println, it works fine, when I try to do operations that needs more power, the brownout detector gets triggered. I'm running my chip on an ok buff power supply so I don't get what the problem is.


texts:
void setup() {
  Serial.begin(9600);
  setupPWM16();
}

uint16_t icr = 0xffff;

void loop() {
  analogWrite16(9, 0);
}
void setupPWM16() {
  DDRB  |= _BV(PB1) | _BV(PB2);       /* set pins as outputs */
  TCCR1A = _BV(COM1A1) | _BV(COM1B1)  /* non-inverting PWM */
        | _BV(WGM11);                 /* mode 14: fast PWM, TOP=ICR1 */
  TCCR1B = _BV(WGM13) | _BV(WGM12)
        | _BV(CS10);                  /* prescaler 1 */
  ICR1 = icr;                         /* TOP counter value (freeing OCR1A*/
}

/* 16-bit version of analogWrite(). Works only on pins 9 and 10. */
void analogWrite16(uint8_t pin, uint16_t val)
{
  switch (pin) {
    case  9: OCR1A = val; break;
    case 10: OCR1B = val; break;
  }
}

Using the code above I can achieve 16 bit PWM signal, but when writing 0 in analogWrite16 it output ~33mV. I know that I can set the PWM pin low but yet again it don't output 0V.

I'm guessing beside the ATMEGA offset the Arduino UNO board it self ground is raised either because it's being fed from USB or the board circuitry and PCB traces resistance. or both?

because ~33mV offset is a lot, is it normal?

How can I make Arduino to start at 0V or at least reduce that 33mV offset to 1-2mV?


texts: Problem communicating between arduino UNO R3 and Mega 2560 via MAX485

texts:
I want to send data between Arduino Uno and Mega via MAX485.

When I set the data Enable pin to HIGH on Mega (to transmit data) and set the same pin on UNO to LOW (to receive data) I can read data from Mega into Uno properly. However, when I want to do it vice versa (send data from uno to mega) can't get any data from Uno into Mega. Tried different pins on both boards but still no answer.

This problem happens when I want to change data Enable pins to low or high inside loop(), I mean when I use for example Uno as permanent master and mega as permanent slave, it works properly but when I try to change them from slave to master on runtime, data cannot be sent from uno to mega!

PS: Im newbie on RS485 and MAX485. Here is my code in MEGA side:

#include <SoftwareSerial.h>'
SoftwareSerial mySerial(2, 3);
String inputS = "";
boolean stringComplete = false;
int i = 0;
bool b= false;

void setup() {
  mySerial.begin(9600);//Using SoftwareSerial Port
  Serial.begin(9600);
  pinMode(8, OUTPUT);//DE/RE Controling pin of RS-485
  digitalWrite(8, HIGH);//DE/RE=HIGH Transmit Enabled M1
}

void loop() {
  mySerial.println("MEGA:Hi");
  Serial.println("Hi Sent");
  digitalWrite(8, LOW);
  CheckAndReceive();
  if(stringComplete)
  {
  stringComplete = false;
  inputS.trim();
  Serial.print(inputS);
  Serial.println(": " + String(i++));
  inputS = "";
  }
  digitalWrite(8, HIGH);
    delay(1000);
}

void CheckAndReceive()
{
  while (mySerial.available()) {
    // get the new byte:
    char inChar = (char)mySerial.read();
    // add it to the inputString:
    inputS += inChar;
    // if the incoming character is a newline, set a flag
    // so the main loop can do something about it:
    if (inChar == '\n') {
      stringComplete = true;
    }
  }
}

This code is supposed to send a string to UNO and listen to it.

UPDATE:
UNO cannot send data to MEGA at all. I think there is a problem with my UNO


texts: Is there a simple HTTP(S) library that doesn't rely on WiFi?

texts:
I'm trying to implement a Mobile Network (only) for the ESP32 using Arduino IDE. So to be able to connect to website up/download files etc. I need to be able to handle various HTTP PUT/GET/POST requests. However, the available libraries seem to always rely on additional WiFi related libraries. I don't want to have to load those as well, as they are quire bloated and not needed for my use scenario.

What options do I have for minimalist HTTP request libraries that does not rely on WiFi or BT or ETH?


texts:
I have an android device and stm32f103 + HC-05 bt dongle. I'm sending 10 bytes "0123456789" string from android to stm32, but I'm receiving only random 1-5 bytes. code on stm32 side:

long received = 0;
const unsigned long buffer_size = 128;
uint8_t buffer[buffer_size];

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

[...]
void loop() {
    [...]
    if(Serial1.available()){
        received += Serial1.readBytes(buffer + received, bufferSize-received);
    }
}

So, if will send "0123456789" from android, let say, 3 times every 1 second, on stm32 i will receive 3 portions like this:

"0", "0567", "047"

or something like this, i.e. I always receive first byte and it's always correct, but it looks like the rest bytes could be randomly lost.

any idea what am I doing wrong?

P.S.> On stm32 side I'm using Arduino STM32 library. Serial1 is a UART interface, which is located on stm32f103's PA9 and PA10 pins.

I tried to use other bod rate (19200, 38400), but in this case the data is completely corrupted, i.e. just random bytes.

When I'm sending data from stm32 to Android everything works just fine, i.e. I'm receiving all the data on android side.

I'm using standard BluetoothSocket on android side. So, code looks like this:

BluetoothSocket socket;
OutputStream outStream;
[...]

void init(...) {
    socket = ConnectToSTM32(...);
    [...]
    outStream = socket.getOutputStream();
}

void send(byte[] bytes) {
    outStream.write(bytes);
}

[...]
String strToSend = "0123456789";
send(strToSend.getBytes());


texts: Can anyone explain how to use MPL sensor with Arduino MEGA?

texts:
I am trying to connect a MPL3115A2 Altitude/Pressure/Temp Sensor Breakout which I bought from Hobbytronics to my Arduino Mega. What I had in mind was (Breakout -> Arduino):

3.3V -> 3.3 V
GND -> GND
SDA -> A4
SCL -> A5

The information which I've found so far is very conflicting and I'm not sure whether or not I should be using pull-up or in-line resistors, and if so, what value?

The code which the product page links to also differs, with one stating that the Wire library is unsafe to use with a 3.3V rated sensor due to the internal pull-ups, but the other code uses the Wire library?

If anyone could advise me on how best to use this sensor without frying it, it would be much appreciated!

Product information
Code


texts: Controlling stepper motor direction with push buttons

texts:
I'm trying to control the direction of three 28byj-48 stepper motors using the ULN2003 drivers. I am using 6 push buttons, 2 for each motor. what I want is for each motor to be stationary by default and rotate forward when I press on one button and reverse when I press the other.

You can find my code below. When I use the same approach for coding for one motor, it works fine with a suitable speed. But once I add all 3 motors, motor A and C perform fine but with low speed, motor B keeps rotating forward from the start, stops while I'm pushing its forward button and nothing happens when I push its reverse button. I have checked my circuit several times and there's nothing wrong with it.

#include <Stepper.h> //including stepper motor library

//defining pins section

// pins for motor A:
int stepAIN1Pin = 5;
int stepAIN2Pin = 4;
int stepAIN3Pin = 3;
int stepAIN4Pin = 2;

// pins for motor B:
int stepBIN1Pin = 9;
int stepBIN2Pin = 8;
int stepBIN3Pin = 7;
int stepBIN4Pin = 6;

// pins for motor C:
int stepCIN1Pin = 13;
int stepCIN2Pin = 12;
int stepCIN3Pin = 11;
int stepCIN4Pin = 10;

int stepsPerRevolution = 2048; // amount of steps per revolution for the 28BYJ48 motor

int buttonA1Pin = A5;  // pushbutton 1 pin for clockwise rotation of motor A
int buttonA2Pin = A4;  // pushbutton 2 pin for counter clockwise rotation of motor A

int buttonB1Pin = A3;  // pushbutton 1 pin for clockwise rotation of motor B
int buttonB2Pin = A2;  // pushbutton 2 pin for counter clockwise rotation of motor B

int buttonC1Pin = A1;  // pushbutton 1 pin for clockwise rotation of motor C
int buttonC2Pin = A0;  // pushbutton 2 pin for counter clockwise rotation of motor C

Stepper myStepperA(stepsPerRevolution, stepAIN1Pin, stepAIN3Pin, stepAIN2Pin, stepAIN4Pin); // stepping sequence for motor A

Stepper myStepperB(stepsPerRevolution, stepBIN1Pin, stepBIN3Pin, stepBIN2Pin, stepBIN4Pin); // stepping sequence for motor B

Stepper myStepperC(stepsPerRevolution, stepCIN1Pin, stepCIN3Pin, stepCIN2Pin, stepCIN4Pin); // stepping sequence for motor C

void setup()
{
  // Setting up the pushbutton pins to be an input:
  pinMode(buttonA1Pin, INPUT);
  pinMode(buttonA2Pin, INPUT);

  pinMode(buttonB1Pin, INPUT);
  pinMode(buttonB2Pin, INPUT);

  pinMode(buttonC1Pin, INPUT);
  pinMode(buttonC2Pin, INPUT);

myStepperA.setSpeed(15); // Setting the speed for motor A

myStepperB.setSpeed(15); // Setting the speed for motor B

myStepperC.setSpeed(15); // Setting the speed for motor C
}

void loop()
{

int buttonA1State, buttonA2State, buttonB1State, buttonB2State, buttonC1State, buttonC2State;

  buttonA1State = analogRead(buttonA1Pin);
  buttonA2State = analogRead(buttonA2Pin);

 if ((buttonA1State != 0) && !(buttonA2State != 0))  // if we're pushing button 1 and NOT button 2
  myStepperA.step(stepsPerRevolution/8);

 if (((buttonA2State != 0) && !(buttonA1State != 0)))  // if we're pushing button 1 and NOT button 2
  myStepperA.step(-stepsPerRevolution/8);

  buttonB1State = analogRead(buttonB1Pin);
  buttonB2State = analogRead(buttonB2Pin);

 if (((buttonB1State != 0) && !(buttonB2State != 0)))  // if we're pushing button 1 and NOT button 2
  myStepperB.step(stepsPerRevolution/8);

 if (((buttonB2State != 0) && !(buttonB1State != 0)))  // if we're pushing button 1 and NOT button 2
  myStepperB.step(-stepsPerRevolution/8);

  buttonC1State = analogRead(buttonC1Pin);
  buttonC2State = analogRead(buttonC2Pin);

 if (((buttonC1State != 0) && !(buttonC2State != 0)))  // if we're pushing button 1 and NOT button 2
  myStepperC.step(stepsPerRevolution/8);

 if (((buttonC2State != 0) && !(buttonC1State != 0)))  // if we're pushing button 1 and NOT button 2
  myStepperC.step(-stepsPerRevolution/8);

  }


texts: Why does Arduino IDE take so long to open?

texts:
I have Arduino IDE, version 1.8.10 (Windows 10 x64, 8GB RAM, i5-7200 @2.5GHz) on a network drive mapped to D:, on a 100Mbit wired network and fast file server.

If I navigate to the network shared folder and launch 'arduino.exe', it takes at least 2 minutes for the IDE to appear.

This seems totally unreasonable considering the entire arduino.exe file is only 395kB. Seems more likely the IDE is waiting for something until a timeout occurs, before finally loading up the IDE.

What can be causing this and how can I diagnose it?

As an aside, it seems the compilation process takes longer than it should too, even for programs that use no external libraries and are very short.


texts: Controlling 12v DC LED strips using Arduino UNO

texts:
I have 2 LED strips with 6 LEDs on each. They use a 12V power supply.

My question, how can I use them like regular LEDs using Arduino UNO? Without any MOSFETS or transistors if possible.

And can I use PWM?


texts:
I am trying to code something for fun using an Arduino Due and a LED matrix. The led matrix has a backpack controller. This device is using SPI. So I connect MOSI and SCLK to their respective pins and SS to pin 10 on the Due. So far so good.

The problem I have is that when i run my rudimentary code nothing happens.
this is the current code I am using. I thought this should be enough, but it clearly isn't.

#include <SPI.h>
void setup() {
  SPI.begin(10);
  SPI.transfer(10, 0x26, SPI_CONTINUE); //setup the matrix
  for (int i = 0; i<64; i++){
    SPI.transfer(10, 0x00, SPI_CONTINUE); //set all pixels to black...
  }
}

Output:

 Erase flash
 Write 10444 bytes to flash
 [                              ] 0% (0/41 pages)
 [=======                       ] 24% (10/41 pages)
 [==============                ] 48% (20/41 pages)
 [=====================         ] 73% (30/41 pages)
 [============================= ] 97% (40/41 pages)
 [==============================] 100% (41/41 pages)
 Verify 10444 bytes of flash
 [                              ] 0% (0/41 pages)
 [=======                       ] 24% (10/41 pages)
 [==============                ] 48% (20/41 pages)
 [=====================         ] 73% (30/41 pages)
 [============================= ] 97% (40/41 pages)
 [==============================] 100% (41/41 pages)
 Verify successful
 Set boot flash true
 CPU reset.

So my question is: am I doing something wrong? what?
Or is the Led matrix broken?

Hoping for good answers.
regs
KB


texts:
I want to create a system that will detect illegal parking. I will place the sensor s to specific locations and when a car parks there the system will send a message to local authorities. My question is if a PIR is the suitable sensor for this project.

thanks in advance.


texts: Best practise when dynamically updating sketch

texts:
I am currently working on a project that uses an Arduino Mega 2560 board along with the Arduino GSM shield to connect to the internet and send/receive SMS messages.

As part of my project, I want to be able to update the software that I am running dynamically. At a high level, I want to connect to my server, check if there is an update, if there is, download it and then overwrite the current sketch to run the new downloaded binary if the checksum of the downloaded binary is as expected (to avoid corruption).

Now, I am new to Arduino programming, so I figured I would ask a community of people with experience to determine the best method.

My current ideas are as follows:

Writing a custom bootloader - The sketch will have an update routine that downloads the new binary to a known location, and then performs a system reset. The bootloader will then overwrite the current sketch with the downloaded binary and then run the sketch.
Overwriting the sketch whilst running - I'm not sure of the viability of this method, but the overall method would be to write an update routine to the end of flash memory, and in this code simply overwrite all of the non-bootloader code with the new sketch.

Are these methods both viable, if so, is there one that would be preferable to another? If not, are there any known solutions to this problem?


texts: Using Capacitance-to-Digital converters AD7150 or AD7747 to measure fluid levels

texts: I'm looking to measure the fluid inside a polyethylene waste holding tank with walls 10 mm thick. This is typical of a boat or RV. I'd like to measure using proximity sensing capabilities of Capacitance-to-Digital converters, which have no direct contact with liquid, are highly accurate and have low current requirements. Analog Devices makes two sensors, AD7150 and AD7747 that might work based on the specs I've read, but I don't know if they'll measure through the holding tank walls. If anyone knows if either of these would work, or has any other suggestions I'd appreciate your advice. Thanks.


texts:
Problem:

I have an HDMI switch that is controllable via RS232

Scenario 1:

Setup: PC connected to HDMI switch using USB -> serial adapter
Test: Opening PuTTY on COM port and sending command "sw i01" from my PC
Results: HDMI switch input changes to port 1 [Good]

Scenario 2:

Setup: Arduino UART port connected to TTL->RS232 adapter connected to serial->USB adapter connected to PC with PuTTY program open on COM port
Test: Sending command "sw i01" from Arduino to PC using code below
Results: "sw i01" prints repeatedly on the Putty terminal [Good]

Scenario 3:

Setup: Arduino UART port connected to TTL->RS232 adapter connected to HDMI switch serial port
Test: Sending "sw i01" from Arduino repeatedly to HDMI switch using code below
Results: HDMI port does not switch from port2 to port1 [Bad]

Hardware:

Intel Galileo Gen 2
SparkFunRS232/TTL Shifter connected to Galileo UART
HDMI switch is IOGear GHSW8141

Code:

[Note: Galileo Gen 2 requires Serial1 for UART communication]

void setup() {
    Serial1.begin(19200);
}

void loop() {
    Serial1.print("sw i01");
    Serial1.write(13);    // CR
    Serial1.write(10);    // LF
    delay(1000);
}

Question:

It seems like Scenario 1 and 2 confirm that the Arduino->HDMI switch communication should work, but it doesn't. Am I missing something regarding physical connectivity? Does manually typing "sw i01" in PuTTY send different commands than I have in the Arduino code?


texts:
For some reason, my 3.3v on my Arduino is fluctuating a lot, and I am not sure why.
The multimeter is measuring dc voltage and is connected between GND and 3.3v of an Arduino Mega.

The multimeter works fine. Connecting between 5v and GND gives 5V on multimeter.


texts: Confusion over Transistors for a switching circuit with an Arduino Mega 2560

texts:
Apologies if this is a stupid question asked by a noob, but I've looked around to try and find the answer and just can't work it out.

Basically, I'm making a project on thingiverse (Glitch's MK2 Stargate), and I've tried all sorts of different transistors with my circuit, I just can't get it to work properly.
Could you please advise which Transistor would work for the following circuit:

It's a basic thing, but the plan I was originally working from on thingiverse called for BC548BU transistors, however, the LEDs they were using were surface mount, and I am trying the same thing with 3mm standard LEDs. The BC548BU didn't work right on the normal LEDs.

I'm a total noob with this, but I've been trying to match the Base pin on the Transistor voltage output of my Arduino, but not sure if I'm doing the right thing. Can anybody help?

Thanks
-Dave

p.s. I have a load of transistors already (listed below), if any of these work, that would be great, if not, I will order the correct ones. The only one that seemed to match Data with the BC548 is the S9014, but it didn't seem to work at all, unless my understanding of the wiring of Transistors needs adjustment.


texts:
I'm currently trying to integrate my ESP32 Module (as in https://cdn.instructables.com/FOL/YWLI/JEOILQ5U/FOLYWLIJEOILQ5U.LARGE.jpg) with Fingerprint Sensor(R307) using the Adafruit Fingerprint Library. While using the Enroll example from that library I commented out the SoftwareSerial part and enabled HardwareSerial Part from the code below, but still I keep getting message that it didn't Find fingerprint sensor

 #include <Adafruit_Fingerprint.h>

// On Leonardo/Micro or others with hardware serial, use those! #0 is green wire, #1 is white
// uncomment this line:
#define mySerial Serial1

// For UNO and others without hardware serial, we must use software serial...
// pin #2 is IN from sensor (GREEN wire)
// pin #3 is OUT from arduino  (WHITE wire)
// comment these two lines if using hardware serial
// SoftwareSerial mySerial(2, 3);

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);

uint8_t id;

void setup()
{
  Serial.begin(115200);
  while (!Serial);  // For Yun/Leo/Micro/Zero/...
  delay(100);
  Serial.println("\n\nAdafruit Fingerprint sensor enrollment");

  // set the data rate for the sensor serial port
  finger.begin(57600);

  if (finger.verifyPassword()) {
    Serial.println("Found fingerprint sensor!");
  } else {
    Serial.println("Did not find fingerprint sensor :(");
    while (1) { delay(1); }
  }
}

uint8_t readnumber(void) {
  uint8_t num = 0;

  while (num == 0) {
    while (! Serial.available());
    num = Serial.parseInt();
  }
  return num;
}

The rest of the code (Loop part)is same as given in example. What is the mistake I'm doing and help me in correcting it. Also point me on how to make circuit connections so that it will detect Fingerprint Sensor


texts: Bridging the wifi networks on nodemcu: how to set the esp8266 as wifi extender, simplest case

texts:
It seems to me that humidity is getting high in one room in the basement in my house. To monitor the situation temporarily, I would like to build a very small wifi-mesh network to exchange these humidity data to a locally installed raspberry pie server. Most of the time the networking would be in idle state, every some 5 minutes sending the humidity sensor data over mqtt to the server.

What is the simplest code that sets up an esp8266 to connect to an existing wifi network and act as an access point and wifi extender a couple of yards further?

I tried this code:

#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>

const char* ssid = "SSID_Internet";
const char* password = "qaz12345";

const char* newssid = "SSID_Extender";
const char* newpassword = "qaz12345";

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

  // set both access point and station
  WiFi.mode(WIFI_AP_STA);
  WiFi.softAP(newssid, newpassword);

  Serial.print(newssid);
  Serial.print(" server ip: ");
  Serial.println(WiFi.softAPIP());

  WiFi.begin(ssid, password);
  int wifi_it = 0;
  int wifi_status;
  while ((wifi_status = WiFi.status()) != WL_CONNECTED) {
    Serial.println("Trying to connect to wifi");

    wifi_it++;
    delay(500);
  }

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

  long rssi = WiFi.RSSI();
  Serial.print("Signal strength: ");
  Serial.print(rssi);
  Serial.println("dBm");
}

void loop(void){

}

It successfully registers the esp8266 to the wifi, sets up an AP, but if I connect to SID_Extender with my mobile phone, the internet traffic is not forwarded further.

There are projects that allows to configure multiple esps in user friendly manner, but I am wondering how to setup such an esp myself.


texts: Understanding the variation of Arduino's current consumption with respect to the voltage supply

texts:
Even though this is already a well-debated topic, I couldn't find an extensive discussion about what really is drawing so much power in Arduino's board.

Here is the preamble: I have an Arduino Mega 2560, I measured its power consumption in a steady state with just a red LED turned on with a 560Ohm series resistor.
The power supply (Vcc) was given to Arduino from the Vin pin and the measurement were as follows (below the schematic set-up):

30mA @Vcc = 5.2V;
65mA @Vcc = 8.3V.

What I would like to understand is:

From a hardware perspective, I don't see what is drawing all of this current in Arduino's board;
Why the current drawn from the power supply changes so much with the power supply's value (i.e. what part of the board changes its consumption with the power supply value);
It also seems that turning on an LED through a digital output of Arduino draws a higher current with a higher power supply (Vcc). Why is that?

Note that, by looking at the datasheet of the ATmega2560, the uC mounted on my Arduino, I saw that the current Icc drawn from the power supply is max 14mA (I suppose when no output is sourcing current, I couldn't find the test conditions, unfortunately). I thought the microcontroller was the major cause of power consumption, but it doesn't seem to be so!

Another thing I considered is the onboard LDO, but the input voltage should change the power dissipated by the LDO, not the current drawn from its output.

It's even more strange if you think that regardless of the Vin, all the electronics after the LDO is working at the same voltage.

EDIT1

After Majenko pointed out a big flaw in my set-up with his answer, I re-measured with Vcc = 12.1V and I measured approximately the same Icc observed at Vcc = 8.1V.
I completely agree with Majenko's answer and I would just like to go a bit more in details about what happens while the board is working under voltage.

Here is my analysis:

The minimum operating condition when supplied from Vin is 7V, and that's the "knee" point in Majenko's answer.

However, the maximum quiescent current of the LDO is 10mA, and the Icc of the ATmega2560 is 15mA, so even if we suppose they don't draw any current at Vcc=5.2V, and then draw 25mA together at the minimum operating voltage at 7V, this doesn't add up to the actual increase of 40 or 50 mA that Majenko calculated I observed from 5.2 to 8.3 (which should be the same as from 5.2 to 7V).

And we're not even taking into account that at 5.2V the micro is perfectly able to turn on and keep on the LED, so it's somewhat working and already drawing some current.

Other things that we can take into account, but don't change the facts, are:

a second LDO (LP2985) to generate the 3V3, whose quiescent current should be around 100uA since the circuit is not drawing any current from the 3V3.
a second microcontroller related to the USB programming, whose Icc may be up to 20mA but this one is OFF when supplying from Vin.  -->  Edgar Bonet correctly pointed out that this is not true!
Some voltage dividers and comparators.

So what is the cause of this increase in current consumption from 5 to 7V?


texts:
I'm trying to send data from my esp to my arduino using serial using the following codes :

esp :

server.on("/drive",HTTP_GET, handleDrive);
void handleDrive()
{
    server.send(200,"text/html", "Drive!");
    String sendToArduino = "";
    for (int i=0;i<server.args();i++)
    {
   sendToArduino = sendToArduino+server.argName(i)+"="+sendToArduino.arg(i)+"&";
    }
    Serial.println(sendToArduino);
}

and on arduino :

Serial.begin(9600);
esp8266.begin(115200);

if (esp8266.available())
{
   String  readString="";
   while (esp8266.available())
   {
     delay(2);
     char c = esp8266.read();
     readString += c;
   }
}

but when i send data from esp to arduino i get it with "noise"

Ex : "variable1=1234"   i recive it on arduino "variab@e=12"
What can i make to make sure that what i send is same in arduino ?


texts: Help with Arduino Due and APA102 LED strip Vs Matrix

texts:
I am in a fix since last one week regarding this:

As mentioned in a previous question (asked here only), I have been working to develop a APA102 LED based display. Now for this I have an Arduino Due. The display area is non rectangular however there is a central rectangular region measuring 63 cm X 36 cm. I have managed to do everything from the software side however stuck with the hardware (first time, its mostly vice-versa!!). The confusion is this, 2 options that I have at my disposal:

Go for the APA102 144 LEDs/meter (high density required) strip and then use them to make the display. On doing a small approximate calculation, I found I would have close to 2500-2600 LEDs. My first question is that:

a. Can Arduino Due handle this? I also need to display static images (bitmaps) (forget animations) and perform fading. Would the refreshing be fast enough? I have some values from APA102 datasheet and Arduino Due but cannot make head or tail of it...I do not know how to find out time taken, data rate etc.

b. The other problem I have with this is that for the bitmap to be "perfect", the pixel pitch needs to be same. In vertical direction, this is not possible without cutting the strip along the length to reduce its width. This a damn tedious and useless job. This act along with the soldering and everything involved makes me go for option 2 (below).
I go for eight 8*32 APA102 flexible displays and arrange them in two columns so that to display the bitmap, I split the bitmap data into two 32*32 matrices and then pass them separately. this is because I cannot find the relation between the bitmap pixel index and the actual display index. The arrangement is like that. Here Also, my question is: Can Arduino Due deal with this a good refresh rate without flickering etc. (POV display req.) The problem with this option is that I can cover only the rectangular region of the area and I am left with some area which makes me feel guilty to see it not lighted whereas with strip I can cover the whole area and only display bitmaps for the rectangular area. Both options have serpentine arrangement. This option also has cleaner and easy construction.

Both options seem plausible to me but I really cannot decide which one is better. Confused! Please, any help, idea, guidance, advice...anything would be great. I would be ordering this stuff from aliexpress etc. and thus a wrong decision would be taxing on my pocket.

I would be glad to provide any other info if required.

Thanks!


texts: How to select hardware for my Arduino board?

texts:
As I embark on my first Arduino project, I have lots of questions. Specifically, what considerations should I make when selecting equipment, and what are the critical parameters to safe operation?

Some elaboration upon my questions can be seen below. However, outlining general principals of equipment selection would be highly useful.

I have an Arduino Uno. The Uno has an input voltage of 6-20 V, and operating voltage of 5 V as from the tech specs. Does this mean that I can select any sensor with less than 20 V output to send data to my Arduino?

I am interested in using a sensor like this
 Texas Instruments HDC1080 High Accuracy Digital
Humidity Sensor, which has a supply of 5.5 V. If my logic is correct, this output should be fine. I should know whether or not I need to buy some sort of shield based purely upon the output pins of the sensor, correct? I know I have 6 analog and 6 PWM/digital pins on the Arduino, so the digital signal should be capable of being processed by my Arduino. However, the interface type on the sensor product is I2C, but I am unsure as to what this means or if it needs to be a consideration.


texts: Can't enable face detection on esp32 cam : CORRUPT HEAP: Bad head at 0x3ffe2eb4. Expected 0xabba1234 got 0x00000008 abort()

texts:
I was trying to make esp32 face recognition using the esp32 camera web server example in arduino ,
and everything works fine untill i press on face detection the frame is frozen , module restarted and put this error to serial monitor :

CORRUPT HEAP: Bad head at 0x3ffe2eb4. Expected 0xabba1234 got 0x00000008
abort() was called at PC 0x4008a64d on core 1

ELF file SHA256: 0000000000000000

Backtrace: 0x4008df7c:0x3ffe1c30 0x4008e1f5:0x3ffe1c50 0x4008a64d:0x3ffe1c70
0x4008a779:0x3ffe1ca0 0x400f97cb:0x3ffe1cc0 0x400f5a61:0x3ffe1f80 0x400f59f0:0x3ffe1fd0
0x40093545:0x3ffe2000 0x40082976:0x3ffe2020 0x4008a545:0x3ffe2040 0x4000bec7:0x3ffe2060
0x400d1bc9:0x3ffe2080 0x401194f5:0x3ffe2230 0x40119bfd:0x3ffe2260 0x40119cb5:0x3ffe22f0
0x4011a088:0x3ffe2310 0x40118774:0x3ffe2330 0x401187cb:0x3ffe2370 0x4008fe86:0x3ffe2390

Rebooting...
ets Jun  8 2016 00:22:57

rst:0xc (SW_CPU_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0018,len:4
load:0x3fff001c,len:1216
ho 0 tail 12 room 4
load:0x40078000,len:10944
load:0x40080400,len:6388
entry 0x400806b4

I tried erasing flash bt it made the same error again
I am using Arduino IDE 1.8.12 , esp32-cam
operating at 5 volts from the programmer (also tried other external power supplies)
and these are the pictures of settings : (also used wrover kit in programming settings with huge app >3mb)
Chip name
ESP32 Cam
FTDI Programmer
AI THINKER
Settings
I want to make a face recognition door lock , if this doesn't work could anyone refer me to how can I get facial recognition on esp32 cam with any other way?


texts: How do I feed NRF24L01 from Arduino Pro Mini?

texts:
I wanted to control speed of my four coreless DC motors using Arduino Nano. Then I realised my 3.7V 380mAh 25C and 720mAh (110mAh on picture is just to hold my battery's place) 25C LiPo batteries won't meet the voltage requirement of a Nano. Then I came up with the idea of using Pro Mini instead of Nano; however I couldn't find a 3.3V pin on Pro Mini to feed NRF24. On Nano, I was using a 3.3V pin and 10uF capacitors between Vin and Gnd legs of NRF24.

So my question is: can I feed NRF24 directly from Vcc pin? Or as an alternative what would happen if I fed NRF24 directly from battery and reduce 3.7V to 3.3V via another TIP122 transistor?

Note: I am using 4 of TIP122 transistors whose gate legs are connected to Pro Mini's 5, 6, 9 and 10 pwm pins (I forgot to add base-resistors). Do you also think it is a reliable way of controlling the motors' speed?


texts: Digital to Analog converter with DAC5311, Any suggestion?

texts:
I made my DAC code with DAC5311 and Arduino Uno.
I think it has no problem, but it doesn't work well. Just print 0.(I use an oscilloscope.)
I don't know where has the problem. Please give me any suggestion.

#include <SPI.h>
#include <math.h>
#define pin_CS 10
#define pin_MOSI 11
#define pin_SCLK 13
#define max_VOLT 5

void setVoltage(float voltage){
  if (voltage < 0) voltage = 0;
  if (voltage > max_VOLT) voltage = max_VOLT;
  uint16_t temp = int(voltage * pow(2, 8) / max_VOLT);
  temp = temp << 6;
  uint8_t upper = temp >> 8;
  uint8_t lower = (temp & 0xff);
  digitalWrite(pin_CS, LOW);
  SPI.transfer(upper);
  SPI.transfer(lower);
  digitalWrite(pin_CS, HIGH);
}

void setup() {
  Serial.begin(9600);
  pinMode(pin_CS, OUTPUT);
  pinMode(pin_MOSI, OUTPUT);
  pinMode(pin_SCLK, OUTPUT);
  SPI.begin();
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE0);
  digitalWrite(pin_CS, HIGH);
}

void loop() {
  setVoltage(5);
  delay(10);
}


texts:
Good day to everyone,

I am currently working on project using ATmega2560. I want to use threading, that is why I decided to use FreeRTOS. However, I cannot make one thread to work fine, so that I start writing second one. So, I have following code:

#include <stdlib.h>
#include <avr/wdt.h>
#include <Arduino_FreeRTOS.h>
#include <semphr.h>

void setup()
{
    pinMode(car_state_pin, INPUT);
    pinMode(battery_pin, INPUT);

    Serial.begin(9600);
    Serial2.begin(9600);
    Serial3.begin(9600);

    watchdogSetup(); //setup WD for 8 secs

    Serial.println("Create Tasks");

    Serial.flush();
    Serial2.flush();
    Serial3.flush();

    xTaskCreate(collect_data, (const portCHAR *) "GPS_Collect_Data", 128, NULL, 1, NULL);

    //collect_data(NULL);
}

And I have function collect_data which should run as thread:

void collect_data(void *pvParameters)
{

    (void)pvParameters;
    uint8_t len;
    char *tmp;

    for (;;)
    {
        millis_delay(2000);

        if (digitalRead(car_state_pin) == HIGH)
        {

            Serial.println("Collecting Data");
            tmp = (char *) calloc(50, sizeof(char));

            do
            {
                wdt_reset();
                len = gps_get_data(tmp);
                Serial.println("Len < 15!");
                millis_delay(100);
            } while (strlen(tmp) < 15);

            /* Add imei and state of the car into the data string */
            len += sprintf(tmp + len, "%s,%d,%d", imei, digitalRead(car_state_pin), digitalRead(battery_pin));
            tmp[len] = 0;

#ifdef DEBUG
            Serial.print("TMP IS: ");
            Serial.println(tmp);

            Serial.print("Len is: ");
            Serial.println(len);
#endif

            free(tmp);
        }
    }
}

The problem is, this current code does not work properly, it resets automatically after printing "Collecting Data" and it just repeats forever (So output is:

Creating Tasks
Collecting Data
Creating Tasks
Collecting Data

and so on).
However, when I comment xTaskCreate and do normal function call (uncomment the last line of setup), it works perfect. Can there be any reason, why thread wouldn't work as normal function call? I guessed maybe because of stacksize, but I've increased it and still no result.


texts:
I'm looking to convert an int value to a char array. currently I've found the following will return [number]

int num = [number]
str = String(num);
str.toCharArray(cstr,16);
Serial.println(cstr);

However, per Majenko's The Evils of Arduino Strings I feel like this code would make my Arduino's heap look like swiss cheese. Is there a better way to change an [int] into a char[n] array that avoids the String class?


texts: Arduino Nano, ICSP header and 595 Shift register

texts:
I'm trying to control a 4-digit 7 segment display with an Arduino Nano, but I'm getting something wrong. I'm using the ICSP header to interface with a 74HC595 Shift Register which is then connected to the display. I've tested and retested the connections and everything seems to be alright, however the shift register doesn't have the desired output, and I notice it only shifs one single bit when I press the reset button on the arduino board.

74HC595   |    A. Nano
DS     <-----> MOSI (ICSP)
SH_CP  <-----> SCK (ICSP)
ST_CP  <-----> D6
MR     <-----> 5V (ICSP)
OE     <-----> GND (ICSP)
VDD    <-----> 5V (ICSP)
GND    <-----> GND (ICSP)

My code:

//pin connected to STCP
const int latchPin = 6;
//pin connected to SHCP
const int clockPin = 17;
//pin connected to DS (MOSI)
const int dataPin = 11;

byte val=0;

void setup() {
  // put your setup code here, to run once:
  //SPI pins are output
  pinMode(latchPin,OUTPUT);
  pinMode(clockPin,OUTPUT);
  pinMode(dataPin,OUTPUT);

  pinMode(3,OUTPUT);
  updateRegister(0);

}

void loop() {
  // put your main code here, to run repeatedly:
  digitalWrite(3,HIGH);
  for (int i=0; i<8; i++) {
    updateRegister();
    delay(500);
  }

}

void updateRegister() {
  //pull latch low to write new bits to the register
  digitalWrite(latchPin,LOW);
  //shift out the data
  shiftOut(dataPin,clockPin,LSBFIRST,val);
  //pull latch pin high so that the leds light up
  digitalWrite(latchPin,HIGH);
}


texts: What is the most Inputs on An analog Pin with a specified Accuracy on the Resistors Used?

texts:
I am asking about the technique were switches and resistors in series are used on the analog pin, so it creates a voltage divider when one of the switches is pressed, it a well known technique it is described here with 5 buttons on one analog pin

http://www.instructables.com/id/How-to-access-5-buttons-through-1-Arduino-input/

Obviously we assume the circuit is set up correctly e.g. the voltage reference is stable-but such things aren't the main point of this question.
My question is about an obvious generalisation of that circuit for more inputs - and where the resistors are all replaced by, a single type of resistor, a fixed resistance value (e.g. 4k ohm) with a known error on the resistance (e.g. 5%). We use the 4k resistors to make up larger values 4k,8k,12k,16k,20k Ohms and make the 100k Ohm resistor out of twenty five 4k ohm resistors.
My question using only 4k ohm resistors (connected in series in the voltage divider) within a 5% error of their value -what is the most switches  we can theoretically connect for reliable working on one analog pin?-I'll have a guess at 20 switches.

The second question is given X ohm resistors (connected in series in the voltage divider) within a E% error of their value -what is the most switches, M,  we can theoretically connect for reliable working on one analog pin? So there will be a formula for this-so what is it?


texts:
So recently I made code that used two custom sensors that are connected to the analog pin A0 & A5. Schematic can be seen here (http://inmoov.fr/test-your-finger-sensor/).

const int ono = A0;
const int twe = A5;

int one;
int two;

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

  }

void loop() {
  one = analogRead(ono);
  two = analogRead(twe);

  Serial.print(one);
  Serial.print(" ");
  Serial.println(two);

}

So after I follow the schematic i did the code, but the data value from the Serial Plotter of both sensors are always equal even though I was only pressing down on one sensor. So is this a code problem or the circuit? if so is there any fix for it? Thx.


texts:
I have written a code that transmits data over the I2C channel, The device ID and every other stuff is working fine. The only issue being that my code gets stuck at Wire.endTrasnmission().

I found the issue using Serial debug messages.

Strange thing:

When i disconnect the SCL line (A5 on arduino Pro Mini), the hang disappears and the code starts to function again.

A search brought me to this forum
http://forum.arduino.cc/index.php?topic=66353.0

where a guy talks about the code snippet

if(hang)
unfreeze();

is this possible, if yes where do i place it?

Observation:  The hang goes away if i disconnect the SCL line on either of the arduinos communicating, the sam edoes not happen if i disconnect the SDA.


texts: Using 2 piezo buzzers to emit the same tone with phase difference

texts: For a physics project, I want to record the effect of 2 speakers emitting 100hz at different phase differences. Trouble is, the Arduino can only send one tone() signal at a time. How do I create a phase difference effect using one Arduino?


texts: how do I power my motor shield without an arduino uno?

texts:
I want to power my motor shield without my UNO. I have connected the +ve and -ve terminals resulting in lighting up of the LED.

Is there any way to control the motors in this arrangement from the Arduino?


texts: Coin Slot Sensor Using AttachedInterrupt

texts:
Hi Im having a problem on my code How can I properly use the attached Interrupt on my coin Sensor so that it will not have any problem on detecting coins
#include <Adafruit_Fingerprint.h>    //Libraries needed
#include <SoftwareSerial.h>
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <EEPROM.h>
#define I2C_ADDR 0x27          //LCD i2c stuff
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
const int coinSlot = 9;
int relayPin = 4;

String Names[] = { "RAVEN", "Surtr", "Tech",}; //Those are the names affected to the fingertemplates IDs
//The first on which is Names[0] : "" has the ID 1 in the fingerprint sensor

SoftwareSerial mySerial(2, 3);                  //Fingerprint sensor wiring RX 3, TX 2
LiquidCrystal_I2C lcd(I2C_ADDR, En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin); //LCD declaring

Adafruit_Fingerprint finger = Adafruit_Fingerprint(&mySerial);                    //Fingerprint sensor declaring

volatile int coinCount = 0;
int requiredCoins = 1;
boolean coinInserted = false;

void setup()
{
  pinMode(relayPin, OUTPUT);
  digitalWrite(relayPin, HIGH);
  pinMode(coinSlot, INPUT_PULLUP);
  lcd.write(EEPROM.read(5));
  Serial.begin(9600);
  attachInterrupt(digitalPinToInterrupt(9), coinInterrupt, FALLING);
  finger.begin(57600);              //Sensor baude rate
  lcd.begin (16, 2);
  lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
  lcd.setBacklight(HIGH);
  lcd.setCursor(0, 0);
  lcd.print("SECURED VAULT");
  lcd.home();
  finger.getTemplateCount();        //Counts the number of templates stored in the sensor flash memory
  delay(2000);
}

void loop() {
  int FingerPrintResult = getFingerprintIDez();

  if (FingerPrintResult != -1) { //This function keeps looping and waiting for a fingerprint to be put on the sensor
    OpenDoor();
  }
  else
  {
    if (coinInserted) {
      coinInserted = false;
      coinCount++;

      EEPROM.write(0, coinCount);
      Serial.println(EEPROM.read(0));

      lcd.setCursor(0, 0);
      lcd.print("TOTAL:");
      lcd.setCursor(0, 1);
      lcd.print(coinCount);
    }

    void coinSlot() {
      coinCount++ ;
      insert = true;

      else {
        lcd.clear();
      }
    }
  }
}
//Only the modifications are commented
int getFingerprintIDez() {
  uint8_t p = finger.getImage();        //Image scanning
  if (p != FINGERPRINT_OK)  return -1;

  p = finger.image2Tz();               //Converting
  if (p != FINGERPRINT_OK)  return -1;

  lcd.clear();                     //And here we write a message or take an action for the denied template
  p = finger.fingerFastSearch();     //Looking for matches in the internal memory
  if (p != FINGERPRINT_OK) {         //if the searching fails it means that the template isn't registered
    lcd.print("Access denied");
    delay(2000);
    return -1;
  }
  //If we found a match we proceed in the function

  lcd.print("Welcome");                  //Printing a message for the recognized template
  lcd.setCursor(2, 1);
  lcd.print(Names[finger.fingerID - 1]); //Then print the name we gave it and the -1 is to remove the shift as the ID starts from "1" but the array from "0"
  return finger.fingerID;
}
void OpenDoor() {
  digitalWrite(relayPin, LOW); // turn on solenoidlock
  delay(5000);
  digitalWrite(relayPin, HIGH); // turn off solenoidlock
}

Please how can I get the code working and what line of code should I focus to make the code work


texts: More speed from ATMEGA328 Internal Clock

texts:
I have a board that is designed and produced. It was designed to use an Atmega328 with the internal clock. There is no space on the board to place an external clock. After completing these and testing them I have found that 8Mhz is too slow to complete my main loop actions seamlessly. The main loop involved shifting data out to 20 registers. Is there any way to speed this up without going back to the drawing board on the PCB design? Can another AVR be substituted as a drop in replacement with a faster internal clock? Can the internal clock be made to run faster or doubled to achieve 16Mhz?

The application is a matrix display that has 50 columns and 7 rows. The registers are the display buffers and represent the current state of the display. Because of the multiplexing in the matrix, only 1/5 of the pixels are illuminated at any given time. In order to trick the eyes into seeing all lit at the same time the speed needs to be faster. The display flickers with the interal clock. If I connect and UNO board instead of using the on board ATMEGA328 (QFP) it works good. So the difference between 8Mhz and 16Mhz is visible. If I can double the speed of the display loop than that is a solution. Below is the loop, for reference, latchPin = 8, clockPin = 12, dataPin = 11.


texts: I'm doing a comparative study between ATtiny84 and ATtiny85, and I found from the datasheet that ATtiny84 consumes less current, is that normal even if it is bigger in terms of size and number of pins? Am i wrong?


texts: What options are available for connecting to a CDMA network?

texts:
I am looking specifically to connect to a CDMA carrier from an Arduino. In doing research, I came across a CDMA shield option (requires getting a CDMA module that you drop into a shield), but that ends up being quite expensive - the CDMA module alone is $140, as opposed to a GSM shield which runs $30-$60. I've also tried looking for other CDMA modules, but haven't been able to find much.

Even if it's not sold as a proper Arduino shield, does anyone know of a CDMA module for hobby projects?


texts: append a String on ArduinoJson Object value

texts:
I've a json string request coming from server and I convert it into json object

  StaticJsonBuffer<500> jsonStaticBuffer;
  JsonObject& root = jsonStaticBuffer.parseObject(String(msg));
  String reqId;
  String reqData;
  root["requestid"].printTo(reqId);
  root["data"].printTo(reqData);

I need to populate another char json string initiated at the beginning

const char response[] = "{\"response\": {\"requestid\":, \"data\":}}";

such that I need to write requestid into the response::requestid and data into response::data + ACK/NAK . here is how i've tried;

  DynamicJsonBuffer jsonDynResponse;
  JsonObject& jsonResponse = jsonDynResponse.parseObject(response);
  String out;
  if (ACK) {
      jsonResponse["response"]["requestid"] = root["requestid"];
      jsonResponse["response"]["data"] = root["data"] + " ACK"; //THIS DOESN'T WORKS
      jsonResponse.printTo(out);
  } else {
      jsonResponse["response"]["requestid"] = reqId;
      jsonResponse["response"]["data"] = reqData + " NAK";
      jsonResponse.printTo(out);
  }

I know this will definitely not work root["data"] + " ACK" because we can't combine const char with String. But this reqData + " NAK"; resulted in "\"data\" NAK"". How can I concate root["data"] into another String ?
Thank you in advance :)


texts: Class is not tracking changes to a private field

texts:
I have a program where a device registers itself with a command object. The command object is losing track of the registrations. The following program repeats "0 devices registered" even though when it initializes it displays "Devices registered 1". My guess is that I am accidentally creating 2 copies of the command object.
This is the main sketch

#include "command.h"
#include "widget.h"

Command command;
Widget widget;
void setup() {
  command.init();
  widget.init(command);
}

void loop() {
  command.update();
}

command.h

#include "Arduino.h"

#ifndef Command_h
#define Command_h

typedef struct  {
  char id;
  char name[20];
} Device;

class Command
{
  public:
    Command();
    void init();
    void registerDevice(Device _cmd);
    void update();
  private:
    Device Devices[20];
    byte DevicesPtr = 0;
};

#endif

command.cpp

#include <Arduino.h>
#include "command.h"

#define DEVICES_MAX 9

Command::Command() {
  DevicesPtr = 0;
  Device Devices[DEVICES_MAX];
}

void Command::init() {
  Serial.begin(9600);
}

void Command::update(){
  Serial.print( DevicesPtr );
  Serial.println( " devices registered" );
  delay(500);
}
void Command::registerDevice(Device _cmd) {
  _cmd.id = '0' + (++DevicesPtr);
  Devices[DevicesPtr] = _cmd;
  Serial.print("Devices registered ");
  Serial.println(DevicesPtr);
}

widget.h

#include "Arduino.h"
#include "command.h"

class Widget
{
  public:
    static void init(Command _command);

  private:
};

widget.cpp

#include "widget.h"
#include "command.h"

void Widget::init(Command _command) {
  Device device;
  strcpy(device.name, "Widget #1");
  _command.registerDevice(device);
}


texts: connection between Arduino Uno with nRF24L01 and notebook with wireless card

texts:
My project intend to command an Arduino UNO by my notebook without cable. I thought to use a RF Nordic nRF24L01 cabled on an Arduino UNO, and to use the wireless card of my notebook to send command to it. Is it possible? Any solution?
Is this hardware solution possible?

I need to send to Arduino four analog signals to setup the light of four led.


texts: How can I capture raw Bluetooth data on a ESP32?

texts:
I want to send data from a BBC micro:bit to an ESP32 using microbit's radio because the Bluetooth stack is not available on the microbit.
Here is a workaround that shows that there is a communication between radio an an NRF24 device. https://youtu.be/743c329t1xs
Is there a way to capture the raw data from the receiver? It also uses the 3.4 GHz band as Bluetooth does.


texts: Can I use the NodeMCU ESP12 5v pin and control it with a relay?

texts:
This question might be a little esoteric, but I cannot find any answer for it.

Situation:

I want to have more than 8 Analog sensors on a NodeMCU ESP32. Unfortunately due to SPECTACULARLY poor design choices you cannot do this and have WiFi active at the same time. This is a non-starter for my project so I need a workaround.

Thought:

What if I share the available pins I can use, by turning power on and off to the sensors in question? Easy enough using the digital GPIO's and just turning them on and off. The issue is that the sensors are at the end of long wires and so I need 5v power to ensure good readings. So what if I just use a relay, powered off the 5v pin on the ESP32, and switch them on and off?

My question is - can you even do this? Most of what I have seen would indicate I need a separate power supply for the relay itself, and the source being switched on and off, but I would like to avoid having another power supply, and build it as in the circuit diagram below.

A couple of notes:

ignore the V1/1 V label in the picture - the circuit tool is very nice, but freezes a lot and I forgot to change that to VIN/5V before the screenshot
I have also omitted the data connections from sensors and to the relays to switch them on and off - I know they need to exist, but they aren't the issue.
I am running this project plugged in to the wall so source power is not an issue - I am not worried about drain or having a full 5V from the VIN pin

Before I fry parts, I thought it would be good to ask if anyone has tried this or if it is even possible?


texts: Cannot upload sketch to Atmega328p TQFP soldered on PCB

texts:
After creating a working prototype with DIP ATMega328 chip/ Arduino UNO I recently got PCBs assembled with SMD components and ATMega328P TQFP soldered onto them, but now I'm having a hard time trying to upload the Arduino program.

This is the schematic of the PCB with ATMega328P TQFP with ISP headers for programming:

I'm using USBasp programmer with upgraded firmware to upload the code. The chip gets detected and also I can upload sketches to it but the problem is the code runs slow, which I found out is due to the default 8MHz internal clock.(the blink program makes LED blink every 16 seconds instead of 1 second,i.e. with delay(1000))

Now to switch to the external 16MHz clock which I want to use I found out here that I have to change the fuse values from the default

  lfuse: 0x62   hfuse: 0xD9   efuse: 0x3F

to

  lfuse: 0xFF   hfuse: 0xDE   efuse: 0x05

I tried it two times and both the times it screwed up the ATMega328P chip

C:\Users\p>avrdude -p m328p -c usbasp -U lfuse:w:0xFF:m -U hfuse:w:0xDE:m -U efu
se:w:0x05:m

avrdude: AVR device initialized and ready to accept instructions

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

avrdude: Device signature = 0x1e950f
avrdude: reading input file "0xFF"
avrdude: writing lfuse (1 bytes):

Writing | ################################################## | 100% 0.02s

avrdude: 1 bytes of lfuse written
avrdude: verifying lfuse memory against 0xFF:
avrdude: load data lfuse data from input file 0xFF:
avrdude: input file 0xFF contains 1 bytes
avrdude: reading on-chip lfuse data:

Reading | ################################################## | 100% 0.01s

avrdude: verifying ...
avrdude: 1 bytes of lfuse verified
avrdude: reading input file "0xDE"
avrdude: writing hfuse (1 bytes):

Writing | ################################################## | 100% 0.03s

avrdude: 1 bytes of hfuse written
avrdude: verifying hfuse memory against 0xDE:
avrdude: load data hfuse data from input file 0xDE:
avrdude: input file 0xDE contains 1 bytes
avrdude: reading on-chip hfuse data:

Reading | ################################################## | 100% 0.01s

avrdude: verifying ...
avrdude: 1 bytes of hfuse verified
avrdude: reading input file "0x05"
avrdude: writing efuse (1 bytes):

Writing | ################################################## | 100% 0.03s

avrdude: 1 bytes of efuse written
avrdude: verifying efuse memory against 0x05:
avrdude: load data efuse data from input file 0x05:
avrdude: input file 0x05 contains 1 bytes
avrdude: reading on-chip efuse data:

Reading | ################################################## | 100% 0.01s

avrdude: verifying ...
avrdude: 1 bytes of efuse verified

avrdude: safemode: Fuses OK

avrdude done.  Thank you.

C:\Users\p>avrdude -p m328p -c usbasp

avrdude: error: programm enable: target doesn't answer. 1
avrdude: initialization failed, rc=-1
         Double check connections and try again, or use -F to override
         this check.

avrdude done.  Thank you.

Both of the PCBs are not responding to the USBasp programmer and now I have only got one PCB left. I desperately want to get the final one working.

This is my first time using the SMD ATMega328P chips and any help would be appreciated.


texts: Connecting a time on/off circuit and my adafruit neopixel light strip

texts:
I'm new to programming and hardware so be gentle.
I've used this tutorial https://www.instructables.com/id/Arduino-Ultra-Mega-Timers/ to create a time on/off circuit.
I'm attempting to connect some adafruit neopixel led strips to a 5v relay. I've been trying to read up on how exactly relays work and what wires would go from GND, 5v, and Dout to NO and NC but I've hit a brick wall because all of the schematics I've found show light bulbs connecting to the relays. A detailed explanation of exactly how to connect the LED strip to the relay and why it works would be great as I am trying to learn!
Thank you everyone!
-Matthew


texts: Trouble using bluetooth module with the ESP32s2 feather board

texts: I am trying to use an ESP32-S2 feather board with a separate bluetooth module, the Adafruit BLuefruit LE UART Friend. I previously used this bluetooth module with the Feather M0 Adalogger through UART without experiencing any major problems. Now, the bluetooth module does not even get past its begin function. In fact, in order for my program to even compile, I have to change the UART header and cpp files in the nRF51 library by commenting out Software Serial code (although, I don't actually use software serial) because the esp32 core does not have that library. Is this a matter of cores (esp32 as opposed to samd or avr) or something else entirely?


texts: can teensy 3.0 or above run fingerprint scanner fps gt-511c1r?

texts:
I have an fps gt-511c1r fingerprint sensor module. I want to know whether i can run it using teensy 3.0 or above?
I have tried it successfully using arduino uno.

EDIT: I have uploaded the fps blink sketch on the teensy 3.2 successfully, but the fingerprint scanner is not responding. Here is the code:-
         #include "FPS_GT511C3.h"
         #include "SoftwareSerial.h"

     // Hardware setup - FPS connected to:
     //   digital pin 0(arduino rx, fps tx)
     //   digital pin 1(arduino tx, fps rx)

     FPS_GT511C3 fps(0, 1);

     void setup()
     {
         Serial.begin(9600);
         fps.UseSerialDebug = true;
         fps.Open();
     }

     void loop()
     {
        // FPS Blink LED Test
        fps.SetLED(true);
         delay(1000);
         fps.SetLED(false);
         delay(1000);
     }

connected fps tx to teensy rx(pin 0),
          fps rx to teensy tx(pin 1),
          fps vcc to 3.3v teensy,
          fps gnd to teensy gnd.


texts: Switch between ntc resistor sensors time based for other device

texts:
We have a heating system that uses an ntc resistor to measure water temperature. I would like to replace that ntc resistor by a fixed one (low enough to disable heating) temporary on a 5 minute schedule, or any other.

It's to prevent the warm water using up all the heat and not leaving any for the central heating of the building. We got fooled by the contractor and a proper upgrade would now cost several thousands, so we just want to trick the system. ;p

The arduino is not supposed to measure anything, just to connect one of the two resistors to the heating system.

Is an arduino the right choice for that? If yes, which model? What extra elements would I need? Transistors? Relays? They shouldn't have too much own resistance to not influence the measuring of the heating system when the NTC is connected.

Just a simple connection of the extra resistor would work too because the resulting resistance would be lower and still indicate "water is hot enough" to the heating system.

Any help is welcome, even if it is not arduino based.


texts: Why is it i need transistors and resistors to turn a dc motor with an Arduino but i can connect it directly to a battery

texts:
As the question says im building a circuit to run a DC motor whenever motion is detected on a motion sensor. Now as this image suggests

I need a diode + resistor + transistor to get this thing to turn with an arduino but i can do the same with a battery and connecting each of the terminals to the + and - of the battery. I understand this might be for speed control ? or turning the motor different ways ?
But if I just need it to spin at 100% would all this be needed ?
I tried hooking up the motor directly with a resistor to the 5V + GND of the board while it was on but no joy (obviously) doing something wrong but wanted to use this problem as a way to learn circuits better.
Thanks
S


texts: Esp-01 why is serial data being sent and received on the same pin?

texts: I’m trying to send serial data between my esp and a micro controller. I’m able to send a message from the microcontoller to the esp and display it on the serial monitor, similarly I can send data from the esp to turn on a micro controller led, however serial.swap() and serial.read() both use the tx pin making it impossible to send and receive at the same time. Using rx to read crashes the esp. is it possible to us tx to send data to the micro controller and rx to receive it?


texts: I'm new to Arduino and also new to electronics. I'm following the tutorial here. I'm not understanding the importance of the resistor in this schematic diagram. Can someone please help me on this?


texts:
This question is an extension of this question.

Accessing Values From Array Within a Library

The answer provided by Mark showed me how to read and print a single value from a particular array by using the index number to print to the serial console.

The second part of this question is how to get these values from the array to map to 0-180 for values that are useful to the servo.

The below code is my attempt that is not working. I used the servo sweep example from the Arduino examples which worked fine with a potentiometer but not with the ppm input. What am I doing wrong here? This won't compile. (I am using TinyServo.h library since this is for an attiny85. Works with with the pot mapping just fine.)

#include <TinyServo.h>
#include <TinyPinChange.h>
#include <TinyPpmReader.h>
#include <Rcul.h>

int PPM_INPUT_PIN = TinyPpmReader.width_us(3); //<------- Doesn't work

//int potpin0 = 3;    <---------          // This worked
int val0;                     // integer to store value

const byte SERVOS = 1;                   // how many servos do you have? up to 5 on ATTiny85 and 8 on ATtiny84/2313
const byte servoPin[SERVOS] = { 0 }; // what pins are your servos on?
                                       // you have the option to give your servos nice names. 0 refers to the first servo pin above, 1 to the second, etc

#define PANSERVO 0
#define PPM_INPUT_PIN  2    <--------- //define pin for ppm input

void setup()
{
  setupServos();
}

void loop()
{
  val0 = analogRead(PPM_INPUT_PIN);  <---------          //Doesnt work// reads the value of the       potentiometer (value between 0 and 1023)            // reads the value of the 2nd potentiometer (value between 0 and 1023)
  val0= map(val0, 1000, 2000, 0, 180);
    // scale it to use it with the servo (value between 0 and 180)
       // scale it to use it with the servo (value between 0 and 180)

moveServo(PANSERVO, val0);

  delay(5);                           // waits for the servo to get there
}

For some background, the ppm library outputs like this to the serial monitor:

Ch4=1560 us

These values move from ~1000 - 2000 depending on the ppm signal input. (The input is from a RC remote control receiver)

This example below prints only channel 4 (Ch4=1560 us)from  a total of 8 channels. Now, I want to map this to the values of 0-180:

#include <TinyPinChange.h>
#include <TinyPpmReader.h>
#include <Rcul.h>

#define PPM_INPUT_PIN  2

void setup()
{
  Serial.begin(38400);//attiny tx - rx uno does not work at 9600 baud. Set to 38400 @ attiny 1mhz and uno serial console to 38400 baud
  TinyPpmReader.attach(PPM_INPUT_PIN); /* Attach TinyPpmReader to PPM_INPUT_PIN pin */
}

void loop()
{

Serial.print(F("Ch"));Serial.print(3);Serial.print(F("="));Serial.print(TinyPpmReader.width_us(3));Serial.println(F(" us"));

 display results */
  delay(500);
}

What am I doing wrong?