texts: Serial Communication with two bluetooth modules on Arduino Mega

texts:
I'm trying to communicate with two bluetooth module (RN-42) on the Arduino Mega.

I studied about Serial communication in Arduino, and I used Serial1, Serial2 to get information at the same time from the modules.

At the setup period, baud rate will be set. The command "$$$" makes the bluetooth module go into the configuration mode. Until this, everything works pretty well.

The problem is, it seems nothing works inside the loop(). I think Serial1.print(inByte), Serial2.print(inByte) doesn't work properly. I checked the TX1, TX2 port whether it sends any data or not by using LED, and the LED never blinked.

Here's the code that I used.

void setup() {
  // initialize both serial ports:
  Serial.begin(9600);

  Serial1.begin(115200);
  Serial1.print("$$$");
  delay(100);
  Serial1.println("U,9600,N");
  Serial1.begin(9600);

  delay(100);
  Serial1.print("?");

  Serial2.begin(115200);
  Serial2.print("$$$");
  delay(100);
  Serial2.println("U,9600,N");
  Serial2.begin(9600);

}

void loop() {
  // read from port 1, send to port 0:

  while(Serial1.available()>0) {
    char inByte = Serial1.read();
    Serial.print(inByte);
  }

  while(Serial2.available()>0) {
    char inByte = Serial2.read();
    Serial.print(inByte);
  }

  // read from port 0, send to port 1:
  while (Serial.available()>0) {
    char inByte = Serial.read();
    Serial1.print(inByte);

    delay(10);
    Serial2.print(inByte);
  }
}

Thank you


texts: Disable auto-reset Mega 2560 on serial monitor open using 60 ohm resistor

texts:
I tried preventing my Arduino Mega 2560 from restarting every time I open the serial monitor. This link didn't work for me at all.

I tried connecting the RESET pin to 3.3v pin via a 60 ohm resistor and it worked for me. The question is: If I leave that resistor permanently connected, will this solution damage my board as time passes?


texts: How to avoid that my arduino clicks eternally?

texts:
I have accidentally implemented a program that imitates the click of the mouse.

The problem is that now I can´t delete the program because each time that I connect the USB, the computer starts clicking everything and it is not possible to upload a new program.

Can I solve this problem?


texts:
How do you detect when the serial port has been disconnected or interrupted on an Arduino Uno and reset it?

I'm trying to diagnose a problem communicating between an Arduino Uno and a Raspberry Pi via the USB serial link. The Pi routinely pings the Arduino for a status, but after a few minutes, the serial connect fails with a write timeout error. For the life of me, I can't figure out why. The Arduino is connected to a few I2C devices, so there might be some interference, but I can't confirm it.

My workaround at the moment is to detect on the Pi when the Arduino hasn't responded to a ping after 5 seconds, and reset the serial port. However, this adds latency and interrupts whatever the Arduino was doing, so I'd like the Arduino to try and detect this as well. Is there any way to detect when the serial port has been stuck and reset it on the Arduino's side?


texts: Where can I find the source codes for the various classes and methods used in Arduino Primo?

texts:
I am new to Arduino development. I am trying to connect a BLE device (Arduino Primo) with my iOS app. From the Arduino BLE examples, I understand how to initialize the BLEperipheral class and then call the setValue method to pass value to be transmitted. However I do not want to be dependent on example codes, rather I want read the source code and definitions to know about the available classes and their methods, what argument types passed etc.(not precompiled libraries with .o extension).

For my current issue, I want to know what type of arguments does the setValue take in the BLEperipheral class. Can I pass an int value(4 bytes) or it has to be a char only? These questions can be answered by reading the source code of these inbuilt libraries.

Any direction would not only help me with the current project, it would also help to tackle and understand any projects in the future, where I might use inbuilt library calls.

I have searched the internet, however not much information is available for newcomers like me.
Below is a similar question link but outdated and does not solve what I am looking for.

How can I get the source files for Arduino libraries?

Thank you for any suggestions.


texts: How to connect gyro to Arduino Uno via I2C

texts:
parts

Three-axis rate gyro on breakout board: gyro datasheet, breakout board "datasheet"
Arduino Uno: pinout

goal: I want to periodically read a single axes' angular rate. As rvbarreto pointed out, Adafruit built an Arduino library for this sensor, so I'm playing around with its example file.

configuration:

I have a 5600 Ohm pull-up connected to the SDA and SCL pins each on the Arduino. The internal pull-ups of the Arduino are too weak according to this thread.

code: (Adafruit library's sensorapi example)

#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_FXAS21002C.h>

/* Assign a unique ID to this sensor at the same time */
Adafruit_FXAS21002C gyro = Adafruit_FXAS21002C(0x0021002C);
//Adafruit_FXAS21002C gyro = Adafruit_FXAS21002C(0x21);

void displaySensorDetails(void)
{
  sensor_t sensor;
  gyro.getSensor(&sensor);
  Serial.println("------------------------------------");
  Serial.print  ("Sensor:       "); Serial.println(sensor.name);
  Serial.print  ("Driver Ver:   "); Serial.println(sensor.version);
  Serial.print  ("Unique ID:    0x"); Serial.println(sensor.sensor_id, HEX);
  Serial.print  ("Max Value:    "); Serial.print(sensor.max_value); Serial.println(" rad/s");
  Serial.print  ("Min Value:    "); Serial.print(sensor.min_value); Serial.println(" rad/s");
  Serial.print  ("Resolution:   "); Serial.print(sensor.resolution); Serial.println(" rad/s");
  Serial.println("------------------------------------");
  Serial.println("");
  delay(500);
}

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

  /* Wait for the Serial Monitor */
  while (!Serial) {
    delay(1);
  }

  Serial.println("Gyroscope Test"); Serial.println("");

  /* Initialise the sensor */
  if(!gyro.begin())
  {
    /* There was a problem detecting the FXAS21002C ... check your connections */
    Serial.println("Ooops, no FXAS21002C detected ... Check your wiring!");
    while(1);
  }

  /* Display some basic information on this sensor */
  displaySensorDetails();
}

void loop(void)
{
  /* Get a new sensor event */
  sensors_event_t event;
  gyro.getEvent(&event);

  /* Display the results (speed is measured in rad/s) */
  Serial.print("X: "); Serial.print(event.gyro.x); Serial.print("  ");
  Serial.print("Y: "); Serial.print(event.gyro.y); Serial.print("  ");
  Serial.print("Z: "); Serial.print(event.gyro.z); Serial.print("  ");
  Serial.println("rad/s ");
  delay(500);
}

NOTE: I noticed that Adafruit's Github had removed a line of code (line 67) in their library's main .cpp file. I edited my library code to reflect that change.

problem: I keep getting the "Ooops, no FXAS21002C detected ... Check your wiring!" error message.

questions:

Am I connecting my pull-up resistors correctly?
Should I not power VDD and VDD_IO on the same rail? Can they even be powered by the Uno?


texts: I'm using an Arduino to control a reverse osmosis machine, I would like after a certain number low pressure events to return to the testing routine. Can you call to previous functions?


texts: Building Multidimensional Arrays from simple arrays

texts:
Hi I am trying to write a functiont that will build a 2x4 array based on 2 1x4 arrays.

the two relevant functions are below. The first function gets information from some sensors and outputs it (I think) as a 1x4 array.

The second function is the problem and I have attached the error messages.

{
double quatCalib_mat[2][4];
double quatCalib_ABC[4];
double quatCalib_GHI[4];

 double  get_quat(Adafruit_BNO055 ref, double quatArray[])
{
  imu::Quaternion quat2 = ref.getQuat();

  quatArray[0]= quat2.w();
  quatArray[1]= quat2.x();
  quatArray[2]= quat2.y();
  quatArray[3] =quat2.z();

}

void Calibrate()
{
quatCalib_ABC=get_quat(bnoABC, quatCalib_ABC);

quatCalib_GHI=get_quat(bnoGHI, quatCalib_GHI);

quatCalib_mat= {
  {quatCalib_ABC},
  {quatCalib_GHI}
  };
}

the error messages

Arduino: 1.6.9 (Windows 7), Board: "Arduino/Genuino Uno"

E:\UNI2016\thesis\gizmo programming\Thesis_V3_M\Thesis_V3_M.ino: In function 'void Calibrate()':

Thesis_V3_M:101: error: incompatible types in assignment of 'double' to 'double [4]'

 quatCalib_ABC=get_quat(bnoABC, quatCalib_ABC);

              ^

Thesis_V3_M:103: error: incompatible types in assignment of 'double' to 'double [4]'

 quatCalib_GHI=get_quat(bnoGHI, quatCalib_GHI);

              ^

Thesis_V3_M:105: error: assigning to an array from an initializer list

 quatCalib_mat= {

              ^

exit status 1
incompatible types in assignment of 'double' to 'double [4]'

Cheers

Alex


texts:
I've just tried out my new TFT_ILI9163C display with TFT_ILI9163C library but I'm having an issue with it. The graphics has moved down (the "hello world" should be in the top left) and the leftover space looks like there was no signal. Can be seen in the photo.
What could be wrong?


texts: Unable to receive and print SMS on the serial monitor with Arduino Uno and SIM900A

texts:
I'm trying to receive an SMS and show it on the serial monitor.

My code is as following:

void setup()
{

  Serial.begin(2400);
  Serial.write("AT+CMGF=1\r");           //set GSM to text mode
  delay(1500);

  Serial.write("AT+CPMS=\"SM\"\r");         //Preferred SMS Message Storage
  delay(1000);

  Serial.write("AT+CMGL=\"ALL\"\r");       //List SMS Messages from Preferred Storage
  while(1)
  {
    if(Serial.available())
    {
      Serial.write(Serial.read());
    }
  }
}

void loop()
{
}

The circuit diagram is as shown below.

The output that I am getting is as following:

AT+CMGR=1
AT+CMGF=1

OK
AT+CPMS="SM"

ERROR
AT+CMGR=1
AT+CMGF=1

OK
AT+CPMS="SM"

ERROR

ERROR
AT+CMGR=1
AT+CMGF=1

I am not able to use AT+CPMS or AT+CMGL commands.


texts:
I'm using the Adafruit SD shield with a Mega board and wrote a simple program to log data.  I am outputting a constant stream of data at 115200 baudrate from another Arduino to the Mega.  The data output is mostly good, but there are places where some data are skipped.  These skipped data usually occurs around a file flush.  I've tried playing around with the flush frequency and the soft buffer size, but to no avail.  I'm not sure what these hiccups are caused by and would like some help.

void loop(void)
{
  while (Serial1.available())
  {
    softBuffer[i] = Serial1.read();
    i++;
  }

  if (i >= SOFT_BUFFER_SIZE)
  {
    for (x = 0; x < SOFT_BUFFER_SIZE; x++)
    {
      logfile.print(softBuffer[x]);
    }

    logfile.flush();

    i = 0;
  }
}


texts:
Is there a way to use common/cheap components to put the 3.3V and 5V pins on an Arduino under load, in order to measure if they are giving a correct and stable voltage?  Can I calculate a certain load to test?

Something keeps happening to my boards which causes the 3.3V pin to measure the correct voltage when idle, but to spike when put under load, which kills the component I was powering (XBees, which are previously tested working).


texts: Run 5V/2.3W water pump on Arduino Pro Mini 5V

texts:
I want to build up my automatic water pump with an arduino pro mini 5v and a 5v usb water pump (2.3 W). As I understand, I cannot power the pump directly through the vcc pins of the board, right?
Would it be possible to place a female USB Port in my system to power the board and the pump through a relay on the board? What would be an appropriate circuit diagram?


texts: How to use float data from a sensor with the Arduino mouse library

texts:
I'm using a gyroscope, which returns angular velocity in floats. I'm trying to use this data with the arduino mouse library. The move function requires a signed character. I'm not what the best way is to convert the float data from the sensor into signed char.
In what way can I do this, losing the least in terms of precision?
I found out you can use dtostrf to transfer floats into an array of characters, but not sure what to do following this or if it's even the best way.
I would appreciate any guidance.


texts:
My Arduino crashes after using sprintf, To reduce system ram am trying to move away from strings to char and now this happened. Loop not working properly and it's not going to webrequest, spent 2 days to find a solution nothing worked yet. My project is to send temp and humidly to my server i was using strings and after one day of use system very slow to send data to server then i realized stings are the culprit then i changed to char
char ventionoroff[6];

char Foggeronoroff[6] ;

char Exhuastonoroff[6] = "OFF";

char current[4];

char today[10];

bool running = false;
bool isFoggerRunning = false;
bool isExhaustFanRunning = false;

Time t;

void loop() {

 t = rtc.getTime();

  hum = dht.readHumidity();
  temp = dht.readTemperature();
  delay(1000);

  if (isnan(hum) || isnan(temp)) {
    Serial.println(F("Failed to read from DHT sensor!"));
    return;
  }
  val = digitalRead(powerStatus);

      byte MIN = t.hour;
      byte SEC = t.min;

  char timeStamp[20];
 snprintf(today, "%02d:%02d",  MIN, SEC);

   Serial.println(today);

if (millis() - lastConnectionTime > postingInterval) {
   Serial.println("reaching here2");
    httpRequest();
  }

  if (val)
  snprintf( current , "YES");

  else
 snprintf( current , "NO");

  if (running == false) {
    snprintf( Foggeronoroff , "WAIT");

  } else {
   snprintf( Foggeronoroff , "READY");

  }

    ventilationfan();

void httpRequest() {
Serial.println("shit reached here");
  client.stop();
  char data[10];
  const char phpScript[21]  = "/farmsensor/add.php";
  const char server[20]  =  "www.gstorefresh.com"; // also change the Host line in httpRequest()

   char strt[6];
   char str[6];
  sprintf(strt, "te=%d", temp);
  strcpy(data, strt);
  strcat (data,"&ti=");
  strcat (data,today);
   strcat (data,"&mot=");
   strcat (data,ventionoroff);
   strcat (data,",");
   strcat (data,Foggeronoroff);
    strcat (data,",");
    strcat (data,current);
     strcat (data,"&mo=");
     strcat (data,Exhuastonoroff);
      sprintf(str, "&hum=%d",hum);
      strcat (data,str);

 Serial.println(data);
   int len = strlen(data);
  if (client.connect(server, 80)) {
    client.print("POST ");
    client.print(phpScript);
    client.println(" HTTP/1.1");
    client.println("Host: www.gstorefresh.com");
    client.println("User-Agent: Arduino/1.0");
    client.println("Connection: close");
    client.println("Content-Type: application/x-www-form-urlencoded; charset=UTF-8");
    client.print("Content-Length: ");
    client.println(len);
    client.println();
    client.print(data);
    restartnet = 0;
     data[0] = 0;
     Serial.print("data after sucessfull connection");
     Serial.println(data);
     Serial.print("freeMemory after connection");
     Serial.println(freeMemory());
    lastConnectionTime = millis();

  } else {

     Serial.println(F("Failed"));
     data[0] = 0;

  }
}


texts: Can I link another device to the Uno's clock?

texts:
I'm trying to use an unusual 16x2 LCD display with my Uno. As far as I know, it's an EA-X16027AR. It doesn't seem to be compatible with the HD44780 driver, which is typically used for Arduino LCD's.

According to the datasheet, the display's ENB (Enable) pin requires a clock input, described as follows:

  Basical Clock to perform Instructions in Controller LSI. The Clock at the same timing as MPU are usually input.

The timing graphs elsewhere in the datasheet show it wants a speed of around 2 MHz.

Is it possible to get the internal clock signal from the Uno, scale it down to 2 MHz, and output it to a GPIO pin or similar? Alternatively, is it possible to emulate a clock signal at that speed on-board, without adding additional timing components?


texts: Connecting high sampling rate DAC and ADC to arduino DUE, timer consideration

texts:
I'm in the echopen association, our goal is to create a low cost, open source echographic probe. In order to do that, we use an arduino due for the first step. For doing acoustic imaging, we use ultrasonic transducer wich works at high frequency, typically 5 MHz. So, for our purpose we need to send and receive analogic signal at high frequencies.
We want to connect a 80 Msps DAC and a 80 Msps ADC to the arduino due so we can generate and mesure analog signal up to 42 MHz. I have found here (http://www.instructables.com/id/Arduino-Timer-Interrupts/#step0) how to use arduino timer interrupts in order to send and receive data at 84 MHz. I haven't connect my converters for the moment, but I have preliminary questions.
First, is the definition of the timer is the same for the arduino due (i.e. timer1 is a 16 bits timer) ? Morever, my ADC and DAC are 14 bits converters, can I tell to the arduino to sent only 14 bits digital signal ?
Secondly, as we work at high frequencies we will have to send a lot of data from the microcontroller to a computer via the serial port. I have make a test and at 250000 bauds it takes nearly 0.5 second to transfer 4300*8 bits datas. It is to slow for our purpose, how can I do it faster ?


texts:
I'm trying to control an Arduino-powered motorized toy with a differential drive. However, I want to code it the motor movements with a direction vector.

e.g.

(1,0) = forward
(-1,0) = backward
(0,1) = turn left, pivoting on center axis
(0,-1) = turn right, pivoting on center axis
(1,1) = forward-left, pivoting on left wheel
(1,-1) = forward-left, pivoting on right wheel

I thought the equation to convert these to the literal motor signals was:

float mag = sqrt(dirX*dirX + dirY*dirY);
float left = dirX - dirY;
float right = dirX + dirY;

This seems to work for the first 4 cases, but fails for the last two, where it results in an un-normalized vector.

One potential fix would be to simple wrap left and right in min() to stop it from going over 1.0, but that feels like a hack, and would possibly lose resolution. Is there a more elegant fix?


texts: Making a composite waveform using a single TIMER interrupt

texts:
I'm writing software for a laser tag gun, which under the system we use needs the output waveform to be a carrier wave of 57600Hz with a signal wave of 1800HZ for about 50ms

Using the Tone library (https://code.google.com/p/rogue-code/wiki/ToneLibraryDocumentation) and a transistor AND gate, I've had this working using two timers, however I really want to shrink it down to one timer so that I can use the other for sound (using the TMRPCM library which only needs timer1).

I've modified the Tone library cut down to what I need, with the following methods:

void TagTone::beginPulse(uint8_t tonePin)
{
    _pin = tonePin;
    _timer = 2;

    // 8 bit timer
    TCCR2A = 0;
    TCCR2B = 0;
    bitWrite(TCCR2A, WGM21, 1);
    bitWrite(TCCR2B, CS20, 1);
    timer2_pin_port = portOutputRegister(digitalPinToPort(_pin));
    timer2_pin_mask = digitalPinToBitMask(_pin);

    int duration = 50; //50 milliseconds
    uint8_t prescalarbits = 0b001;
    int32_t signal_toggle_count = 0;

    // Note: may need prescaler reimplemented if using 16Mhz, fine on current 8Mhz
    ocr = F_CPU / (CARRIER_FREQUENCY * 2) - 1;
    prescalarbits = 0b001;

    TCCR2B = (TCCR2B & 0b11111000) | prescalarbits;

    toggle_count = 2 * CARRIER_FREQUENCY * duration / 1000; // how many times the carrier toggles before pulse ends

    // want to AND with 1800 Hz signal

    // as duration now set to 50: toggle_count for carrier = 5760
    // equivalent toggle count for signal = 180
    signal_toggle_count = 2* SIGNAL_FREQUENCY * duration / 1000;

    // want to flip signal state every 32 carrier pulses
    signal_cycle_count = 32; //toggle_count / signal_toggle_count;
}

// duration (in milliseconds).

void TagTone::playPulse()
{

    OCR2A = ocr;
    timer2_signal_toggle_count = signal_cycle_count;
    timer2_toggle_count = toggle_count;
    bitWrite(TIMSK2, OCIE2A, 1);

}

ISR(TIMER2_COMPA_vect)
{
    if(timer2_toggle_count  < 0)
    {
        *timer2_pin_port ^= timer2_pin_mask & signal_state; // flip

        if (timer2_signal_toggle_count > 0)
        {
          timer2_signal_toggle_count--;
        }
        else
        {
            signal_state ^= signal_state;
            timer2_toggle_count -= timer2_signal_toggle_count;
            timer2_signal_toggle_count = signal_cycle_count;
        }
    }
    else
    {
        TIMSK2 &= ~(1 << OCIE2A);                 // disable the interrupt
        *timer2_pin_port &= ~(timer2_pin_mask);   // keep pin low after stop
    }
}

What I hope this is doing is 32 toggles at the carrier speed (ie 16 full cycles of 57600Hz), followed by 32 'silent' toggles where nothing happens, followed by another 32 at carrier speed, etc.  I should then be able to fire using:

digitalWrite(signalPin, HIGH);
carrierTone.playPulse();
delay(60);
digitalWrite(signalPin, LOW);

But that doesn't set off the sensor, whereas the simple code below works.

carrierTone.play(57600, 50);
signalTone.play(1800, 50);


texts: When uploading a sketch to an esp8266, isn't that the same as "flashing firmware"?

texts: I thought that I read that using a PC running the Arduino IDE to "upload a sketch" to an esp8266 overwrites the original firmware (with the AT commands), and is actually "flashing the firmware" each time a "sketch" is uploaded. If I have that right, then why does the esp8266 WiFi still visible in available connections? There must be some code instructing the esp8266 to do this, but where is it? My sketch was simply the hello blinky thing and contained no #include statements. Where have I slipped?


texts:
There is tons of information on how IR remote controls work and how to use an Arduino to decode those signals and use any IR remote to suit your project. But I couldn't find much info about 2.4G RF remotes.

I want to control a string of addressable LEDs and cycle through different patterns using one of these 2.4G RF remotes

Is it possible to use these remotes with Arduino? If yes, how can I read the signals and assign tasks to different buttons on the remote?


texts: nodemcu POST request over https return error code -1

texts:
I have a nodejs application deployed and have been trying to send data to the api using the following sketch on my nodemcu:

#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>

void setup() {

Serial.begin(115200);
WiFi.begin("mySSID", "myPassword");

while (WiFi.status() != WL_CONNECTED)

delay(500);
Serial.println("Waiting for connection");

}

void loop() {

if(WiFi.status()== WL_CONNECTED){ //Check WiFi connection status

  HTTPClient http;
  http.begin("https://www.livesessions.host/api/v1/readings" , "cc2707645d0222700161a174671cb8b0258eaa91");
  http.addHeader("Content-Type", "application/json");
  String postMessage = "{'deviceMAC':'ddd eee fff', 'humidity':'99', 'soilTemp':'88'}";
  int httpCode = http.POST(postMessage);
  Serial.print("http result:");
  Serial.println(httpCode);
  http.writeToStream(&Serial);
  String payload = http.getString();
  http.end();

  }else{

    Serial.print("Error in Wifi connection");

}

delay(30000); //Send a request every 30 seconds

}

Although I am able to make data entries using the api and postman, the below code returns -1 (which I think is connection refused), the website is an https site.
Please advise on what I am doing wrong.
Thanks.


texts:
I am making a stream-based radio clock that needs to send snippets of the stream to an external API for music recognition using an ESP-WROOM-32 DevKit.

The snippets that I record are 15 seconds long, which results in a file ~2MB in size (assuming the stream is 128Kbps, MP3). If I try to buffer this in the ESP32's RAM, it will fill it up in no time.

How can I send that snippet via HTTP without overflowing the ESP's RAM?


texts: Arduino Pro Mini and GDEW0154T1 ePaper (e ink) display

texts:
I just got my Arduino Pro Mini and GDEW0154T1 ePaper display (GDEW0154T1 display) and I'm trying to figure out a way to make them "talk". I started reading documentation and multiple sites but I still have no idea. I bought Breadboard, USB connector for Arduino and cables.

I think I need some port to connect display to Breadboard. Could you tell me where to look for it? What next?

Thank you for any advice!


texts: I am using a KY-005 with an Arduino Uno. I have the knowledge that Arduino can provide a forward current of 40 mA. How can I make it to 55 mA or above upto 60 mA to unlock its full potential, so as to get efficient IR communication without data being distorted at the KY-022 IR receiver?


texts: Is it possible to receive a 9 bit protocol on the Arduino Uno with Arduino?

texts:
I want send and receive a 9 bit async-serial protocol with 4800 baud on my Arduino Uno, i have read on the specification from the ATmega328P that the uart can do that.
My aim is that when my Uart receive the 9th bit as a 1 he must throw a interrupt. On this interrupt i can recognize that this byte was an adress byte.
When he receive a zero he sould do nothing spezial, only transmit it as hex-byte over usb to the pc.

My Problem now, i can´t initialize the Uart right because the command Serial.begin(4800, config) is not enough, i must throw the interrupt and translate the data to hex-bytes.
My Question can i modify the Serial.begin() source code respectively where can i find the source code for the Serial.begin function?

When there is no possibility to change the code has someone a other option for me to send and receive the 9 bit protocol with an Arduino Uno?


texts:
I am using the FastLED library in my program and the basic usage is that the following lines go at the top of the main sketch:

#include <FastLED.h>
#define NUM_LEDS 60
#define DATA_PIN 6

You can see the documentation at https://github.com/FastLED/FastLED/wiki/Basic-usage

However, I am using the FastLED library in several different objects in my program and I would like to be able to reference NUM_LEDS in different header files for each object so that the number of LEDS can be controlled just by changing the value in the main sketch.

I am also intending that my own objects can be made into libraries for others to use, so they will then define the settings in their main sketch, that my libraries will then use.


texts: Conditional compilation depending on sizeof(double)

texts:
Is there a macro (#define ...) somewhere in the bowels of Arduino IDE or core header files which tells me at compile time(!), if the double data type for a given platform/board is a true double precision floating point number (64 bit width) or "only" an alias for a single precision float (32 bit width)?
With Arduino, both can be the case. 8-bit AVR boards have double equal to float, ARM-based boards (like Arduino Zero) support "true" double precision.
I am working on a library which implements some bit-banging of floating point numbers (both single and double precision). Due to the low-level nature of the problem, there must be separate functions for float and double. I would like to do somthing like that:
uint32_t function_for_float(float f) {
    // function body here...
}

#if defined(HAS_64_BIT_DOUBLE)
uint64_t function_for_double(double d) {
    // function body here...
}
#endif

That way, a compile time error would be generated if somebody tried to use the "double" version on platforms which do not support the "true" double data type. I want the compiler error to be generated, because function_for_double() will do silently "the wrong thing" when fed a single precision float, leading potentially to difficult-to-debug problems.
Right now, I am defining a macro constant for every relevant board I own, like this:
#if defined(ARDUINO_SAMD_ZERO) \
 || defined(SAMD_FEATHER_M0_EXPRESS) \
 || defined(ADAFRUIT_FEATHER_M4_EXPRESS)
    #define HAS_64_BIT_DOUBLE
#endif

But this is ugly and not future-proof (new boards can/will become available...).
Any suggestions?


texts: Getting maxretry error when trying to ping using python requests or urllib3

texts:
I have written this code working on SimpleHost example from ESP8266Ping library,

the code works,

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

#define HTTP_REST_PORT 80

const char* ssid     = "usernaem";
const char* password = "password";

const char* remote_host = "10.10.10.12";

ESP8266WebServer http_rest_server(HTTP_REST_PORT);

void get_online_status() {
  StaticJsonBuffer<200> jsonBuffer;
  JsonObject& jsonObj = jsonBuffer.createObject();
  char JSONmessageBuffer[200];

  Serial.print("Pinging host ");
  Serial.println(remote_host);

  if(Ping.ping(remote_host)) {
    Serial.println("Success!!");
    jsonObj["roku_express"] = 1;
  } else {
    Serial.println("Error :-(");
    jsonObj["roku_express"] = 0;
  }
  jsonObj.prettyPrintTo(JSONmessageBuffer, sizeof(JSONmessageBuffer));
  http_rest_server.send(200, "application/json", JSONmessageBuffer);
}

void config_rest_server_routing() {
    http_rest_server.on("/", HTTP_GET, []() {
        http_rest_server.send(200, "text/html",
            "Welcome to the ESP8266 REST Web Server");
    });
    http_rest_server.on("/ping", HTTP_GET, get_online_status);
}

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

  // We start by connecting to a WiFi network

  Serial.println();
  Serial.println("Connecting to WiFi");

  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(100);
    Serial.print(".");
  }

  Serial.println();
  Serial.print("WiFi connected with ip ");
  Serial.println(WiFi.localIP());
  config_rest_server_routing();
  http_rest_server.begin();
  get_online_status();
}

void loop(void) {
  http_rest_server.handleClient();
  }

if I try to access my wemos D1 Mini from web browser I get correct message :
if offline

{
  "roku_express": 0
}

if online

{
  "roku_express": 1
}

but if I try to get the REST URL from python code either using requests or urllub3

import urllib3
http = urllib3.PoolManager()
url = "http://10.10.10.4/ping"
response = http.request('GET', url)

I get below error

  MaxRetryError: HTTPConnectionPool(host='10.10.10.4', port=80): Max
  retries exceeded with url: /ping (Caused by
  NewConnectionError(': Failed to establish a new connection: [Errno -536870212]
  Unknown error: -536870212'))


texts: I am new to arduino programming. I want to sense temperature and send it to a server in my college. I am using Arduino Uno R3 board which has ATmega 328P micro-controller. I am able to get serial output on my PC but is there a way in which I can send temperature data to the server in a packet format using Arduino Programmer and not using Ethernet Shield ? Please answer in a less complex way.


texts: How to store firmware configuration or image in source-control?

texts:
I'm writing an Arduino application in C/C++ and I'm storing my source code in Github.

However, to make my code runnable, I have had to install multiple libraries through the Arduino desktop tool like this:

And I have had to update the firmware and certificates through the Arduino desktop tool like this:

How can I store these firmware updates, library changes and certificates in source control? Is there a binary image I can download and check in? Better yet, is there some plain-text source file that I can check-in to derive such a binary?


texts: Connect the output of an Arduino to the input from another Arduino

texts:
I'm making a project and i'm trying to send bits from an Arduino to another Arduino with the digital pins. So my setup are 2 Arduino's connected with a jumper.
I connected the grounds and they have both a different power supply.
Now I tried this set-up and as soon as I connect the output pin to the input pin from the other Arduino the voltage lowers from 5V to 2.6V so we can't detect our bits.
Anybody an idea how to solve this problem?

Thanks in advance!

Kind regards,
Manu


texts:
I'm using a simple IR receiver connected to the Arduino through A0 analog pin. The problem is that I want to stabilize the output of IR receiver when it's not receiving an IR signal from a specific IR source, or at least minimizing the disruption to a specific range that I can handle, no matter where its position, But in my case moving the IR receiver a few inches in any direction will results in different voltage output. the difference between values on disruption is very random to handle.

What can I do to isolate IR receiver, may be a specific material or a specific color?


texts: Sensing concentration of methane with MQ-4 methane sensor?

texts:
I'm on a project to sense any amounts of methane in the home. I have bought the popular MQ-4 methane sensor from SparkFun: https://www.sparkfun.com/products/9404

I've looked online for any sample code, but I am confused as to whether the input from the sensor is already given in parts per million, or it is just a voltage. To be specific, here is the sample code the data sheet for the sensor gives:

int sensorValue;

void setup()
{
  Serial.begin(9600);      // sets the serial port to 9600
}

void loop()
{
  sensorValue = analogRead(0);       // read analog input pin 0
  Serial.println(sensorValue, DEC);  // prints the value read
  delay(100);                        // wait 100ms for next reading
}

I have also used a breakout board for these sensors: https://www.pololu.com/product/1479
The sensor is soldered on it, along with a 20K ohm load resistor, like how the spec. sheet specifies.
However, I am confused on the readings I am getting. It's always something that ranges between 259 and 261. Is this ppm of methane in my home? If it is, shouldn't the normal level be 0? I currently have no methane based heating. Or is the 259 - 261 voltage?

Thanks for any help.


texts: How to send MFRC522 data to a C# app using a NodeMCU TCP server?

texts:
I am trying to send MFRC522 data to a C# application through a NodeMCU acting as an access point for the C# app. I have modified the code I got from this site.

#include ESP8266WiFi.h>
#include SPI.h>
#include MFRC522.h>

const char* AP_SSID ="IoT4143" ;
const char* AP_PASSWORD ="iot4143";

#define RST_PIN D3
#define SS_PIN D4

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

WiFiServer server(80);
WiFiClient client;

void wifiConnect() {
  WiFi.disconnect();
  WiFi.softAP(AP_SSID, AP_PASSWORD);

  int watchDog = 0;
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    watchDog++;
    if(watchDog == 60) {
      WiFi.disconnect();
      WiFi.printDiag(Serial);
      watchDog = 0;
      return;
    }
  }
  server.begin();
}

void setup() {
  Serial.begin(115200);
  SPI.begin();      // Init SPI bus
  mfrc522.PCD_Init();   // Init MFRC522
  mfrc522.PCD_DumpVersionToSerial();  // Show details of PCD - MFRC522 Card Reader details
  Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
  wifiConnect();
}

void loop() {
  //Are we connected to WiFi?
  if(WiFi.status() != WL_CONNECTED) {
    wifiConnect();
  }

  //Wait for a connection attempt
  client = server.available();
  if (!client) {
    return;
  }

  // Wait until the client sends some data
  int watchDog = 0;
  while(!client.available()) {
    delay(1);
    if(watchDog == 10000) {
      watchDog = 0;
      return;
    }
    watchDog++;
  }
  sendData();
}

void sendData() {
  // Read the first line of the request
  String request = client.readStringUntil('\r');
  client.flush();

  // Match the request
  while(request=="READSTOP") {
    Serial.println("RFID READING STARTED..."); //Forward to C# App
    if (!mfrc522.PICC_IsNewCardPresent()) {
      return;
    }
    // Select one of the cards
    if (!mfrc522.PICC_ReadCardSerial()) {
      return;
    }
    // Dump debug info about the card; PICC_HaltA() is automatically called
    client.print(mfrc522.uid));
  }
  Serial.println("RFID READING STOPPED"); //Stop server
  delay(1);
  client.stop();
}

I am very new to hardware/network programming. I don't know what will be possible errors in this code and whether it will work or not.

When I verified the code in the Arduino IDE, there was an error on this line of code:

client.print(mfrc522.uid));

  error:= no matching function for call to 'WiFiClient::print(MFRC522::Uid&)'

When the connect button in the application is clicked the "READSTART" string is sent to NodeMCU and when disconnect is clicked the "READSTOP" string is sent.

Please help!


texts: Passing reference to hardware between methods in custom class

texts:
I'm a C++ / Arduino newbie, trying to build a custom library for the first time. I created a unit called CDSensors.cpp, which has two methods, SetupSensor and ReadSensors. The sensor is a SparkFun accelerometer/magnetometer.

If there are any errors in the settings, the sensor returns all zeros for compass and accelerometer. If there is no pointer or other connection between the SetupSensor and ReadSensor methods, the sensor returns all zeros as if it hasn't been setup.

So I'm trying to pass a reference to the sensor library between the methods as shown with the Limu object in the code below. I now get mag data but the accelerometer returns all zeros so something in my object references is messing with the sensor setup? (the accelerometer works ok in the SparkFun demo code, on which my code is based).

Main.ino

#include <CDSensors.h>
#include <Wire.h>
#include <SPI.h>
#include <SparkFunMPU9250-DMP.h>

CDSensors* LSensors = &CDSensors     (0);
CDSerialPrint* LSerialPrint = &CDSerialPrint (0);
MPU9250_DMP Limu = MPU9250_DMP ();
unsigned long LTimeNow = 0;

struct meas {
  int BUx;
  int acc_x
};

struct meas r;

void setup() {
  LSensors->SetupSensors (Limu);
}

void loop() {
  LSensors->ReadSensors  (Limu, LTimeNow, r.BUx, r.acc_x);
  Serial.print((int) (r.BUx) );
  Serial.print((int) (r.acc_x) );
}

CDSensors.h

#ifndef CDSensors_h_h
#define CDSensors_h
#include <Wire.h>
#include <SPI.h>
#include <SparkFunMPU9250-DMP.h>

class CDSensors {
  public:
    CDSensors(int);
    static void SetupSensors(MPU9250_DMP *imu);
    void ReadSensors (MPU9250_DMP *imu, unsigned long& TimeNow, int&     BUx,int& BUy,int& BUz,int& acc_x,int& acc_y,int& acc_z,int& a0,int& a1,int& a2,int& a3 );
  private:
    int value;
};
#endif

CDSensors.cpp

#include <Wire.h>
#include <SPI.h>
#include <SparkFunMPU9250-DMP.h>
#include "CDSensors.h"

//MPU9250_DMP imu;
boolean       MPU9250_found = false;
unsigned long TimeNow = 0;
CDSensors::CDSensors(int givenValue) {
  value = givenValue;
}

static void CDSensors::SetupSensors(MPU9250_DMP imu) {
  if (imu.begin() != INV_SUCCESS) {
    while (1) {
      Serial.println("No MPU-9250 found, Check connections");
      delay(5000);
    }
  }
  imu.setSensors(INV_XYZ_ACCEL | INV_XYZ_GYRO | INV_XYZ_COMPASS);
  imu.setGyroFSR(2000);
  imu.setAccelFSR(2);
  imu.setLPF(188);
  imu.setSampleRate(100);
  imu.setCompassSampleRate(100);
}

void CDSensors::ReadSensors(MPU9250_DMP imu, unsigned long& TimeNow, int& BUx, int& acc_x) {
  TimeNow = millis();
  if (imu.dataReady()) {
    imu.update(UPDATE_ACCEL | UPDATE_GYRO | UPDATE_COMPASS);
  }
  BUx = imu.calcMag(imu.mx);
  acc_x = imu.calcAccel(imu.ax);
}


texts:
I have built a basic obstacle avoidance robot. When the sensor senses an obstacle it gives a RISING interrupt to pin 2. At this moment I want the robot to come back for 2 seconds and turn right for 2 seconds.

I have code to turn back and rotate right but I cannot use the delay() function inside the ISR so how do I code this?


texts:
The Space Replay
A hovering object that explores and manipulates transitional public
spaces with particular acoustic properties. By constantly recording
and replaying these ambient sounds, the levitating sphere produces a
delayed echo of human activity.

In this project, the Arduino board and an Adafruit Wave Shield is used. The Wave shield is not designed to record audio however, they say that they use the board for both recording and playback.

The sphere responds sonically to people and its surroundings by means of a battery-powered Arduino, an Adafruit Wave Shield hacked to record and playback audio on-the-fly and a small speaker.

This generates a few questions.

How would this be done?
Where would the microphone be placed inside the balloon for decent audio capture?
Would there be a better way to design this?


texts:
I am working on a project on Arduino OLED MAX6675 thermocouple and SSR for my oven.
My problem is when my SSR goes in LOW or HIGH state it  turn ON and OFF several times before going to permanent HIGH or LOW state.
This make my load(Heater) on and off many times. Since the temperature crosses the set-point to change the output state, the process temperature will be cycling rapidly, going from below set-point to above, and back below.
This frequent ON OFF will damage my SSR and heater.
My Question.
Is there any hardware or software solution. To reduce the frequency of ON OFF .
I can’t increase  the delay() time because it make my button input slow.
My codes are below.

#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include "max6675.h"

//oled
//oled i2c addresss
#define OLED_ADDR 0x3C
Adafruit_SSD1306 display(-1);
// 128 x 64 pixel display
#define SSD1306_LCDHEIGHT 64

//MAX6675
//Pin initialization
int so = 2;
int cs = 3;
int sck = 4;
MAX6675 thermocouple(sck, cs, so);
float current_temp;
int set_temp;
int const h_temp = 2;

//Button
int button_up = 7;
int button_down = 8;
int button_upv;
int button_downv;

//SSR
int ssr_u = 10;
int ssr_d = 12;

void setup() {
    Wire.begin();
    delay(1000);

    // initialize and clear display
    display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
    display.clearDisplay();
    display.setTextSize(2);
    display.setTextColor(WHITE);
    display.setCursor(8, 20);
    display.println("Welcome..");
    display.display();
    display.clearDisplay();
    delay(1000);

    //Button
    pinMode(button_up, INPUT);
    pinMode(button_down, INPUT);
    set_temp = 20;
    pinMode(ssr_u, OUTPUT);
    pinMode(ssr_d, OUTPUT);
}

void loop() {
    current_temp = thermocouple.readCelsius();
    delay(100);
    button_upv = digitalRead(button_up);
    button_downv = digitalRead(button_down);

    //button
    if (button_upv == HIGH && set_temp < 180) {
        set_temp = set_temp + 5;
    }
    if (button_downv == HIGH && set_temp > 20) {
        set_temp = set_temp - 5;
    }

    display.clearDisplay();
    display.setTextSize(2);
    display.setTextColor(WHITE);
    display.setCursor(5, 10);
    display.println(current_temp);
    display.setCursor(5, 30);
    display.println(set_temp);

    display.setTextSize(2);
    display.setTextColor(WHITE);
    display.setCursor(30, 40);
    if (button_upv == HIGH) {
        display.println("Up");
    }
    if (button_downv == HIGH) {
        display.println("Down");
    }
    display.display();

    //SSR
    if (current_temp < set_temp - h_temp) {
        digitalWrite(ssr_u, HIGH);
        digitalWrite(ssr_d, HIGH);
        delay(500);
    }
    if else(current_temp > set_temp + h_temp) {
        digitalWrite(ssr_u, LOW);
        digitalWrite(ssr_d, LOW);
        delay(500);
    }
}

Thanks in advance for help


texts: white screen : 2.8" TFT LCD Screen Module: HY-280TFT

texts:
i have a problem with my new  2.8" TFT LCD Screen Module HY-280TFT.i connect it with an Arduino Uno board like this way:
 Connect HY-TFT280 to Arduino UNO

LEDA -> 5V
LEDK -> GND
VCC -> 5V
RD -> 3.3V
GND -> GND
DB0->DB5 to D8->D13
DB6->A0
DB7->A1
DB10->DB17 to D0->D7
RSET->A2
CS->A3
WR->A4
RS->A5

i downloaded and installed the new UTFT library. then i tested the example : Arduino(AVR)->UTF_Demo_320x240 , but i always have a white screen.
In the code, i change

UTFT myGLCD(ITDB32WD,38,39,40,41); by UTFT myGLCD(ITDB32WD,A5,A4,A3,A2);

but i still have the white screen

please what can be the problem? thank you


texts:
Bit of a noob here. Im trying to use the sensor number (float) in my mqtt topic, but cant seem to get this right. Any help would be appreciated. Keep getting this error (cast from 'char*' to 'char' loses precision)

      char buffer2[5];

       dtostrf(sensor.sensor_no, 4, 2, buffer2);
     char* buffer4 = mqtt_topic + char(buffer2);

  dtostrf(sensor.dht22_t,0, 0, buffer);
     client.publish(buffer4, buffer); //Topic name


texts: Using a 4*4 keypad to enter an integer value

texts:
I have a 4*4 keypad and I want to use it to enter a number.  I will then use this number as a delay to a LED or a motor to run for the specified time.
This is my sample code:

#include<Keypad.h>
#include<LiquidCrystal.h>
const byte numRows = 4; //number of rows on keypad
const byte numCols = 4; //number of columns on keypad

char keymap[numRows][numCols]=
{
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'X', '0', 'Y', 'D'}
};

char value[4]="";
int index = 0;

byte rowPins[numRows] = {22,23,24,25}; //Rows 0 to 3
byte colPins[numCols]= {26,27,28,29}; //Columns 0 to 3

Keypad key= Keypad(makeKeymap(keymap), rowPins, colPins, numRows,numCols);

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

void setup() {
Serial.begin(9600);
pinMode(13,OUTPUT);
lcd.begin(20,4);

lcd.print("       WELCOME      ");
delay(100);
}

void loop() {
char keypress = key.getKey();
while (keypress != NO_KEY){
  if (keypress == 'X'){
      lcd.clear();
      for(int j=0;j<=4;j++){
        value[j]=0;
      }
      index=0;
      }
   else if (keypress == 'Y'){
      int amt = atoi(value);
      digitalWrite(13, HIGH);
      delay(amt);
      }
   else
      value[index]=keypress;
      index++;
    }
}

How do I read the value returned by the keypad as an integer?  (When I press 3 I want to read 3 not "3").


texts: Does Leonardo need a separate power supply?

texts:
I'm currently using an Arduino Uno (R3), but want to switch to Leonardo for the USB-ability. The Uno can work from the USB's 5V. Looking at the Leonardo's schematic it seems the only input to the voltage regulator is from the power connector. This makes sense as it's a 5V regulator which needs > 5V in. But I don't see the MOSFET which connects the USB's 5V to the board's 5V, like there's one on the UNO.

So, does the Leonardo need the separate power input connected?


texts: Can I run more than 2 servo motors smoothly, connecting their power to regulated limit voltage and signal wires to the digital pins of the arduino?

texts:
Now my next project is going to be about Servo Motors and for that, I don't want to buy any shield or motor driver for Servos. So I have designed a circuit, to drive 12 servos at a time without any interruptions. I haven't got any Servos yet, well my order is shipped already...Keeping that aside lets head down to the connection..

The Screenshot was taken from a circuit designed by me at tinkercad.com.
Parts:

HiWatt Battery (Standard 9 volts battery blue and white coloured)

SG90 Servo Motor
(6v 400mah max)
(Resistance of each of them is 1.4kohm, when connected power and ground of multimeter)

Arduino
(Required amp is 40*12)

The circuit Explanation:

The Orange wires of servos are signal wires connected to the pins of Arduino.

A 750 ohm resistor is connected to the positive terminals of each motor, from which, voltage is regulated for the motor.

The motor grounds have been connected to the ground of the battery.

Ground of Arduino has been connected to the ground terminal of the battery. So now, ground of the battery and the Arduino is same.

All the motors are connected in parallel connections with 750 ohm resistors at the positive terminal of each motors

So now my question is, How many servos will I be able to run when I power them parallel-ly using a standard 9 volts battery (HI-WATT, Blue and white one), if no, Which will be the best battery for doing it?
I need to run 12 Servos uninteruptedly.
Thanks for your precious time....


texts: Connecting battery and LED to Arduino Due

texts:
I am brand new to Arduino/robotics and am trying to take baby steps. First I'd like to just power an Arduino and an LED from a 9V battery like so:

No programming, just simple circuitry. The battery powers the Due, and the Due in turn powers the LED.

A few concerns here:

Will the 9V battery fry the Due, which I believe is expecting 3.3V? If so, what can I do to reduce the voltage/amps?
Will the 9V battery fry the resistor and/or LED?
As you can see by my question marks, I'm not real sure where to connect the battery to the Due (both positive & negative terminals) as well as the where to connect the breadboard to the Due (again, both terminals).

Any ideas?


texts:
The code I have works for the most part but when I send data via bluetooth received over software serial, too quickly, it is not parsed correctly.

I'm a bit stuck with what can be done to a void the incorrect formatting, since it works correctly if I send data slowly.

I could have a buffer to not send data more than once every set amount of time, but more responsiveness is preferred.

I am sending a string "center:255,0,255;"
it saves the command in a char array untill it sees the ":", then it saves the red in a  char array breaking on "," then same for the blue and green. when it  reaches the ";" it send the four arrays to print to a console. Later it the data will be used to light specific leds based on the command, but when I send data too quickly it gets parsed incorrectly, for example:

command: center
red:195
green:0
blue:255
command: center
red:208
green:0center:221
blue:0,255
command: center
red:246
green:0
blue:255

the 'green:0center:221' isnt correct, its either not seeing the "," or seeing the ";" too soon. Not sure how to avoid it.

#include <SoftwareSerial.h>
SoftwareSerial mySerial(6,7); // RX, TX

void setup() {
  Serial.begin(9600);
  mySerial.begin(57600); //required when using the hm-10 with an arduino nano
  mySerial.listen();
}

void loop() {
  while (mySerial.available () > 0) {
    processIncomingByte (mySerial.read ());
  }
}

const unsigned int MAX_INPUT = 50;

void processIncomingByte (const byte inByte) {
  static int parse_the_string = 0;
  static char command [MAX_INPUT];
  static char red [MAX_INPUT];
  static char green [MAX_INPUT];
  static char blue [MAX_INPUT];
  static unsigned int input_pos = 0;
  switch (parse_the_string) {
    case 0:
      switch (inByte) {
        case ':':
          command [input_pos] = 0;  // terminating null byte
          input_pos = 0;
          parse_the_string ++;
          break;
        default:
          if (input_pos < (MAX_INPUT - 1))
            command [input_pos++] = inByte;
          break;
      }
      break;
    case 1:
      switch (inByte) {
        case ',':   // end of text
          red [input_pos] = 0;  // terminating null byte
          input_pos = 0;
          parse_the_string ++;
          break;
       default:
          if (input_pos < (MAX_INPUT - 1))
            red [input_pos++] = inByte;
          break;
      }
      break;
    case 2:
      switch (inByte) {
        case ',':   // end of text
          green [input_pos] = 0;  // terminating null byte
          input_pos = 0;
          parse_the_string ++;
          break;
        default:
          if (input_pos < (MAX_INPUT - 1))
            green [input_pos++] = inByte;
          break;
      }
      break;
    case 3:
      switch (inByte) {
        case ';':   // end of text
          blue [input_pos] = 0;  // terminating null byte
          // terminator reached! process input_line here ...
          process_data (command, red, green, blue);
          input_pos = 0;
          parse_the_string = 0;
          break;
        case '\r':   // discard carriage return
          break;
        default:
          if (input_pos < (MAX_INPUT - 1))
            blue [input_pos++] = inByte;
          break;
      }  // end of switch
      break;
    default:
      break;
  }
}

void process_data (const char * command, const char * red, const char * green, const char * blue)
  {
  // for now just display it
  Serial.print ("command: ");
  Serial.println (command);
  Serial.print ("red:");
  Serial.println (red);
  Serial.print ("green:");
  Serial.println (green);
  Serial.print ("blue:");
  Serial.println (blue);
  }


texts: How to declare a global variable in the .h file?

texts:
I have a .h library file in which I want to declare a global variable that can be read in the program loop and in the library's .cpp file.

The question is, is it possible to declare a variable in the .h file and make it global?


texts:
Am I able to send instruction from my computer, from another compiler, via the Arduino USB port?

To put this in context, I'm doing some vision processing on my computer, with Visual Studio, and I want to send some motor output via USB for the Arduino to execute.


texts: Writing data from multiple sensors in burst mode to an Arduino Due

texts:
I need help developing a simple sketch that can read data simultaneously from 3 analog accelerometers and send it in 'burst mode' to be stored on an SD card, to reduce the effect of latency.

I used this library to get my accelerometers to work properly, but I'm just having difficulty coming up with a sketch in the code to getting all the acceleration data out in bursts.

Your help will be much appreciated.

What I meant by 'burst mode' is that all acceleration data from all three sensors connected to the Arduino should be saved at once to the file on the SD card (a temporary measure, as I'll have to send this data via Bluetooth to a base station as I build the system up to be able to receive more data from multiple Arduinos).

Although there would be a delay of about 1/10th of a second between each reading from the three sensors, the idea behind it is to be able to read and write off the data in this said simultaneous burst mode at a high sample rate (this will be adjusted with an oscilloscope at a later stage) to prevent data from being lost or chunked up.

Here is a link to the datasheet as requested.


texts: How to upload Arduino sketches to Atmel chips

texts:
I am new in this Arduino coding world and I was trying to make a project. I normally used Arduino Unos all the time, but I was facing a problem and that is that the Arduino Uno has only 13 digital pins and 6 analog pins, and some of my friends advise me to use an Arduino Mega, but that costs too much, some to my friends also tell me that I could use only a Atmel chip, which will save money.

But the problem is that I can not burn these chips without a burner. I see online that Arduino Uno has Arduino ISP options also that will allow you to bootload or upload Arduino sketches to those kind of chips, but I have been trying for over 3 months and I cannot figure out how to do that

At present I am working with the ATmega8 chip.

This is my problem:

Using stk500v1 but the problem is not resolved


texts:
How to count +1 all the time if LED blinks with LDR sensor

Image:

If i turn on led it must count into serial monitor 1 and if i turn off led and turn on again then it counts 2.

To turn on led I must put my hand into LDR sensor.

It also looping text in serial monitor "First LDR sensor is Dark".

int ledPin1 = 7;
int ledPin2 = 8;
int ledPin3 = 9;
int ldrPin1 = A0;
int ldrPin2 = A1;
int ledTest = 200;
int ldrStatus1 = 0;
int ldrStatus2 = 0;
int ledCheck1 = 0;
int ledCheck2 = 0;
int Count = 0;

void setup() {

  Serial.begin(9600);
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);

  pinMode(ldrPin1, INPUT);
  pinMode(ldrPin2, INPUT);
}

void loop() {

  ldrStatus1 = analogRead(ldrPin1);
  ldrStatus2 = analogRead(ldrPin2);

   if (ldrStatus1 <= ledTest) {
    digitalWrite(ledPin1, HIGH);
    Serial.println("First LDR is Dark");
    ledCheck1 = 1;
    Count++;
    Serial.println(Count);
   } else {
    digitalWrite(ledPin1, LOW);
    ledCheck1 = 0;
   }

   if (ldrStatus2 <= ledTest) {
    digitalWrite(ledPin3, HIGH);
    Serial.println("Second LDR is Dark");
    ledCheck2 = 1;
    Count++;
    Serial.println(Count);
   } else {
    digitalWrite(ledPin3, LOW);
    ledCheck2 = 0;
   }

   if ((ledCheck1 == 1) && (ledCheck2 == 1)) {
    digitalWrite(ledPin2, HIGH);
    Count++;
    Serial.println(Count);
   } else {
    digitalWrite(ledPin2, LOW);
   }

}

At the moment it counts when it is turned on, like seconds..
How to fix or make it work correctly?


texts: How to prevent optocoupler to activate when resetting the arduino?

texts:
From various example on how to use optocouplers ( eg 4N25)  I gathered that they
work in inverted way meaning that for the optocoupler to output a signal,
the input LED must be OFF.

This is very easy to process by code as I just need to use digitalWrite LOW
instead of digitalWrite HIGH to activate the output of the optocoupler.

My problem is that when I reboot the arduino, the optocupler LED goes OFF and thus activate the ouput of the optocoupler for a few seconds until the code is loaded on the arduino.

How can I prevent this behavior ? Should I connect the optocoupler in a non inverted way ? ( And if so how ? ). Should I use an inverter ?


texts:
I programming atmega328P bootloaded with an FTDI.

Some tutorial mentions that you have to connect the DTR to the reset pin:

http://electronics-diy.com/FT232RL_USB_to_Serial_Adapter_for_PIC_AVR_ATMEGA_ARDUINO_MCUs.php

Is that so? Because some don't, they just say rx,tx is enough. I still can't program the chip with the error:

 avrdude -p m328p -P /dev/ttyUSB0 -c avrisp -b 9600 -n -v -v -v

avrdude: Version 5.11.1, compiled on Oct 18 2011 at 21:17:35
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "/etc/avrdude.conf"
         User configuration file is "/root/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : /dev/ttyUSB0
         Using Programmer              : avrisp
         Overriding Baud Rate          : 9600
avrdude: ser_recv(): programmer is not responding
avrdude: stk500_recv(): programmer is not responding

avrdude done.  Thank you.

I tried different baud rates, no matter what it's not responding. Linux recognizes the FTDI as:

Sat Feb 13 22:52:14 2016] ftdi_sio ttyUSB0: FTDI USB Serial Device converter now disconnected from ttyUSB0
[Sat Feb 13 22:52:14 2016] ftdi_sio 1-2.1:1.0: device disconnected
[Sat Feb 13 22:52:19 2016] usb 1-2.1: new full-speed USB device number 73 using uhci_hcd
[Sat Feb 13 22:52:20 2016] usb 1-2.1: New USB device found, idVendor=0403, idProduct=6001
[Sat Feb 13 22:52:20 2016] usb 1-2.1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[Sat Feb 13 22:52:20 2016] usb 1-2.1: Product: FT232R USB UART
[Sat Feb 13 22:52:20 2016] usb 1-2.1: Manufacturer: FTDI
[Sat Feb 13 22:52:20 2016] usb 1-2.1: SerialNumber: A6004mhS
[Sat Feb 13 22:52:20 2016] ftdi_sio 1-2.1:1.0: FTDI USB Serial Device converter detected
[Sat Feb 13 22:52:20 2016] usb 1-2.1: Detected FT232RL
[Sat Feb 13 22:52:20 2016] usb 1-2.1: FTDI USB Serial Device converter now attached to ttyUSB0
[Sat Feb 13 22:56:25 2016] usb 1-2.1: USB disconnect, device number 73
[Sat Feb 13 22:56:25 2016] ftdi_sio ttyUSB0: FTDI USB Serial Device converter now disconnected from ttyUSB0
[Sat Feb 13 22:56:25 2016] ftdi_sio 1-2.1:1.0: device disconnected

Well my questions now are:

1, When I use the Arduino IDE to program a barebone 328P with this FTDI what should be the BOARD and what should be the PROGRAMMER?

Right now I have it on Arduino Nano/Atmega328 + AVRISP mkII

Although I tried almost all... I think something else is wrong.

2, Should I be able to get any result with doing the previous:

 avrdude -p m328p -P /dev/ttyUSB0 -c avrisp -b 9600 -n -v -v -v

command WITHOUT connecting the barebone chip? I think not, since this doesn't act like a fully fledged MCU just like a serial converter.

Thanks


texts:
So I recently bought a Lilypad and a Prolific PL-2303HX which I only discovered when connecting it to the computer has phased out since 2012. I found a video online which shows the solution was to install an older driver so that's what I did.

However, now I have trouble uploading code to the Lilypad, even basics such as Blink. During the upload, the Lilypad blinks very rapidly, but then it keeps showing:

avrdude: stk500_recv(): programmer is not responding

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

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

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

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

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

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

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

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

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

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

I have tried pressing the reset button when it's uploading but that hasn't worked. Is it because of the phased out Prolific?


texts: Search for a certain combination of strings in serial and read the following characters until another set character stops the search

texts:
I have the following serial message that I'm receiving from an ESP32 running GRBL:
<Idle|MPos:158.500,0.000,0.000|FS:0,0|Pn:H|Ov:100,100,100|SD:0.21,/instruction.nc>

I want to check the value after SD: which in this case would be 0.21.
It is a value that represents the percentage of a file being read, so values between 100.00 and 0.00 are being sent.
My guess is to look for the SD: in the string and then read all characters until the , but I can't really find a way to realize that.
I found the startsWith() and the substring()function that are able to look for a set of characters in a string, but it seems like they can only check a set amount of characters which in this case doesn't work as 0.00 is 4 characters and 100.00 is 6 characters.
Any help is much appreciated!!


texts: How to include userid, pass to WifiClient connect() api

texts:
These are my remote server credentials that I want to connect from my local device.

Server  m12.cloudserver.com
User    <myname>
Password    <mypassword>
Port    19999
_ or
api_key 5678909876-009-00d

I want to use the WiFiClient client() API as shown, but where or how do I include the User credentials ? so that I can make a successful connection to the remote server from my device connected over Wifi.

Cut and paste from my Arduino code.

const int httpPort = 19999;
if (!client.connect("m12.cloudserver.com", httpPort)) {
 Serial.println("connection failed");
 return;
}


texts: Convert Long to binary - least signifant bit first

texts:
I have found an Arduino function which converts a 2-bytes-long-value to a binary value.

e.g. I call sendCommand(0x05) And it gives me an output:

00000101

void sendCommand(unsigned long command){
  for (unsigned long  mask = 1UL << (7);  mask;  mask >>= 1) {

    if (command & mask) {

    Serial.print( "1" );
    } else {

    Serial.print( "0" );
    }
  }
}

my Problem is, that I want to have the Least significant bit first. How do I have to adjust this function to achieve this?

e.g.
sendCommand(0x05)
shall give an output:

10100000


texts: Arduino ethernet shield not responding to every request because it is busy

texts:
I have a simple HTTP server that monitors a serial port and responds to HTTP requests by sending the value. The serial port constantly outputs data, so that apart from a brief moment when the device is initializing the Arduino always has data available. Once a value is retrieved from the RS232 connection it is stored in a buffer. The buffer is overridden when new values are received.

Occasionally the server does not respond to a request. Monitoring through Chrome developer tools reports net::ERR_CONNECTION_RESET
Could it be that the Arduino is busy with processing the serial port when the connection request is made? What I find very difficult to understand is that once in a while the code below will display "Not available". This shouldn't happen because, as stated above, the buffer is always available.

    client.println("HTTP/1.1 200 OK");
    client.println("Content-Type: text/html");
    client.println("Connection: close");
    client.println("Cache-Control: no-cache, no-store, must-revalidate");
    client.println("Pragma: no-cache");
    client.println("Expires: 0");
    client.println("Refresh: 5");
    client.println();
    client.println("<!DOCTYPE HTML>");
    client.println("");
    client.println("");
    client.print("Value: ");
    if (valueReady()) {
      client.println( getValue() );
    } else {
      client.println( "Not available" );
    }
    client.println("");
    client.println("");

The "Not available" message is really confusing because that should only occur when the Arduino starts. valueReady() will only return false when power is first applied.

The LEDs on the Ethernet shield do not indicate that the Arduino is being reset, but it seems as if the sketch is periodically restarting. Is it possible for a buffer overrun to cause the Arduino to reboot?


texts: Sketch talks to Android via BLE on Serial2 but times out after 5 seconds when Serial cable disconnected or not present

texts:
From an Android phone I am using the "Serial Bluetooth Terminal" app to communicate to an Arduino Mega 2560 with a Bluetooth Low Energy HM10 (Jaycar XC-4382) module connected via Serial2.

If the physical USB serial cable (Serial) is connected to Arduino the very simple sketch below works fine and runs continuously. When the cable is disconnected mid sketch or the power is cycle without the cable connected the sketch will run for about 5 seconds and then stop.

How can I prevent the sketch from timing out when the serial cable is disconnected?

int counter = 0;

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

void loop()
{
    Serial2.print(counter); Serial2.println();
    delay(1000);
    counter++;
}


texts: Arduino-based mains frequency monitor follow-up

texts:
Following my
previous question, I'm getting closer to thinking about putting together this mains frequency monitor. I would just like to do a sanity check on my electronics before I order the components and the board. Please keep in mind I am not qualified in this so I have had to research how all this will work.

A and B inputs will accept power from a 16VAC 1.25A unregulated power pack.

C1 is a 1µF 25V 85°C ceramic capacitor. I guess this is mostly unnecessary as the power pack should filter any DC bias, but it won't hurt.

D1 is an IN4001 1A standard recovery diode.

R1 is a 300ohm 500V 3W resistor. The RMS power is 16VAC, which is half-wave rectified, so that's sqrt(2) * 16 = ~24V peak @ 300ohm = 80mA peak, and about 25mA on average (right?)

IC1 is a 4N28 optocoupler. It's weird, in one data sheet I see 80mA max forward current on inputs but in another I see 60mA. Anyway, the average should be 25mA so I guess that's probably going to be okay?

The Arduino I will use is the Arduino Micro, as it's quite small and also has a 16Mhz crystal oscillator that will provide a more stable clock than a ceramic resonator. The Arduino will be powered by USB, which I believe is 5V. The digital I/O pins I believe will also operate at 5V and are rated at 40mA max.

C will come from one of the Arduino's digital output pins, and D will go to the Arduino's GND.

R2 is a 150ohm 500mW 250V resistor, that should ensure the C→D current does not exceed 40mA @ 5V.

Now, assuming the components look okay and the circuit looks okay (I assume the circuit is fine), I just had some questions:

Do I need to add anything to the output of the 4N28 coming from the input? I think with a regular transistor, some of the base current gets added to the collector current?
What can I expect the response on the output of the 4N28 to look like? I assumed that it would more-or-less be a square wave, where even a tiny current on the input would activate the transistor and allow the output current to flow freely on the other side, but someone has suggested that this might not be the case?
The way it is set up, the Digital I/O pin can be "trying" to output or not, and that's basically irrelevant to what the transistor is doing. When the transistor is on, the output current from the pin will successfully flow to GND. I assume there is a way to detect this in the Arduino? Something like setting the output pin to 1 and check in loop when there is or is no current flowing?

Thank you!


texts: Set Arduino digitalRead reference voltage

texts:
I wanted to know if the reference voltage for the digitalRead() function could be set to a particular voltage, either with an external reference or internally.

In the Arduino reference under the constants heading they have mentioned that they use 3V as reference for the boards I'm using (an Arduino Uno R3). But I want to change it to be a little lower.

Is it possible and if so how?


texts:
I'd like to power an NodeMCU off of four 1.5v batteries.  That's 6v.

Depending on the source I've read that 5.1v will fry the board and, just a few clicks later, that the board will take up to a 20v input.

What is the real, practical input voltage range for an NodeMCU?  Even the spec sheets seem to disagree.


texts:
I have ethernet shield mounted on arduino mega, I am able to run it as server but when i try to run it as client it doesnt work , most of the time it assigns itself 255.255.255.255 ip address which i get to know as i am printing from my sketch using Ethernet.localIP()  it sometimes randomly works but then it does nt establish connection with server, I have double checked there is no firewall on my router that can block arduino ethernet web client.

#include "Ethernet.h"
#include <SPI.h>
#include<dht.h>
dht DHT;

#define DHT11_PIN 8

double tempInC;
int humidity;

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
//IPAddress ip(192, 168, 1, 177);

// Set the static IP address to use if the DHCP fails to assign
IPAddress ip(192,168,1,177);

byte subnet[] = { 255, 255, 255, 0 }; //assigning subnet mask
byte gateway[] = { 192, 168, 1, 1 }; //assigning gateway

EthernetClient client;
char server[] = "192.168.1.3"; // IP Adres (or name) of server to dump data to

String data;

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

  while (!Serial) {
    ; //wait for serial port to connect. Needed for native USB port only
  }
  Ethernet.begin(mac, ip, gateway, subnet);

  Serial.print(F("connected. My IP is "));
  Serial.println(Ethernet.localIP());
  // give the Ethernet shield a second to initialize:
  delay(1000);
  data = "";
}

void loop() {
  int chk = DHT.read11(DHT11_PIN);
  delay(200);
  tempInC = DHT.temperature;
  humidity = DHT.humidity;
  Serial.print("Temp: ");
  Serial.print(tempInC);
  Serial.print(" Humidity: ");
  Serial.println(humidity);
  if (client.connect(server, 80)) {

    // Make a HTTP request:
    client.print(F("GET /arduino/add.php?temp1="));
    client.print(tempInC);
    client.print(F("&hum1="));
    client.print(humidity);
    client.println(F(" HTTP/1.1"));
    client.print(F("Host: "));
    client.println(server);
    client.println(F("Connection: close"));
    client.println();

  }
  else {
    Serial.println(F("connection failed"));
  }

  // if there are incoming bytes available
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }
  else {
    Serial.println("Client not available");
  }
  if (client.connected()) {
    client.stop();  // DISCONNECT FROM THE SERVER
  }
  //  delay(60000); // WAIT FOR A MINUTE BEFORE SENDING AGAIN
  delay(10000);
}

Here is the output of what I get from above sketch

connected. My IP is 255.255.255.255
Temp: 26.00 Humidity: 63
connection failed
Client not available

Even when it gets correct IP assigned which I am setting up in the sketch the connection to server fails.
I am very upset not being able to run client. Please help.


texts: Arduino function to fade from one RGB color to the next

texts:
For my Arduino project I have a Neopixel RGB Strip with 72 LED's.

I can successfully change the colour of any of the LED's (at the moment I'm only setting the first one 0 for testing purposes) so I know my wiring isn't the problem here, it's my coding.

What I would like to do is be able to select a color and then another color and have the first color fade to the next color and so forth (much like the LIFX bulbs behave when using the iPhone application).

This is what I have at the moment:

I am logging output of all the variables to give you an indication of what's going on. I'm not 100% sure on where I'm going wrong or whether there's a much easier way to do what I'm after (I'm open to suggestions).

The function takes a parameter called command, which is a string separated by commas:

e.g. 255, 0, 0 (RED) or 0, 255, 0 (GREEN).

/*******************************************************************************
 * Function Name  : tinkerSetColour
 * Description    : Sets the strip with the appropriate colour
 * Input          : Pin and value
 * Output         : None.
 * Return         : 1 on success and a negative number on failure
 *******************************************************************************/
int Rstart = 0, Gstart = 0, Bstart = 0;
int Rnew = 0, Gnew = 0, Bnew = 0;

int tinkerSetColour(String command)
{
    sprintf(rgbString, "Rstart %i, Gstart %i, Bstart %i", Rstart, Gstart, Bstart);
    Spark.publish("rgb", rgbString);

    sprintf(rgbString, "Rnew %i, Gnew %i, Bnew %i", Rnew, Gnew, Bnew);
    Spark.publish("rgb", rgbString);

    // Clear strip.
    strip.show();

    int commaIndex = command.indexOf(',');
    int secondCommaIndex = command.indexOf(',', commaIndex+1);
    int lastCommaIndex = command.lastIndexOf(',');

    int red = command.substring(0, commaIndex).toInt();
    int grn = command.substring(commaIndex+1, secondCommaIndex).toInt();
    int blu = command.substring(lastCommaIndex+1).toInt();

    int Rend = red, Gend = grn, Bend = blu;

    sprintf(rgbString, "Rend %i, Gend %i, Bend %i", Rend, Gend, Bend);
    Spark.publish("rgb", rgbString);

    // Larger values of 'n' will give a smoother/slower transition.
    int n = 200;
    for (int i = 0; i < n; i++)
    {
        Rnew = Rstart + (Rend - Rstart) * i / n;
        Gnew = Gstart + (Gend - Gstart) * i / n;
        Bnew = Bstart + (Bend - Bstart) * i / n;

        // Set pixel color here.
        strip.setPixelColor(0, strip.Color(Rnew, Gnew, Bnew));
    }

    sprintf(rgbString, "Rnew %i, Gnew %i, Bnew %i", Rnew, Gnew, Bnew);
    Spark.publish("rgb", rgbString);

    Rstart = red, Gstart = grn, Bstart = blu;

    sprintf(rgbString, "Rstart %i, Gstart %i, Bstart %i", Rstart, Gstart, Bstart);
    Spark.publish("rgb", rgbString);

    return 1;
}

The problem is the colors are not fading between themselves.

Apologies if any of this is confusing. I can provide more information if necessary.

Here's the output selecting RED to begin with:

Rstart 0, Gstart 0, Bstart 0
Rnew 0, Gnew 0, Bnew 0
Rend 255, Gend 0, Bend 0
Rnew 253, Gnew 0, Bnew 0

Here's the output selecting GREEN directly afterwards:

Rstart 255, Gstart 0, Bstart 0
Rnew 253, Gnew 0, Bnew 0
Rend 0, Gend 255, Bend 0
Rnew 2, Gnew 253, Bnew 0

And then the output selecting BLUE after that:

Rstart 0, Gstart 255, Bstart 0
Rnew 2, Gnew 253, Bnew 0
Rend 0, Gend 23, Bend 255
Rnew 0, Gnew 25, Bnew 253


texts: Arduino keypad matrix example? ( teensyduino )

texts:
I'm a beginner using Arduino with a Teensy 3.2 board and programming it as a usb keyboard. I have two 4 button membrane switches. Their button contacts are on pins 1-8, and the 9th pin holds a soldered together wire of both membrane switches' "ground" line or whatever it's true name is; the line that completes the circuit.

Basically when you press the buttons they are supposed to simply type "a, b, c..." respectively. I've been told I need to use a matrix for this.

I'm looking for an example of how to code a keyboard matrix that effectively supports a one row/9 column line (or vice versa?) I've been unable to find that solution online.

All I have so far is this code which, when the button on the second pin is pressed, sends tons of "AAAAAAAAAAAAAAAA" keystrokes.

void setup() {
  // make pin 2 an input and turn on the
  // pullup resistor so it goes high unless
  // connected to ground:
  pinMode(2, INPUT_PULLUP);
  Keyboard.begin();
}

void loop() {
  //if the button is pressed
  if(digitalRead(2)==LOW){
    //Send an ASCII 'A',
    Keyboard.write(65);
  }
}

Would anyone be able to help?


texts: Arduno as bridge between two i2c masters

texts: so I am gonna just jump right into the topic. Recently, I have been trying to build a project where I need to connect an ev3 to a raspberry pi. I have decided doing it by i2c after reading (and successfully replicating) an article about connecting an ev3 to arduino by i2c https://www.dexterindustries.com/howto/connecting-ev3-arduino/.  However, after setting it up with raspberry pi, I realized a huge problem that I am facing, both of these devices acted as masters and I could not get them to connect to each other. So I decided to use an arduino between those two which transports the data that it receives to the other device, which I couldn't get working. I have no idea how to get it working anyways, it was just a hopeless try. Now I am doubting myself If I can't do it. So my question is, is such a project possible or should I just give up. If I should, what type of communication do you suggest that I use.


texts: Cannot upload to Leonardo after update to macOS Catalina

texts:
I'm not sure this is the right site, but I've spent several hours trying to figure out why I suddenly cannot upload to my Leonardo (actually, a "Pro Micro" with a 32u4) after upgrading to macOS Catalina.

Initially I thought the board was just dead, but I can program it without issues from a Windows machine. I also worked just fine with it a few days ago, before the update to Catalina. Now I'm getting this output:

Arduino: 1.8.10 (Mac OS X), Board: "Arduino Leonardo"

Sketch uses 10226 bytes (35%) of program storage space. Maximum is 28672 bytes.
Global variables use 1000 bytes (39%) of dynamic memory, leaving 1560 bytes for local variables. Maximum is 2560 bytes.

avrdude: ser_recv(): read error: Device not configured
avrdude: butterfly_recv(): programmer is not responding
avrdude: ser_drain(): read error: Device not configured
avrdude: ser_send(): write error: Device not configured
avrdude: ser_recv(): read error: Device not configured
avrdude: butterfly_recv(): programmer is not responding
avrdude: ser_send(): write error: Device not configured
avrdude: ser_recv(): read error: Device not configured
avrdude: butterfly_recv(): programmer is not responding
avrdude: ser_recv(): read error: Device not configured
avrdude: butterfly_recv(): programmer is not responding
avrdude: ser_send(): write error: Device not configured
avrdude: ser_recv(): read error: Device not configured
avrdude: butterfly_recv(): programmer is not responding
Found programmer: Id = ""; type = �
Software Version = .�; Hardware Version = �.�
avrdude: ser_send(): write error: Device not configured
avrdude: ser_recv(): read error: Device not configured
avrdude: butterfly_recv(): programmer is not responding
avrdude: ser_send(): write error: Device not configured
avrdude: ser_recv(): read error: Device not configured
avrdude: butterfly_recv(): programmer is not responding
avrdude: error: buffered memory access not supported. Maybe it isn't
a butterfly/AVR109 but a AVR910 device?
avrdude: initialization failed, rc=-1
     Double check connections and try again, or use -F to override
     this check.

avrdude: ser_send(): write error: Device not configured
avrdude: ser_recv(): read error: Device not configured
avrdude: butterfly_recv(): programmer is not responding
avrdude: error: programmer did not respond to command: leave prog mode
avrdude: ser_send(): write error: Device not configured
avrdude: ser_recv(): read error: Device not configured
avrdude: butterfly_recv(): programmer is not responding
avrdude: error: programmer did not respond to command: exit bootloader
avrdude: ser_close(): can't reset attributes for device: Device not configured
the selected serial port avrdude: ser_close(): can't reset attributes for device: Device not configured
does not exist or your board is not connected

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

My Mega2560 as well as Due work just fine. I even tried re-burning the bootloader into the Pro Micro using the Mega, which worked fine but didn't solve the issue.

I also tried getting into the bootloader mode, by tapping the reset (actually, using a wire to pull RST to GND) button twice. It changes the error to

Found programmer: Id = ">>> SPI"; type = SSoftware Version = >.>;
Hardware Version = >.
avrdude: error: buffered memory access not supported.
Maybe it isn't a butterfly/AVR109 but a AVR910 device?
avrdude: initialization failed, rc=-1
Double check connections and try again, or use -F to override this check.

The bootloader trick is not required on Windows, it just works.


texts: Yet another "Mac cannot find USB serial port" post

texts:
I have read about every post about people having issues with their Arduinos on Macs. I have a 100% authentic Arduino UNO, that I cannot by any circumstance manage to connect to my late 2009 iMac with macOS Sierra 10.12.2.

I tried just about anything from disabling Apple FTDI drivers, installing FTDIUSBSerialDriver, D2XX drivers and even the CH34X drivers (for knockoffs). NOTHING works.

Not even setting boot arguments, not disabling default extensions/drivers, not removing extensions/drivers.

I am completely stuck, and no guide has ever worked. I've tried rebooting numerous times, but still no luck. The only port available in the Port menu is the Bluetooth Incoming port.

Does anyone have any tips or hints? I am on the verge of doing a complete reinstallation of my computer just to have all drivers back to default.


texts: I want to use ESP-NOW with esp32 and esp8266. The esp32 will mostly send data to esp8266.I was not able to find any good tutorial on YouTube to achieve this. The only videos I found was for either communicating with esp32 to esp32 or esp8266 to esp8266. Is it possible to do this if yes how.


texts: ATMega328P chip on breadboard does not work properly

texts:
I wanted to get some help about my ATMega328P on my breadboard. I programmed a simple clock like this -

#include <LiquidCrystal.h>
#include <dht.h>
#include <DS3231.h>

LiquidCrystal lcd(2, 3, 4, 5, 6, 7);
dht DHT;
DS3231  rtc(SDA, SCL);

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

}

void loop() {

  int chk = DHT.read11(9);
  delay(1000);
  lcd.print("Temp: ");
  lcd.print(DHT.temperature);
  lcd.print(" ");
  lcd.print((char)223);
  lcd.print("C");
  lcd.setCursor(0,1);
  lcd.print("Humi: ");
  lcd.print(DHT.humidity);
  lcd.print(" %");
  lcd.setCursor(0,0);

  delay(5000);

  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Time:  ");
  lcd.print(rtc.getTimeStr());
  lcd.setCursor(0,1);
  lcd.print("Date: ");
  lcd.print(rtc.getDateStr());
  delay(5000);

  lcd.clear();
 }

The code works when ATMega328P is connected on the Arduino Board itself, everything is showing correctly. But when I remove the chip (when it's already programmed) and place it on the breadboard, do all the necessary wirings, it only outputs me the words Humi and Temp without even showing the proper values (-999.0 degrees it shows me). I triple-checked my connections and found nothing. And after those 5 seconds of waiting, I finally got Time, and nothing is there, only the text, not even those weird numbers. And it doesn't even reload back to Temp and Humi, it just stays on Time word forever.

I have feeling that loop doesn't work properly somehow.

EDIT: I found out what was the problem about reseting, BUT STILL the proper values doesn't show up

Can you help me out, please?


texts: Can´t load a program into my ESP01 using an ArduinoUno

texts:
This is my problem,  I´ve been trying to load a program(any program) into mi ESP01 and because I do not have the usb adapter, I decided to use my Arduino Uno to do the work.

This is my first time working with this board (ESP01), and in my search I found that it is important to have GIO0 LOW ,GIO2, RST and in HIGH to upload a program; besides I already have this board into the list that Arduino´s IDE have and I used 3.3v for VCC.  Yet, when I try to upload a program, the IDE wont let me because of this error: esptool.FatalError: Failed to connect to ESP8266: Invalid head of packet (0xF0

The program that I want to try is the HelloServer example.

Thanks for your help!!


texts:
I have to code in arduino the logic gates based on the truth table with two inputs. I searched for some examples, however all that I found is using && to compared them using only onf if else condition. What I need is to do it using all the possible cases. This is what I have, however only the last condition is working. I ask you please clarify to me what concept I am not understanding well, or what is wrong in my logic. Thank you.

  const int p2  = 2;  //Ground G
  const int p13 = 13; //Input A
  const int p15 = 15; //Input B

  void setup() {
    // put your setup code here, to run once:
    pinMode(p2,   OUTPUT);
    pinMode(p13,  INPUT_PULLUP);
    pinMode(p15,  INPUT_PULLUP);
  }
void loop() {
  // put your main code here, to run repeatedly:
  if ( digitalRead(p13) == 0 && digitalRead(p15) == 0 ){
    digitalWrite(p2, HIGH);
  }

  if( digitalRead(p13) == 0 && digitalRead(p15) == 1 ) {
    digitalWrite(p2, LOW);
  }

  if( digitalRead(p13) == 1 && digitalRead(p15) == 0 ) {
    digitalWrite(p2, LOW);
  }

  if( digitalRead(p13)== 1 && digitalRead(p15) == 1) {
    digitalWrite(p2, LOW);
  }

}


texts: Button state changes despite not being connected?

texts:
I have written some code to test buttons that I want to use

const int buttonPin1 = 1;
const int buttonPin2 = 2;
const int buttonPin3 = 3;
const int buttonPin4 = 4;
const int buttonPin5 = 5;
const int buttonPin6 = 6;

int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;
int buttonState5 = 0;
int buttonState6 = 0;

void setup() {
  Serial.begin(9600);
  pinMode(buttonPin1, INPUT_PULLUP);
  pinMode(buttonPin2, INPUT_PULLUP);
  pinMode(buttonPin3, INPUT_PULLUP);
  pinMode(buttonPin4, INPUT_PULLUP);
  pinMode(buttonPin5, INPUT_PULLUP);
  pinMode(buttonPin6, INPUT_PULLUP);
}

void loop() {
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  buttonState3 = digitalRead(buttonPin3);
  buttonState4 = digitalRead(buttonPin4);
  buttonState5 = digitalRead(buttonPin5);
  buttonState6 = digitalRead(buttonPin6);

  if (buttonState1 == HIGH) {
    Serial.println("button1 press");
  }
  if (buttonState2 == HIGH){
    Serial.println("button2 press");
  }
  else if (buttonState3 == HIGH){
    Serial.println("button3 press");
  }
  else if (buttonState4 == HIGH){
    Serial.println("button4 press");
  }
  else if (buttonState5 == HIGH){
    Serial.println("button5 press");
  }
  else if (buttonState6 == HIGH){
    Serial.println("button6 press");
  }
  else{

  }
}

I have tried with the buttonPins being A0-A5 as well, and whenever I try to run the code, it always spams out that button 5 and button 2 are being pressed, despite me not pressing them, as well as when I remove the buttons entirely, and pull out all the wires from it, it still prints it out. Even when I re-run the code. How can I fix this?


texts: Arduino and SIM900 unavailable all the time

texts:
I have the a problem with my arduino MEGA 2560 and the SIM900 module.
I want to save the outputs of the AT commands, but I never get a chance. If I print mySerial.available() I only get 0.
Sending SMS works fine on the other hand.

Initializing...
AT+CMGF=1
AT+CNMI=2,2,0,0,0

OK
Done
AT+CMGL="REC UNREAD"

OK
0
0
0
0
0
0
0
0
0
0
0

This is the sketch I use:

#include <SoftwareSerial.h>

//Create software serial object to communicate with SIM900
SoftwareSerial mySerial(11, 10); //SIM900 Tx & Rx is connected to Arduino #7 & #8
String incoming="";
String incoming2="";
String messages="Test";
String auth_num="+49xxxxxxxxx";
char incoming_char=0;

String response = "";

const byte numChars = 32;
char receivedChars[numChars];
boolean newData = false;

int period = 6000;
unsigned long time_now = 0;

void setup()
{
  //Begin serial communication with Arduino and Arduino IDE (Serial Monitor)
  Serial.begin(9600);

  //Begin serial communication with Arduino and SIM900
  mySerial.begin(9600);

  Serial.println("Initializing...");
  delay(1000);

  mySerial.println("AT+CMGF=1");
  mySerial.println("AT+CNMI=2,2,0,0,0"); // Decides how newly arrived SMS messages should be handled
  //mySerial.println("ATE0");
  updateSerial();
  Serial.println("Done");

  //sms_versenden("xxxxxxxx", "text");
}

void loop()
{
  updateSerial();
  Serial.println(mySerial.available());
  if(millis() - time_now > period){
    time_now = millis();
    if(sms_erhalten()){
      sms_autorisiert();
    }
  }
}

void updateSerial()
{
  delay(500);
  while (Serial.available())
  {
    mySerial.write(Serial.read());//Forward what Serial received to Software Serial Port
  }
  while(mySerial.available())
  {
    Serial.write(mySerial.read());//Forward what Software Serial received to Serial Port
  }
}

void sms_versenden(String rufnummer,String text)
{
  mySerial.println("AT"); //Handshaking with SIM900
  updateSerial();

  mySerial.println("AT+CMGF=1"); // Configuring TEXT mode
  updateSerial();
  if(rufnummer.startsWith("0")){
    rufnummer.remove(0,1);
    mySerial.print("AT+CMGS=\"+49");
    mySerial.print(rufnummer);
    mySerial.println("\"");
  }else if(rufnummer.startsWith("+49")){
    mySerial.print("AT+CMGS=\"");
    mySerial.print(rufnummer);
    mySerial.println("\"");
  }else{
    return;
  }
  updateSerial();
  mySerial.print(text); //text content
  updateSerial();
  mySerial.write(26);
}

boolean sms_erhalten()
{
  mySerial.print("AT+CMGL=\"REC UNREAD\"\r");
  //recvWithEndMarker();
  Serial.println(mySerial.available());
  delay(30);
  while (mySerial.available()){
    String inData = mySerial.readStringUntil('\n');
    Serial.println("Got reponse from SIM900: " + inData);
  }
  /*if(mySerial.available()>0){

    incoming = mySerial.readString();
    Serial.print(incoming);
    delay(10);
  }*/
  updateSerial();
  if(incoming.startsWith("+CMGL:"))
  {
    return true;
  }
  else{
    return false;
  }
}

void recvWithEndMarker() {
    static byte ndx = 0;
    char endMarker = '\n';
    char rc;

    while (mySerial.available() != 0 && newData == false) {
        rc = mySerial.read();
        updateSerial();
        if (rc != endMarker) {
            receivedChars[ndx] = rc;
            ndx++;
            if (ndx >= numChars) {
                ndx = numChars - 1;
            }
        }
        else {
            receivedChars[ndx] = '\0'; // terminate the string
            ndx = 0;
            newData = true;
        }
    }
}

void showNewData() {
    if (newData == true) {
        Serial.print("This just in ... ");
        Serial.println(receivedChars);
        newData = false;
    }
}
String getResponse() {
    while(mySerial.available()>0){
        response += mySerial.read();
    }
    return response;
}

Thanks in advance for every idea.
Bravodelta


texts: How to count number of bytes appearing in the Arduino serial?

texts:
I need to count the number of bytes appearing in the serial (UART bus) bus, how to count bytes in Arduino with Arduino Serial functions? is this possible?
Application -
RS485 communication with multiple boards without slave ID
slave boards will send data to the master board when,
1st 10 bytes = masters send a 10byte message to all slaves
slaves listening to the bus always until it is the turn to send the data
when byte count is 10, slave 1 sends data 5 bytes to master
when byte count is 15 (10+5), slave 2 sends data 5 bytes to master
when byte count is 20 (15+5), slave 3 sends data 5 bytes to master
max count is 25 known value


texts: What to use to Drive: 16 Segment LED, 4 Digit, Common Anode (4 sets)

texts:
I'm trying to make an F/A-18C UFC like this:

Now a while ago I bought 6 x "4 digit 16 segment" z, which happen to be common anode (DataSheet)
What i am looking for is a way to drive all 4 using the minimum of wires - I guess I prefer I²C (IIC) but will work with what ever I can use

Note: I tried something with a HT16K33 IC, but apparently that will only work with Common Cathode

Thank you, and please let me know if you need more info, or suggestions to clarify my question


texts: I am trying to make a mini project with attiny84 and I searched the web so I can make an arduino on breadboard. What I saw on the internet is that they didnt use crystal. Is it mandatory if I want to use 1 pwm pin and the SPI interface on the attiny84?


texts: switch pump on with transistor, mosfet, or relay

texts:
I would like to control a pump.
The pump rating is 12 volt 60watts.
The pump mfg says to use a 12 volt power supply of 5 - 12 amps but AT LEAST 5 amps. This pump has a pressure turn off at 116 psi and the mfg states that the pump will not make maximum pressure with less than 5 amps.

So the question becomes, to be able to switch this pump on and off based on some sensor reading what would be considered best practice:
transistor, MOSFET, or relay?


texts: Is it possible to use Serial window for debug statements while using the hardware serial port for GPS module?

texts:
I am using the hardware serial ports of Atmega 328 to connect to a GPS module . A GSM SIM900 module is connected via Software serial . Is it possible to print the debug statements in the Serial window while the GPS module is connected to the hardware serial ports? Both my module and the Serial window is set to 9600 bps baud rate .
Also I want to read the GSM responses from the Software serial and print the same in the Serial window for debugging. Is this possible?


texts: Why are MOSFETs only giving 8.1V for LEDs, not 12V?

texts:
I'm using three PWM outputs from an Arduino Mini Pro to drive the R/G/B parts of some strips of LEDs. The circuit is basically this:

I've got a single 12V power supply, rated at 200W, to light the LEDs and to power the Arduino via the RAW pin, and there are 5 metres of 60LEDs/m RGB LEDs, i.e. a total of 300 LEDs, which should be drawing ~72W according to the spec sheet (14.4W/m).

The problem is that even when the sketch says digitalWrite(9, 255); digitalWrite(10, 255); digitalWrite(11,255), the LEDs are considerably dimmer than when connected directly to the 12V supply. My cheap, digital volt meter measures ~8.1V between GND and the PWM pins across the LEDs, not the 12V that the transformer is supplying.

Am I doing something wrong? Does the MOSFET really cause such a large drop in voltage? Is there anything I can do to mitigate it? (It's important to get as much brightness as possible from the LEDs for this project).


texts: I want to use an Arduino Uno with Firmata as a standalone datalogger for recording analog signals. I will use power banks to power the Arduino. How is it possible to setup Firmata pins once with PC and use that battery powered in PC-less situation?


texts: Serial communication between PC and Arduino using C

texts:
I'm trying to send some data to my arduino mega 2560 using serial communication.

I'm using the exemple that I found here without success.

Every site I read say that I can send data to the arduino board like writing to any file on ubuntu.

But I alway get Segmentation fault

Here is my code

#include <stdio.h>
#include <string.h>

char arduinoPort[] = "/dev/ttyACM0";

int main() {

  char buffer[] = {'1'};

  FILE *usb_port;

  usb_port = fopen(arduinoPort, "rwb");

  fwrite(buffer, sizeof(char), sizeof(buffer), usb_port);

  fclose(usb_port);

  return 0;
}


texts: Can the EWRF 3022 module be directly connected to the pc totransmit data from the pc wirelessly?

texts:
In my project I want to connect my pc to an RF transmitter. The receiver will be connected to an arduino on my robot. However most of the RF modules I looked up couldn't be directly connected to my computer- in all of them I needed to use an arduino on the transmitter end too. Then I came across this:

   EWRF 3022

Can this be directly connected to my computer? If so, how is it done?


texts: How can I send AT commands to HM-10 module from my android phone?

texts: Earlier today, I was able to connect flawlessly to my HM-10 module via the Arduino serial monitor. I think I then changed some settings without thinking and now I can no longer connect to it. No errors, nothing. I have tried every baud setting but to no avail. I am able to connect to it through my Android phone but is there an app where I can send AT commands just like the Arduino serial monitor. I'm thinking I could do this to run the at+reset command to factory reset it? Are there any other ways of resetting the module?


texts:
I'm looking to make a 15 x 15 grid of load sensors and RGB LEDs for an interactive dance floor. Each node will be driven by an arduino and the entire floor will be managed by a RaspberryPi. I'm trying to figure out the best way to have the nodes communicate with the Pi. Ideally the network would have these characteristics:

Low cost per node
Raspberry Pi as the master, arduino nodes as slaves
Ability to know where each node is in the grid
Healing: If a node goes down it doesn't take out all the others.
Can easily replace broken nodes
The electronics for each node will be ~12 inches apart
The master will be 5 - 10 feet away from the matrix.

So far I have been toiling over a few ides.

I2C
This would allow each node to be addressable, however, it seems that Arduino will only allow up to 127 addresses and this matrix will have at least 225 nodes.

SPI
If daisy chained it would be easy to know where each node is in the matrix. But if one node were to break all the nodes after it would stop communicating. (right?) I could have each row daisy chained separately, so if one goes down it only affects that row.

1-Wire
1-wire also looks promising. I'd have to figure out my own way of determining node placement, which could be achieved a variety of ways.

Custom Serial
Each node has a serial connection (rx/tx) for each of it's four sides. This would allow it to communicate to each of it's neighbors directly and pass along messages that are not addressed to it. If one node were to go down, the message would be automatically routed around the broken node since there are several paths to each destination. This option is a little crazy and I'd prefer to avoid something so custom and convoluted.

USB
This would require a USB hub in each node.

XBee
Too expensive.

Other thoughts or options?


texts:
I want to read 30 differential ended analog sensors.
Using ADS1115 16 bit this is possible, but we end up having only 4 address on I2C, so i chose TCA9548A breakout board with 8 I2C multiplex channels,
Is it possible to read the ADC as shown in the block diagram
if yes, please help with code.