texts: Connect old USB webcam to USB Host Shield 2.0 Arduino Uno / Mega

texts:
Does anybody know how to interface an old USB webcam with the USB Host Shield 2.0 connected to an Arduino (Uno or Mega 2560 or other models - excluding Yun).

I've got the USB Host Shield set up properly and I can run all the examples.

My goal is to make the arduino force the webcam to take a picture (the webcam itself has a button for taking pictures) every second and save it to the SD card of the ethernet shield.

I know how to read and write data to the SD card of the ethernet shield. That's not the problem.

The problem is making the Arduino talk to the USB webcam.
Can anybody please share a basic .ino file with me so I can see what magic they used to do the trick?

I tried the Arduino PTP Camera Control library by felis over at:
https://github.com/felis/Arduino_Camera_Control

But I'm having lots of trouble getting the included examples to work properly with my old USB webcam. I always get the 'can't read data' error in the serial monitor...

Thanks for any help!


texts:
I have been working on a small project recently. I have a circuit like in the image below:

  Hardware Setup Demultiplexer IR Test

As you can see I have 8 IR LEDs, which are driven by an MC14051B Multiplexer/Demultiplexer. My goal is to select each IR led individually and send data over the selected IR LED. None of the other LEDs can send signals. Only one LED at a time can be sending IR codes.

  Hardware Setup Single IR Test

Below is the code I used to send the signal using the IR Library over one LED (no demultiplexer was used in this test).

// New function to send 'items' codes which are held in the array 'data'
void sendMulti (const uint8_t& items, const uint32_t* data) {
  for (int i = 0; i < 2; i++) {
    for (uint8_t itemIndex = 0; itemIndex < items; ++itemIndex) {
      irsend.sendNEC(data[itemIndex], 32);
      delay(1000);
    }
  }
  delay(5000); //5 second delay between each signal burst
}

void loop () {
  static const uint8_t MaxItems = 3;
  uint32_t  data[MaxItems] = {0x1067E21D,0x106722DD,0x106722DD,0x106722DD,0x106722DD,0x106722DD,0x106722DD,0x10676897,0x10676897,0x10676897,0x10676897,0x10676897,0x10676897,0x10678877,0x10676897,0x1067A857,0x1067A857,0x10678877,0x1067A857};
  sendMulti(MaxItems, data);
}

The Single IR Test was a success. However now I want to use the demultiplexer. Any advice or pointers will make me very happy.


texts:
I trying to connect my arduino uno to internet. I'm using the following schematic:

and using the following code to just to check if wifi is connected or not.

#include <ESP8266WiFi.h>
// Set these to run example.
#define WIFI_SSID "Connect4G"
#define WIFI_PASSWORD "68011332724"

void setup() {
 Serial.begin(9600);
 // connect to wifi.
 WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
 Serial.print("connecting");
 while (WiFi.status() != WL_CONNECTED) {
   Serial.print(".");
   delay(500);
 }
 Serial.println();
 Serial.print("connected: ");
 Serial.println(WiFi.localIP());
}

void loop() {

}

However I end up with the following error:

esptool.FatalError: Failed to connect to ESP8266: Invalid head of packet (0xF0)

when I try to connect my esp to internet through AT commands, it works just find.


texts: 4 Digit, 7 Segment Display Wiring (14 pin)

texts:
I purchased this 4 digit, 7 segment display from Adafruit:

Product: http://www.adafruit.com/products/865

Data Sheet: http://www.adafruit.com/datasheets/865datasheet.pdf

Everything I have searched for on the net either has 12 pins or 16 pins and most of those are only using 4 resistors.  This one has 14 pins.  I'm trying to wire it up to an Arduino but I'm not sure which pins should have resistors and which shouldn't.  If I wire it up like in the product picture with 1k resistors, I get 8.8.:8.8. and as I remove resistors from 5V, I can see the different sections that are lit/not lit.

Is that the correct way of doing it?  Can I now just wire those to the Arduino?


texts:
I am considering purchasing these ATmega328 s from
3 pack ATmega328P.

The company says they come with the Arduino UNO bootloader.
I do NOT have any 16 MHz crystals, and I would like to make the chips run on the 8 MHz internal crystal.

I have an Arduino Duemilanove.

Is it possible to burn the minimal setup bootloader from here onto the bootloaded chips without using a crystal?


texts: How to Connect TFT LCD display with NodeMCU?

texts:
I am doing this project wherein I want to display some image on the LCD screen. I am having a problem with the connecting nodemcu with my TFT LCD screen. I cannot find any references. Does a TFT screen go well with a NodeMCU? if yes, please help

I tried taking refrence from this website but i ended up damaging my nodeMCU

http://nobrok.com/connecting-tft-lcd-touch-screen-with-nodemcu-esp8266/

Also attaching images of TFT display and my NodeMCU.

It would be great if you can help. Thanks :)


texts: Arduino FFT library - Open Music Labs installation help

texts:
I downloaded the zip file of the FFT library from the below link

http://wiki.openmusiclabs.com/wiki/ArduinoFFT

and it now as I implement the example codes, it gives out a message which says
"Error compiling for Mega or Mega2560".
I have an Arduino Mega2560 and I want to know how to use this library for my board for frequency analysis of sound. Any help on this will be much appreciated.


texts: Assigning float to 10 decimal place for longitude,latitude

texts:
I'm quite a novice in arduino programming. I am doing a small home project and I am using sim808 to obtain GPS data.

My question is quite simple but i can't find any solution online.

Serial.print("latitude :");
Serial.println(sim808.GPSdata.lat, 10);
Serial.print("longitude :");
Serial.println(sim808.GPSdata.lon, 10;

This code display Longitude and Latitude data on serial monitor to 10 decimal place perfectly.

But when after setting the Longitude and Latitude to float.When I use this code, I don't get a valid gps data.

Longitude = (sim808.GPSdata.lon, 10 );
Latitude = (sim808.GPSdata.lat, 10 );

Please help, Thanks.

(edited)
I understand my error in coding for the above.

In fact, I am using a DF robot shield sim 808 for vehicle tracking. I am uploading my GPS data, longitude, latitude and speed to Ubidots. The only difficulty is in saving accurate data.

I am using this codes

Longitude = sim808.GPSdata.lon;
Latitude = sim808.GPSdata.lat;
Speedperkm = sim808.GPSdata.speed_kph;

client.add("Longitude", Longitude);
client.add("Latitude", Latitude);
client.add("Speed per Km", Speedperkm);

The code is working fine but only GPS data of 2 decimal place is being uploaded. If data of up to 6 decimal place is uploaded then the system will more accurate.

That my problem that I am trying to solve.


texts:
I am trying to get a sampling rate of over 10k Samples per second as well as send each sample over a serial line. Taking a sample and putting it on the serial line each time took too long. I am using Processing 3.3.6 for datalogging into a csv file. I am unable to achieve more than 6k samples per second even at lower prescaler value and high baudrate. What am I doing wrong? Here is my arduino code.

int val[2000];
void setup()
{
  Serial.begin(250000);

  //ADCSRA = 0;             // clear ADCSRA register
  //ADCSRB = 0;             // clear ADCSRB register
  ADCSRA &= ~(bit (ADPS0) | bit (ADPS1) | bit (ADPS2)); // clear prescaler bits
  //ADCSRA |= bit (ADPS0);                               //   2
  ADCSRA |= bit (ADPS1);                               //   4
  //ADCSRA |= bit (ADPS0) | bit (ADPS1);                 //   8
  //ADCSRA |= bit (ADPS2);                               //  16
  //ADCSRA |= bit (ADPS0) | bit (ADPS2);                 //  32
  //ADCSRA |= bit (ADPS1) | bit (ADPS2);                 //  64
  //ADCSRA |= bit (ADPS0) | bit (ADPS1) | bit (ADPS2);   // 128
  //pinMode(A0, INPUT);

}

void loop()
{
  for(int i=0; i<2000; i++) {
    val[i] = analogRead(A0);
  }
  for(int i=0;i<2000;i++){
    Serial.print(val[i]);
    Serial.print('x');
  }

}

P.S I am new to arduino.

--edit1>>
I am using Arduino Mega 2560.


texts:
I use Arduino UNO and two SPST Relay (Wemos Mini D1 Relay) to make the reverse polarity circuit. I use this circuit to open and close the Solenoid Water Valve (SWV), which work with 9 to 12 volt. The connections are as follows:

NO (Relay1) --> NC (Relay2) --> +12 Volt
NC (Relay1) --> NO (Relay2) --> 0
D1 (Relay1) --> D1 (Relay2) --> Digital pin 3 of Arduino
COM (Relay1) --> SWV1
COM (Relay2) --> SWV2
GND Relay1) --> GND (Relay2) --> GND of Arduino
5V (Relay1) --> 5V (Relay2) --> 5 Volt of Arduino

the circuit work perfectly with Arduino boar. But the problem is that when I use ATMEGA328p-PU on breadboard as explained in LINK, Relays are not working properly. Actually, relays connecting and disconnecting continuously when ATMEGA328p sends 1 to D1 pins of Relays.

The point is when I de-attach the SWV, relays work properly. but if the SWV is connected it still is not working.

I've checked the connection many times and they are correct.

I used the following code in arduino:

int Relay = 3;
void setup() {
  // put your setup code here, to run once:
  pinMode(Relay, OUTPUT);
  digitalWrite(Relay, LOW);

}

void loop() {
  // put your main code here, to run repeatedly:
  delay(2000);
  digitalWrite(Relay, HIGH);
  delay(2000);
  digitalWrite(Relay, LOW);

}

Any help is highly appreciated.

Thanks in advance.


texts:
I am having problems with values i get from Pololu MinIMU-9 boards's magnetometer. I am using Arduino-micro and the arduino library from Pololu. The sensor on the board is 3 axis accelero- and magnetometer LSM303.
The problem is - the highest value always seems to be in vertical axis, not horisontal, as i would expect.

For example, here is the data i got when i put sensor flat on the table and made 360 clockwise turn in horizontal plane:
(values are X Y Z)

-6 102 -516
-11 103 -515
-11 103 -515
-21 102 -514
-31 109 -515
-40 114 -512
-57 116 -509
-57 116 -509
-77 111 -507
-93 109 -506
-104 106 -507
-104 106 -507
-114 99 -508
-126 88 -504
-131 74 -507
-142 52 -507
-142 52 -507
-151 31 -506
-150 4 -509
-147 -27 -513
-147 -27 -513
-133 -60 -513
-119 -80 -519
-112 -87 -517
-102 -97 -521
-102 -97 -521
-89 -101 -522
-77 -101 -524
-50 -104 -527
-50 -104 -527
-43 -105 -529
-14 -98 -532
2 -92 -535
23 -92 -535
23 -92 -535
36 -81 -534
66 -54 -534
76 -32 -531
76 -32 -531
76 -21 -532
78 -7 -531
85 10 -528
91 39 -524
91 39 -524
94 50 -524
91 63 -524
76 75 -525
76 75 -525
63 82 -526
47 93 -525
44 98 -522
44 98 -522
38 104 -521
26 110 -521
26 112 -518
21 116 -519
21 116 -519
18 116 -518
12 120 -517
11 120 -515
11 120 -515
8 120 -517
5 122 -515
-5 123 -514

Turning the sensor "upside down" and then rotating it in horisontal plane again gives similar results, only Z axis has positive 500+ value.

Shouldn't the magnetometer always point in the direction of the magnetic field - in X or Y direction?
I have tried this in different rooms and buildings and got the same results.
Rotating the sensor on other axes yields the same results - vertical axis has the largest (and constant) value.

For reference, here is the code i used to get the values.

#include <Wire.h>
#include <LSM303.h>
LSM303 compass;

void setup()
{
  Serial.begin(115200);
  Wire.begin();
  compass.init();
  compass.enableDefault();
}

void loop(){
  compass.readMag();
  Serial.print(compass.m.x);
  Serial.print(" ");
  Serial.print(compass.m.y);
  Serial.print(" ");
  Serial.print(compass.m.z);
  Serial.print("\n");
  delay(100);
}


texts: To connect a simple toy circuit and trigger with an arduino?

texts:
I have a small circuit from a toy sword that has an LED and a small speaker. It was powered by a couple of small coin cells.

I am trying to figure out how to connect it to my Arduino so I can trigger it.
If I attached the circuit directly to the GND and +3.3V and press the switch in it I get the sound of a sword and flashing LED as desired.

Now I want to somehow get the Arduino to trigger the circuit but am very new to Arduino and quite unsure of how to approach this.

Can anyone advise how best to work with an existing low power circuit that can use the Arduino's power rails but needs the switch integrated?

Sorry for the noob question.


texts: MKR1000 disconnecting when hooked up to RGB 16x32 LED Matrix

texts: This tutorial is from 2012, before the MKR1000 existed. The tutorial says the 16x32 LED Matrix panel is compatible with the Arduino Zero, which the MKR1000 is supposedly related to, so I'm thinking I should be able to upload the same program. However, the board keeps disconnecting every time I try to upload a simple sketch, so I am worried that perhaps they are not compatible. I am using the same wiring as the Arduino Uno (using pins 2-10, A0, A1, A2, GND on the MKR1000) that you can see in this tutorial


texts: do two arduinos that are linked to a common 9v rail and ground still need a common negative connection for a serial tx rx connection?

texts: so that there a 2 wires rather than 3 to connect between the two for purposes of serial communication.  And the same question for 3 arduino megas on a common rail and using serial connections?


texts:
I have an arduino pro mini and I have attached a 16x2 character LCD and an LM35 analog temperature sensor. When I upload a sketch using only the sensor and send the readings to serial monitor, the readings are OK. When I upload a sketch that displays the readings to the LCD the readings are about 130°C in room temperature. Where is the problem and how can I solve it. Thanks in advance

Code with lcd:

#include <LiquidCrystal.h>
byte smiley[8] = {
  B00000,
  B01110,
  B01010,
  B01110,
  B00000,
  B00000,
  B00000,
};
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

void setup() {
  // set up the LCD's number of columns and rows:
  lcd.createChar(0, smiley);
  lcd.begin(16, 2);
  analogReference(INTERNAL);
  // Print a message to the LCD.
  lcd.print(analogRead(0)/1024.0 * 500);
  lcd.write(byte(0));
  lcd.print("C");
  lcd.setCursor(0, 2);
  lcd.print("21");
  lcd.write(byte(0));
  lcd.print("C");

}

void loop() {
  // Turn off the cursor:
  lcd.print((analogRead(0)/1024.0)*500);
  lcd.write(byte(0));
  lcd.print("C");
  lcd.setCursor(0, 2);
  delay(5000);
  lcd.clear();
}

Only sensor code:

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

void loop() {
  // put your main code here, to run repeatedly:
  Serial.println(analogRead(0)/1024.0*500);
  delay(500);
}


texts: Why is this spitting giberish instead of serial numbers?

texts:
#include <TrueRandom.h>

void setup() {
  char* ss= (char*)TrueRandom.random(111111111,999999999);
  char* finalss;
  Serial.begin(9600);
  finalss[0] = ss[0];
  finalss[1] = ss[1];
  finalss[2] = ss[2];
  finalss[3] = '-';
  finalss[4] = ss[3];
  finalss[5] = ss[4];
  finalss[6] = '-';
  finalss[7] = ss[5];
  finalss[8] = ss[6];
  finalss[9] = ss[7];
  finalss[10] = ss[8];
  Serial.println (finalss);
}

void loop() {
  ; // Do nothing
}

This is supposed to output a randomly generated number in this format nnn-nn-nnnn.
Updated Code (Doesn't seem to output anything):

#include <TrueRandom.h>

void setup() {
  String ss;
  ss = (String)TrueRandom.random(111111111,999999999);
  String finalss;
  Serial.begin(9600);
  finalss[0] = ss[0];
  finalss[1] = ss[1];
  finalss[2] = ss[2];
  finalss[3] = '-';
  finalss[4] = ss[3];
  finalss[5] = ss[4];
  finalss[6] = '-';
  finalss[7] = ss[5];
  finalss[8] = ss[6];
  finalss[9] = ss[7];
  finalss[10] = ss[8];
  Serial.println (finalss);
}

void loop() {
  ; // Do nothing
}


texts: Receive socket when in loop arduino (Interupt a while loop with a socket)

texts:
I'm currently working on an arduino project. Were the arduino is communicating with a NodeJS server via web sockets.

The socket connection is working fine and has no problems. But the problem I currently have is that I want to be able interupt an infinite while loop with a socket emit from the NodeJS server.

I found a page that had a solution for this problem but only with a button attached to the arduino.

Link to page (Interrupt with button)

This is the loop I want to be able to interrupt with a socket:

bool loopRunning = true;

void rainbow(int wait) {
while(loopRunning == true) {

      for(long firstPixelHue = 0; firstPixelHue < 3*65536; firstPixelHue += 256) {
        for(int i=0; i<strip.numPixels(); i++) {
          int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
          strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
        }
        strip.show();
        delay(wait);
      }
    }
}

I want to set loopRunning to false when I recieve a socket emit.

Anyone have any ides how I can implement this?

Page to the socket functionality that I use


texts: Accessing start up bits of SRAM from MicroBit for PUF

texts:
https://infocenter.nordicsemi.com/pdf/nRF51822_PS_v3.4.pdf
The aim is to extract (output in serial monitor) the start up bits from  the SRAM of this microbit which is located at memory address 0x20000000, given by the datasheet above, all done in the arduino IDE.
After some searches I emerged on this code
void setup()
{
  uint8_t const * p;
  uint8_t i;

  Serial.begin( 115200 );

  p = 0;
  i = 0;

  do
  {
    Serial.print( *p, HEX );
    Serial.print( ' ' );

    ++i;
    ++p;

    if ( (i & 0xF) == 0 )
    {
      Serial.println();
    }
  }
  while ( i != 0 );
}

void loop()
{
}

From this link https://forum.arduino.cc/t/accessing-sram-on-arduino-uno/267777/6
However this pertains to an arduino uno and I'm not entirely sure how I would transfer it to my microbit.


texts: Differential voltage measurement using Arduino

texts:
I have a electrolysis cell in which the anode is hanging using a Structure in a electrolyte. The cathode is at the bottom of the cell with electrolyte above it and anode being dipped into this electrolyte (not completely, a portion of the anode is dipped). The cell operates at 7  volts DC and 90000 amperes of current flowing through it. This is a typical electrolysis process of producing aluminium from alumina powder in a aluminium smelter. The cell is called a pot.
Now the question is I need to measure a potential drop on the anode rod. We usually take a meter to measure the potential drop on the anode rod and typically the reading are in millivolts. As the readings are in millivolts, it just indicates the drop in rod voltage due to resistance of rod. Now can I measure this millivolts drop using Arduino provided the voltage at one point of anode is 5 volts with respect to ground and the voltage at the other point is 4.95 volts with respect to ground, however the difference between these voltages is 0.5 volts and this is voltage I need to measure using Arduino and some arrangements as add on to it. How can I do this?
Can anyone help.
If you want more details, please comment. I will also provide more details.
So far I have done is tried measuring 1.5 volts on a pencil cell using Arduino by connecting A0 analog pin on Arduino to positive directly to the positive of 1.5 volts battery and ground of Arduino to the negative of Arduino.
Can I do the same for this millivolts measurements? I understand that the ground of Arduino and the 2nd point of anode measurement will not be at same potential, so shouldn't be connected together. I am scared to burn my board, so didn't try practically and wanted to get some opinion.


texts:
I'm using now() and millis() to trigger events after a certain time has passed.
I am aware, and it's also easily found on the web, that millis() rolls over after a certain time has passed and for code that has to run indefinitely you have to handle this.

However I am not aware of if now() can do the same at some point. I mean it does count the seconds from the 1.1.1970 so just regarding this fact, it should not roll over. However, just like millis() this has to be counted somewhere no? How does it work?


texts: its possible to read serial ouput from ICSP or Tx Rx pin instead from USB port? If it's possible how? thanks for reply


texts: WiFiNINA communication via SPI on the Nano 33 IoT

texts:
I am trying to understand how the WiFiNINA Lib is working on the Nano 33 IoT device. On the mentioned board the SAMD21G is connected to the ublox wifi module via SPI and I am studying how they communicate. I am new to AT commands. So my question is, does the WiFiNINA module also use AT commands via the SPI connection? I have scanned the library to see if I can find any but without any luck. The only thing I found was some defined commands located in src/utility/wifi_spi.h but I cannot make them match any AT commands. It is like I am missing a link.
If you can guide me to some documentation on this it would be great, too.


texts: Maximizing SPI-speed between Arduino DUE and RA8875 display driver

texts:
For a project I would like to be able to control my RA8875 display driver as quick as possible using an Arduino due.
I started from the Adafruit library and replaces all  "digitalWrites" with direct port manipulation.
Apart from that I wanted to also use that maximum possible SPIspeed.
In the adafruit datasheet I didn't find any specification of the maximum SPIspeed of the controller. In an older datasheet I only found the max speed in relation to the system clock. But I have no idea what that is. .
After googling, the max spi speed of the RA8875 seems to be 12Mhz (source).
So I decided to just try different SPIspeeds. Though I do found the library's Adafruit_RA8875.cpp file a bit confusing since it defines uint32_t spi_speed multiple times based on the architecture.

Once starting at line 48
Once starting at line 134
Once starting at line 164

And the chosen speeds for each architecture are not consistent between those 3 assignments.
I decided to replace line 66:

SPI.beginTransaction(SPISettings(spi_speed, MSBFIRST, SPI_MODE0));

with:

SPI.beginTransaction(SPISettings(12000000, MSBFIRST, SPI_MODE0));

and tried other speeds. But it always resulted in a black screen on my display.


texts: Using use the STM32F103C8T6 board with the Arduino

texts:
last two days I am trying to programm my blue pill with arduino ide, helplessly...
Actually, I managed to install simple blink program, but after that, all other attempts ended up with:

Failed to init device.
stm32flash Arduino_STM32_0.9

http://github.com/rogerclarkmelbourne/arduino_stm32

Using Parser : Raw BINARY
Interface serial_posix: 115200 8E1

An error occurred while uploading the sketch

I crawled internet but no help so far... I followed simply tutorial:
https://www.youtube.com/watch?v=K-jYSysmw9w just as this https://github.com/rogerclarkmelbourne/Arduino_STM32/wiki/Installation, and as I said, first time was problem but finally successfully upload it. However, after that when I wanted some real working program to install failed.
All mappings ftdi -> stm32 are correct, jumper booto is set to 1 mode, for programming, I have required files within /etc/udev/rules.d, stm32 library folder in sketch folder, and yet the error above is happening for a last 20 hours... (I am using ubuntu 16.04)
Please, if anyone point me what is wrong (why first time worked and second wont), or to give me precise steps to perform in order to work, I appreciate...
Thanx

P.S
Blinking program works just fine when I move jumper to 0, and supply power via usb...


texts: Using ps2 mouse (PAW3402 / PAW3412) as a distance sensor for arduino

texts:
I am working on a project where I need to calculate distance traveled by a robot. The mouse is connected to the arduino uno processor and I received some sample code from the arduino website to get started.

The problem is that the mouse gives difference distances depending on how fast or slow the it moves. (The same way you can move your pc mouse from side to side, fast and slow, and watch it cover different distances across the screen). Is there anyway to get get around this mouse setting? If not,  is there a more accurate sensor that can be used to accomplish the task? I'm having a hard time finding one.

Here is a link to the datasheet: http://www.alldatasheet.com/datasheet-pdf/pdf/333273/PIXART/PAW3402.html


texts: where is the digitalPinToInterrupt macro defined

texts: I am new to arduino, and it's confusing to me how you can just write code in the IDE and use functions or macros such as #define ISR() in the avr-libc library without having to include the header file in the arduino sketch. I was trying to find where digitalPinToInterrupt() is defined, but had no luck. Any idea?


texts:
I want to get CO2 value by using MH-Z19. I tried this code with Arduino uno R3 but I always get this result (CRC 0/0). I didn't understand where is the problem.
I linked A0 with TX of sensor and A1 with RX, I powered the card with 3.3V/Vin to visualize the result on PC via USB port.

 #include <SoftwareSerial.h>;

 SoftwareSerial mySerial(A0, A1); // A0 - к TX сенсора, A1 - к RX

 byte cmd[9] = {0xFF,0x01,0x86,0x00,0x00,0x00,0x00,0x00,0x79};
  unsigned char response[9];

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

 void loop()
{
mySerial.write(cmd, 9);
 memset(response, 0, 9);
 mySerial.readBytes(response, 9);

  int i;
byte crc = 0;
 for (i = 1; i < 8; i++) crc+=response[i];
 crc = 255 - crc;
 crc++;

  if ( !(response[0] == 0xFF && response[1] == 0x86 && response[8] == crc) )
 {
Serial.println("CRC error: " + String(crc) + " / "+ String(response[8]));
  } else {
unsigned int responseHigh = (unsigned int) response[2];
unsigned int responseLow = (unsigned int) response[3];
unsigned int ppm = (256*responseHigh) + responseLow;
Serial.println(ppm);
}


texts: Make Piano keys on Webpage create sound on Arduino (w/out Shield)

texts: So I am trying to make a digital keyboard on webpage, that when one of the keys are clicked it creates sounds on the Arduino board. I want to do this without an ethernet shield. I am a beginner so I am not sure how to proceed. I'm not even sure what type of code it needs to work. I just know that I need Processing sketch to act as a go between for the webpage and the Arduino.


texts: Fast switching of high load using an IGBT

texts:
I want to control a high load with fast switching times (motorbike ignition coil) using an arduino. I found an IGBT that claims to be purpose built for that use case (ISL9V3040P3). This IGBT has an Vge (th) max of 2.2 V, so I thought I could simply switch the Gate with an Arduino Pin.
But I did some more digging and most people seem to use an additional IGBT driver (like IR2127PBF). What´s the reason for that? Is it because the arduino can´t provide sufficent current?


texts: Why are there 3 crystals on the Mega2560 schematic?

texts:
I am a software engineer who is new(er) to electronics, I only started a couple of months ago. I've built a bunch of custom circuits, then some arduino nodes that are around my apartment that communicate with a C# server. So I've at least got the breadboarding part down.

So now I am working on a controller board that connects to my home automation system and determines the color on the LED light strips I installed into my bookshelf. So I want to transfer from working with pre-built Arduinos to building my own full node, there are some things I think I'm missing.

I've noticed that there are duplicate parts on the schematic for the Arduino Mega2560 schematic (such as there being 2 voltage regulators - one is replacement if the other is not available). I couldn't find any such description however for why there are 3 crystals located on the board. I see 3 different circuits for crystals (all of which are 16MHz).

Specifically, I am referencing the following


texts: My Code turns on my LED even when my switch is not pressed

texts:
I am trying to create a circuit that will turn my motor when I clap. When the first limit switch is low, and there is only one clap, a solenoid pin is supposed to be engaged (currently an LED), but when I clap once without pressing the limit switch, my LED turns on.

Also, I can't seem to get my code to work properly with the limit switches, to control my motor.

I am not sure what is wrong, can someone help?

I have an Arduino Uno with the following code:

#define sound_Sensor 2
#define EN1 9
#define IN1 8
#define IN2 7
#define solenoid_pin 6
#define LimSwitch1 4
#define LimSwitch2 3

int lastSoundValue;
int soundValue;
long lastNoiseTime = 0;
long currentNoiseTime = 0;
int solenoidPinStatus = LOW;
int status_motor = LOW;
int clap_interval = 200;
int claps = 0;
int pos1 = 1;
int pos2 = 1;

void setup() {
  pinMode(sound_Sensor, INPUT);
  pinMode(EN1, OUTPUT);
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(solenoid_pin, OUTPUT);
  pinMode(LimSwitch1, INPUT);
  pinMode(LimSwitch2, INPUT);
}

void loop() {

  soundValue = digitalRead(sound_Sensor);
  currentNoiseTime = millis();
  if (soundValue == 1 && lastSoundValue == 0 && (currentNoiseTime > lastNoiseTime + 200))
  {
      if (claps == 0) // allow first to register without much condition
      {
          claps = 1;
          lastNoiseTime = currentNoiseTime;
      }
      else
      {
          if (currentNoiseTime > lastNoiseTime + clap_interval)
          {
              claps++;
              lastNoiseTime = currentNoiseTime;
          }
      }
      Serial.print(claps);
  }
  else
  {
      if (currentNoiseTime > (lastNoiseTime + 3 * clap_interval)) // no claps for a longer duration time to print and/or reset clap
      {
          if (claps > 0)
          {
              while(status_motor == LOW){
                  if (digitalRead(LimSwitch1) == LOW && claps == 1)
                  {
                    solenoidPinStatus = HIGH;
                    digitalWrite(solenoid_pin, HIGH);
                  }

                 if (digitalRead(LimSwitch1) == LOW)
                 {
                    pos1 = 2;
                    status_motor = HIGH;
                    digitalWrite(IN1, HIGH); //Turns on Motor
                    digitalWrite(IN2, LOW);
                    analogWrite(EN1, 200); //Set Speed of Motor
                  }
                 else if (digitalRead(LimSwitch2) == LOW)
                 {
                    pos2 = 2;
                    status_motor = HIGH;
                    digitalWrite(IN1, HIGH); //Turns on Motor99++
                    digitalWrite(IN2, LOW);
                    analogWrite(EN1, 200); //Set Speed of Motor
                 }
              }

              while(status_motor == HIGH){
                if (pos1 == 2 && digitalRead(LimSwitch2) == LOW)
                {
                    status_motor = LOW;
                    digitalWrite(IN1, LOW); //Turns on Motor
                    digitalWrite(IN2, LOW);
                    pos1 = 1;
                }

                else if (pos2 == 2 && digitalRead(LimSwitch1) == LOW)
                {
                    status_motor = LOW;
                    digitalWrite(IN1, LOW); //Turns on Motor
                    digitalWrite(IN2, LOW);
                    pos2 = 1;
                }
              }
          }
             claps = 0; ///reset
      }
  }

// if (solenoidPinStatus == HIGH && status_motor == LOW && digitalRead(LimSwitch1) == LOW)
// {
//   solenoidPinStatus = LOW;
//   digitalWrite(solenoid_pin, LOW);
// }
  lastSoundValue = soundValue;
}

Sorry my wire diagram may not be the easiest to look at...


texts: Arduino I2C Wire.onReceive hangs after a few loops

texts:
I have an Arduino Leonardo (master) and a Polulu A-star 328 PB(slave). I intend to use the slave to actuate some servos. I've modified the code from https://www.arduino.cc/en/Tutorial/MasterWriter to also blink the builtin led of the slave and it hangs after a few loops. Without the blink, it works fine. With blink, it hangs after a few loops.

Master:

#include <Wire.h>

void setup() {
  Wire.begin(); // join i2c bus (address optional for master)
}

byte x = 0;

void loop() {
  Wire.beginTransmission(8); // transmit to device #8
  Wire.write("x is ");        // sends five bytes
  Wire.write(x);              // sends one byte
  Wire.endTransmission();    // stop transmitting
  x++;
  delay(2000);
}

Slave:

#include <Wire.h>

void setup() {
pinMode(LED_BUILTIN, OUTPUT);
Wire.begin(8);                // join i2c bus with address #8
Wire.onReceive(receiveEvent); // register event
Serial.begin(9600);           // start serial for output
}

void loop() {
delay(100);
}

void receiveEvent(int howMany) {
while (1 < Wire.available()) {
  char c = Wire.read();
  Serial.print(c);
}
int x = Wire.read();
Serial.println(x);
digitalWrite(LED_BUILTIN, HIGH);
delay(500);
digitalWrite(LED_BUILTIN, LOW);
delay(500);
}

Serial monitor:

x is 16
x is 17
x is 18
x

Any idea what's causing it and what can I do to further debug it or fix it?
Thank you!


texts: Arduino time keeping using millis() is not accurate or correct?

texts:
I have been using the Arduino to record some data. In my Arduino sketch I also used the millis() function so I can keep track of the time at which each value I am measuring is taken. However, I noticed that the timing isn't correct. For example 30 seconds in real life only comes out as 10 seconds (made up example).

Am I correct in saying that the Arduino delay function affects the time keeping using millis()? In other words suppose I have a delay of 50ms, does that mean the millis() function stops for that duration as well and then continues and so on for the duration of the connection? I noticed this when I tried plotting some data and finding that the frequency of the peaks in my data was too frequent given the time which had passed by. So I want to know if that is the reasoning for this mismatch of timing and if so, how do I fix this so that I can keep the time each sample occurs?

To give some context here is my sketch:

#include <eHealth.h>

unsigned long time;
// The setup routine runs once when you press reset:
void setup() {
  Serial.begin(9600);
}

// The loop routine runs over and over again forever:
void loop() {

  float ECG = eHealth.getECG();
  time = millis();
  Serial.print(time);
  Serial.print(" ");
  Serial.print(ECG, 5);
  Serial.println("");

  delay(50);
}


texts:
Bear with me as I'm fairly adept at C# but I am having a problem understanding how to get an array iterated.

I am writing a program to test relay boards, it will eventually have an input mechanism to select the number of relays on the board. For now, i just need to get an array iterated to move on with the code.

The biggest relay board I've seen has 16 relays, so....

#define Relay1  2  // Arduino Digital I/O pin numbers for UNO R3
#define Relay2  3
#define Relay3  4
#define Relay4  5
#define Relay5  7
#define Relay6  8
#define Relay7  9
#define Relay8  10
#define Relay9  11
#define Relay10  12
#define Relay11  13
#define Relay12  A0
#define Relay13  A1
#define Relay14  A2
#define Relay15  A3
#define Relay16  A4

int relays[]{ Relay1,Relay2,Relay3,Relay4,
    Relay5,Relay6,Relay7,Relay8 };
int maxRelayCount = 8;
char rx_byte = 0;

void setup()   //Initializes all variables and settings
{
  Serial.begin(9600);
 // create an input for the amount of relays on the board
//hardcoded for now

//Set pins to OFF & declare pins as OUTPUTS
 for(int i = 0; i < maxRelayCount; i++)
 {
   digitalWrite(relays[i], RELAY_OFF);
   pinMode(relays[i], OUTPUT);
   //How to convert i to a string in c++?
   //Serial.print("Relay " +[i] + " set HIGH and as OUTPUTS");
 }

 //Check that all relays are inactive at Reset
 delay(4000);

}

So there are two issues. If I remove the loop and just hard code 8 times to set HIGH and OUTPUT it works fine, but the loop does not and won't upload to the Arduino, thus the reason I believe it is wrong. Secondary question is how to convert the counter i to a string to concatenate the message


texts:
I made a couple of arduino mini pro and esp8266 pcbs with an rs485 transceiver just to find out that I forgot to think about in-system-programming:

Assuming that I don't need to disable the transceiver i tied *RE/DE to gnd/vcc. It turned out that id do need disable the transceiver (at least the receiving part) in order to be able to program the mcu because otherwise the transceiver disrupts the serial data.

But I don't want to lose one pin for this (which in case of an esp8266 are rare) and I don't want to use jumpers because I really like the workflow without.

Is this even possible?

EDIT: The transceiver is an SP3485.
Currently it is connected like:

Mini Pro     SP3485
A-rx ------  RO
GND  --1k-- *RE   A  ---- somwhere else
Vcc  --1k--  DE   B  ----        "
A-tx ------  DI

Which blocks serial programming because of a) the "echo" and b) holding A-rx line high.

If I connect *RE --1k-- Vcc and DE --1k-- GND I can ISP the Arduino, but now I obviously can't use the transceiver anymore.


texts: Build error on a phantom file that is not in my sketch, but somehow created in AppData/Local/Temp\build

texts:
on attempt to build  I get the following error

C:\Users\gmyer\AppData\Local\Temp\build5d24776aeb7b2efec3566cec737c36d8.tmp\sketch\trash\bootloader.c:1:1: error: unknown type name 'This'

 This modules tests receiving vacuum data from the

 ^

The problem is that I have no file of that name, and no text that exactly matches that any where in my sketch.  and my sketch is located in C:\Software

I have tried rebooting, deleting the Temp directory, reverting to known working code.  but it keeps regenerating.


texts: How to reset arduino Mega 2560 code automatically?

texts: I am working on the temperature project using arduino to collect temperature. But sometimes arduino hang there so I have to unplug cord and plug it back in to restart the arduino. I do not when it is going to hang up again. So I decide to do some research on the internet but no luck for that. Here is the article I read about resetting arduino code with watchdog timer library.(unfortunately, it only work for arduino uno) If someone has any idea how to reset arduino mega 2560 code. Please help !!


texts:
I'm trying to control NodeMCU via Android application and I can control NodeMCU easily but when I added the URL to hit the PHP code to enter data in MYSQL, neither NodeMCU is controllable nor NodeMCU is hitting the PHP code. I'm confused with content type: text/html - I'm not sure where to set this piece. Is there any mistake I'm doing or anything I'm missing?

Following is the ESP8266 code on Arduino IDE:

#include <ESP8266WiFi.h>

const char* ssid = "ssid";
const char* password = "password";
const char* host = "aoatech.ml";

WiFiServer server(3000);
int light1 = 13;
int light2 = 15;
int fan = 12;
int socket = 14;
String what;
int which;
String mac;

void setup() {
  Serial.begin(115200);
  delay(10);
  pinMode(light1, OUTPUT);
  pinMode(light2, OUTPUT);
  pinMode(fan, OUTPUT);
  pinMode(socket, OUTPUT);
  digitalWrite(light1, 0);
  digitalWrite(light2, 0);
  digitalWrite(fan, 0);
  digitalWrite(socket, 0);
  Serial.print("Connecting to: ");
  Serial.print(ssid);
  WiFi.begin(ssid, password);
  Serial.println("Connecting");
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  server.begin();
  Serial.println("Server started");
  Serial.println(WiFi.localIP());
}

void loop() {
  WiFiClient client = server.available();
  if (!client) {
    return;
  }
  Serial.print("Connecting to ");
  Serial.println(host);
  //  const int httpPort = 3000;
  //  if (!client.connect(host, httpPort)) {
  //    Serial.println("Connection failed!");
  //    return;
  //  }
  mac = WiFi.macAddress();
  Serial.println("new client");
  while(!client.available()){
    delay(1);
  }
  String req = client.readStringUntil('\r');
  Serial.println(req);
  client.flush();
  int val;
  if (req.indexOf("/light1/1") != -1){
    val = 1;
    what = "Light_1";
    which = light1;
  }
  else if (req.indexOf("/light1/0") != -1){
    val = 0;
    what = "Light_1";
    which = light1;
  }
  else if (req.indexOf("/light2/1") != -1){
    val = 1;
    what = "Light_2";
    which = light2;
  }
  else if (req.indexOf("/light2/0") != -1){
    val = 0;
    what = "Light_2";
    which = light2;
  }
  else if (req.indexOf("/fan/1") != -1){
    val = 1;
    what = "Fan";
    which = fan;
  }
  else if (req.indexOf("/fan/0") != -1){
    val = 0;
    what = "Fan";
    which = fan;
  }
  else if (req.indexOf("/socket/1") != -1){
    val = 1;
    what = "Socket";
    which = socket;
  }
  else if (req.indexOf("/socket/0") != -1){
    val = 0;
    what = "Socket";
    which = socket;
  }
  else {
    Serial.println("invalid request");
    client.stop();
    return;
  }

  digitalWrite(which, val);

  String url = "http://aoatech.ml/hitthis.php?room=Bed%20Room%201";
  url += "&state=";
  url += val;
  url += "&button=";
  url += what;
  url += "&mac=";
  url += mac;

  Serial.print("Requesting URL: ");
  Serial.println(url);

  client.flush();
  //  client.println("HTTP/1.1 200 OK");
  //  client.println("Content-Type: text/html");
      client.print(String("GET ") + url + " HTTP/1.1\r\n" +
           "Host: " + host + "\r\n" +
           "Connection: close\r\n\r\n");
  unsigned long timeout = millis();
  while (client.available() == 0) {
    if (millis() - timeout > 5000) {
      Serial.println(">>> Client Timeout !");
      client.stop();
      return;
    }
  }
  client.println("");
  client.print(what + " is now: ");

  if(val == 0) {
    client.print("Off");
  } else {
    client.print("On");
  }
  Serial.println("Client disonnected");
}


texts: Impossibility to open a file for modification in ESP32

texts:
Consider the following code:

#include "SD.h"
#include "Fs.h"

void setup() {
  Serial.begin(115200);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }

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

  // see if the card is present and can be initialized:
  if (!SD.begin(5)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    while (1);
  }
  Serial.println("card initialized.");

  File file = SD.open("/test.txt", FILE_WRITE);
  file.write((const uint8_t*)"is a test", 10);
  file.close();

  file = SD.open("/test.txt", FILE_WRITE); <-- Tested with APPEND too
  file.seek(0);
  file.write((const uint8_t*)"this", 4);
  file.close();

  file = SD.open("/test.txt", FILE_READ);

  while (file.available()) {
    Serial.write(file.read());
  }
  file.close();
}

void loop() {
  // put your main code here, to run repeatedly:

}

If I open the file with FILE_WRITE the contents of the file are zeroed and I get as output:

  "this"

And if I open the file in mode FILE_APPEND then seek() does not work and I get as output:

  "is a testthis"

How to modify this program so I get any of both?

  "thisis a test" [insert] (or) "thistest" [overwrite]

Using an ESP32 here as I think the File or the SD objects are different than the Arduino ones.


texts:
I'm writing a simple application that reads voltage from analog input 0. Here is the code:

#define OUT 5
#define ADC 0

void setup() {
  ADMUX &= (0<<REFS0); //Setting reference voltage to internal 1.1V
}

// the loop routine runs over and over again forever:
void loop() {
  // read the input on analog pin 0:
  int sensorValue = analogRead(0);
  float voltage = sensorValue * (1.1 / 1023.0);
  if (voltage>0.5) {
    digitalWrite(OUT,HIGH);
  } else {
    digitalWrite(OUT,LOW);
  }
}

When I apply 1 V on ADC0, the OUT pin is low. Seems like the reference voltage is not set properly. When I set VREF to VCC (5V), everything works fine.

I cannot find the mistake. Would appreciate any help:)

Edit:

Link to datasheet: http://www.atmel.com/images/doc8008.pdf


texts:
I have some level of programming background, however never with Arduino's. I've just started hacking at the examples - I'm not even sure what language I'm currently writing. I presume it's C++.

Anyway, I figured I'd try out the pin 13 LED with the BlinkWithoutDelay example. I've got that running fine (which I was very excited about), however I've tried to modify it to blink out SOS in Morse code, but it doesn't appear to be working.

// constants won't change. Used here to set a pin number :
const int ledPin =  13;      // the number of the LED pin

// Variables will change :
int ledState = LOW;             // ledState used to set the LED

// Generally, you should use "unsigned long" for variables that hold time
// The value will quickly become too large for an int to store
unsigned long previousMillis = 0;        // will store last time LED was updated

// constants won't change :
//unsigned long interval = 1000;           // interval at which to blink (milliseconds)

// Number of times to blink
const long blinkMax = 10;
// Counter for number of times blinked
unsigned long blinkCount = 0;

void setup() {
  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);
}

void loop()
{
  int loopCount = 0;
  // S O S
  int values[] = {1000, 1000, 1000, 200, 200, 200, 1000, 1000, 100};
  blink(values[loopCount]);
  loopCount = loopCount + 1;
}

void blink(int interval)
{
  unsigned long currentMillis = millis();
  if(currentMillis - previousMillis >= interval) {
    previousMillis = currentMillis;
    if (ledState == LOW)
      ledState = HIGH;
    else
      ledState = LOW;
    digitalWrite(ledPin, ledState);
  }
}

As you can see, I've assigned the time values (1000 for long and 200 for short) to an array and had the loop function call my blink function each time. Every time it loops, it increments and goes to the next value.

I know it's able to pull values from the array fine, as I've tried manually modifying loopCount just before the blink() and it blinks at the specified timeout. I presume the loopCount increment is fine (I also did loopCount++; - no luck).

If someone could point me in the right direction, this would be great. Thanks!


texts: Software Serial blocking Wifi Connection

texts:
I'm trying to connect my NodeMCU to wifi. It isn't finishing because software serial is interrupting it.

Sort of like Software serial conflict with WiFi on ESP8266.

Here's my code:

#include <SoftwareSerial.h>
#include "ESP8266WiFi.h"

const char* ssid     = "mywifi";
const char* password = "password123";

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

        connectWifi();

        SoftwareSerial pinSerial(1, 3);
        pinSerial.begin(9600);
}

void loop() {
    // send data received from serial port
}

// in separate function so I can reconnect in the loop
bool connectWifi() {
        WiFi.begin(ssid, password);
        while (WiFi.status() != WL_CONNECTED) {
                delay(500);
                Serial.print(".");
        }
        Serial.println("");
        Serial.println("WiFi connected");
        Serial.println(WiFi.localIP());
        if( WiFi.status() == WL_CONNECTED) {
                return true;
        } else {
                Serial.println("wifi connection failed");
        }
}

The console outputs the periods as it's connecting but never prints the IP and instead prints the serial data it received while trying to connect.

Can I delay the activation of the software serial port? Should I use another serial library?

Please don't focus on basic code errors, I'm still learning.


texts: How do I recover a beetle where I loaded a program that was too large and overwrote the bootloader?

texts:
I'm doing on-target unit testing for an industrialized application and my test code is too large to fit everything on the board at the same time. I'm using the Sloeber toolset to develop, and I put something on the board that was over 28K, and the programming failed. Now the beetle does not show up as a serial port, and not even when pushing the reset pins, which I've had to do a number of times in the past.
If I overwrote the bootloader, which seems likely, is there a way to recover it? Do I need to reprogram the bootloader on a Beetle board? I haven't found any way to do that with a Beetle...
Thanks!


texts: Is there a way to use functions defined in a library in any class?

texts:
I'm trying to design a menu interface on a 1.8'' TFT display module. I've got it working with the Adafruit_ST7735 + Adafruit_GFX libraries. At least when I was just trying out the features... But now I'm trying to organize the code in Classes as this thing will get too complex soon. I have done some Java and C, so I started learning C++. I've been reading and coding nonstop for a week now, but there are some things that I can't wrap my head around that keep me from making any progress for a couple of days already.

So... For example there's a function public void drawRect(); in Adafruit_ST7735 library and I have a function draw() that draws a bunch of related stuff to the display in my own class (Rectangle.cpp). Say I initialize the display in my main program file how can I use that drawRect() function in my Rectangle::draw()?

Also Rectangle will be used for composing other parts of the menu interface and will probably be initialized in a collection or as a member of another class.

I've tried a bunch of different things but I've come to a dead end.

EDIT:

main program:

#include "_v0_0_0.h"
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>

#include "Point.h"
#include "Rectangle.h"
#include "SomeView.h"

#define     TFT_CS  4
#define     TFT_RST 0
#define     TFT_DC  10

Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
SomeView a_view;

void setup()
{
    tft.initR(INITR_BLACKTAB); // initializes the display
}

void loop()
{
    a_view.draw(); //draw something to view (a button, scrollbar, menu item, etc)
    while (true) {}
}

SomeView.h:

#include "Rectangle.h"

class SomeView {
private:
    Rectangle a_rectangle;
public:
    SomeView();
    void draw();

    const Rectangle& getRectangle() const {
        return a_rectangle;
    }

    void setRectangle(const Rectangle& rectangle) {
        a_rectangle = rectangle;
    }
};

SomeView.cpp:

#include "SomeView.h"

SomeView::SomeView() :
        a_rectangle(Point::Point(0, 0), Point::Point(0, 0)) {
}

void SomeView::draw() {
    a_rectangle.setCorners(Point::Point(0, 0), Point::Point(2, 6));
    a_rectangle.draw();

    a_rectangle.setCorners(Point::Point(20, 66), Point::Point(100, 100));
    a_rectangle.draw();
}

Rectangle.h:

#include "Point.h"
#include <Adafruit_GFX.h>    // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>

class Rectangle{
private:
    Point p1;
    Point p2;
public:
    Rectangle();
    Rectangle(Point& p1, Point& p2);
    void setCorners(const Point& p1, const Point& p2);
    void draw();

    // ... getters and setters for the points
};

Rectangle.cpp:

#include "Rectangle.h"

Rectangle::Rectangle() : p1(), p2()
    {
    }

Rectangle::Rectangle(Point& p1, Point& p2) : p1(p1), p2(p2)
    {
    }

void Rectangle::setCorners(const Point& p1, const Point& p2) {
    this->p1 = p1;
    this->p2 = p2;
}

// this is where I want to use a function from the adafruit library
void Rectangle::draw() {
    Adafruit_ST7735::drawRect(p1.getX(), p1.getY(), p2.getX(), p2.getY(), ST7735_GREEN);

}


texts: Using multiple timers and avoiding conflicts

texts:
I would like to use three timers in CTC mode to launch three Interrupt Service Routines at different frequencies.

In this application I need to use the servo library, millis() and micros() functions.

Timer3 (Working)

Thanks to this question, Timer3 has been set up in the following way:

  cli();          // disable global interrupts
  TCCR3A = 0;     // set entire TCCR3A register to 0
  TCCR3B = 0;     // same for TCCR3B

  // set compare match register to desired timer count:  @~744 Hz
  OCR3A = 20;
  // turn on CTC mode:
  TCCR3B |= (1 << WGM32);
  // Set CS10 and CS12 bits for 1024 prescaler:
  TCCR3B |= (1 << CS30) | (1 << CS32);
  // enable timer compare interrupt:
  TIMSK3 |= (1 << OCIE3B);
  // enable global interrupts:
  sei();

  ISR(TIMER3_COMPB_vect)
  {
     cont++;
  }

Timer4
I've tried with this configuration:

cli();          // disable global interrupts
TCCR4A = 0;     // set entire TCCR3A register to 0
TCCR4B = 0;     // same for TCCR3B

// set compare match register to desired timer count: @ ~744 Hz
OCR4A = 20;
// turn on CTC mode:
TCCR4B |= (1 << WGM42);
// Set CS10 and CS12 bits for 1024 prescaler:
TCCR4B |= (1 << CS40) | (1 << CS42);
// enable timer compare interrupt:
TIMSK4 |= (1 << OCIE4B);
//TIMSK4 |= (1 << OCIE4A); same issue
// enable global interrupts:
sei();

ISR(TIMER4_COMPB_vect) //TIMER4_COMPA_vect same issue
{
  cont++;
}

But the compiler returns an error caused by the servo library conflict:

  Servo\Servo.cpp.o: In function '__vector_42': C:\Program Files
  (x86)\Arduino\libraries\Servo/Servo.cpp:117: multiple definition of
  '__vector_42' Timer4B_800Hz.cpp.o:C:\Program Files
  (x86)\Arduino/Timer4B_800Hz.ino:49: first defined here c:/program
  files
  (x86)/arduino/hardware/tools/avr/bin/../lib/gcc/avr/4.3.2/../../../../avr/bin/ld.exe:
  Disabling relaxation: it will not work with multiple definitions

As Gerben suggested in a comment in this question:

  They are just hogging all timers. I guess you have to alter the
  library slightly by removing the #define _useTimer3 line, or try
  putting a #undef _useTimer3 right after the include. –  Gerben

I would avoid changing the servo library since motors play a critcal role in the application.

Timer 5 Same issue

Which timers and output compare registers can I use to set up the three ISR correctly?


texts:
It says in the description of the function:

  Registers a function to be called when a slave device receives a transmission from a master.

So when does it exactly called? I guess it's not been called for each byte, but its the meaning of receiving transmission from the master. Does it called for each byte? When the master use transmissionBegin? transmissionEnd?


texts: How to select which resistor is required for my curcuit to reduce voltage

texts:
I am trying to connect arduino and esp8266 as like this

I know arduino runs at 5V and RX of ESP8266 should not have voltage more than 3.5V. If you see my diagram there voltage is large than need on RX of ESP8266. I know resistor can help me for this and ohm law.

V = R.I => R = V/I

So I want to understand how should I select what ohm resistor for this cuicuit ? Can anyone explain with some calculation using ohm law ?


texts:
I want to connect 24 DS18B20 sensors to arduino by onewire library in the same digital pin .

Can anyone post an example code ?

Thanks


texts: What is the best way to connect multiple Arduinos?

texts:
In my situation, I have a map divided into multiple parts, each part could have about 20 to 100 Arduinos that they should send information from time to time to the master. How could I do this?

Second problem. How could I use the other Arduinos to send the info from Arduino that are so far from the Master?

Example in part 1: Arduino X is 500 meters far away from the master. How could use the other to send the information?

Can I do this with NodeMcu or such equipment with built-in WiFi?


texts: Can d2xx connect to an arduino mega 250?

texts:
I am trying to replace a device which used a FTDI chip (http://www.ftdichip.com/Drivers/D2XX.htm) to get USB to serial. I need some more code on the chip, so I want to use an arduino mega 2560 instead. However, there is quite a lot of software which talks to the FTDI-based solution, some of which is not maintained by myself.

Can I write a program for arduino mega which makes it look to the PC software like I am still a FTDI chip? I am somewhat concerned, because the FTDI requires special drivers, so any software will try to use this driver to connect to the arduino, which does not have a chip that is native to the d2xx driver.

Best,
Alex

PS: If I am not mistaken, arduino used those FTDI chips in the past, but switched to ATmega8u2 for arduino UNO, and to ATmega16U2 for arduino mega 2560.


texts: Outputting 400 mV using Arduino Nano PWM pin

texts:
I am trying to output analog voltage (400 mV) using Arduino Nano PWM pins. Is it okay to directly connect (using jumper wires) the PWM pins to the Vin+ of the INA219 current sensor?

I badly need it for my graduation project. Thanks for the help.


texts: How to write a digitalWrite array for MCP23017 expander chip?

texts:
I'm using multiple expander chips for my project and I was wondering if there is a way to shorten the loop code by using array? So that I don't have a super long code.

void setup() {
  mcp.begin(0);
  mcp1.begin(1);
  mcp.pinMode(0, OUTPUT);
  mcp.pinMode(1, OUTPUT);
  mcp.pinMode(2, OUTPUT);
  mcp.pinMode(3, OUTPUT);
  mcp.pinMode(4, OUTPUT);
  mcp.pinMode(5, OUTPUT);
  mcp.pinMode(6, OUTPUT)
  mcp.pinMode(7, OUTPUT);
  mcp1.pinMode(0, OUTPUT);
  mcp1.pinMode(1, OUTPUT);
  mcp1.pinMode(2, OUTPUT);
  mcp1.pinMode(3, OUTPUT);
  mcp1.pinMode(4, OUTPUT);
  mcp1.pinMode(5, OUTPUT);
  mcp1.pinMode(6, OUTPUT);
  mcp1.pinMode(7, OUTPUT);
}

void loop() {
  mcp.digitalWrite(0, LOW);
  mcp.digitalWrite(1, LOW);
  mcp.digitalWrite(2, LOW);
  mcp.digitalWrite(3, LOW);
  mcp.digitalWrite(4, LOW);
  mcp.digitalWrite(5, LOW);
  mcp.digitalWrite(6, LOW);
  mcp.digitalWrite(7, LOW);
  mcp1.digitalWrite(0, LOW);
  mcp1.digitalWrite(1, LOW);
  mcp1.digitalWrite(2, LOW);
  mcp1.digitalWrite(3, LOW);
  mcp1.digitalWrite(4, LOW);
  mcp1.digitalWrite(5, LOW);
  mcp1.digitalWrite(6, LOW);
  mcp1.digitalWrite(7, LOW);
}


texts:
Does anyone know (1) how much transient current can be output from a pin and (2) how much (and how long) reverse current an output pin can take?  For instance, consider the following circuit (driven by a series of 10 ms pulses at 5V):

  o----------------
       |          |
       = 10µF    1k LOAD
       |          |
  o----------------

which would be a classical filtered (smoothed) PWM circuit.  When the pin goes to +5V, the capacitor would act like a short and allow very high current (assuming about 20 ohm impedance, maybe 250 mA) for a millisecond or so.  Similarly, when the voltage drops to 0V, the charged capacitor will discharge, leading to a reverse current until it bleeds through the load.  Will either of these damage the diodes in the pin or even the IC?  Thanks.  (Worse comes to worse, does this mean that a resistor and diode are needed to protect the pin?)

More info

1)  It's 10µF.  10 pF would be useless in a power supply, it would only store 0.05 µC of electricity at most, which would only be able to smooth the output for a few microseconds.

2)  The load is resistance, 1 k ohms.

3)  A diode would be handy if you wanted to prevent reverse current, since you could put a much larger diode outside than the protective diodes in the Arduino.  They are classically used with motors (inductive load) as a clamp diode.

4)  My general question is about high transient current or reverse currents.  A capacitor is just an example of a situation that could cause this.  Another example would be a pin that is putting out only occasional (for example) 1ms long 100 mA pulses, separated by many seconds.  Such a circuit is really not delivering much power, but for very short periods it exceeds that recommended 40 mA.  Would this burn out the pin or not?

5)  A capacitor in parallel with the load is pretty much the classic filtered DC power supply.  Open any wall wart you have and you'll see a transformer, a rectifier and several large (electrolytic) capacitors (along with a couple small ones) and a voltage regulator.  Closer to this example, say you want to deliver current at 2 volts DC.  You can do this by alternating 2 ms pulses (at 5V) with 3 ms at 0V.  Then have a capacitor in series to smooth it to closer to DC, making it more like analog output.  That is, in fact, exactly how adjustable power supplies often work.


texts:
I was reading through SparkFun's article on transistors when I came across something that confused me. The article showed this circuit:
With this description:

Similar to the NPN circuit, the base is our input, and the emitter is tied to a constant voltage. This time however, the emitter is tied high, and the load is connected to the transistor on the ground side.
This circuit works just as well as the NPN-based switch, but there’s one huge difference: to turn the load “on” the base must be low. This can cause complications, especially if the load’s high voltage (VCC in this picture) is higher than our control input’s high voltage. For example, this circuit wouldn’t work if you were trying to use a 5V-operating Arduino to switch on a 12V motor. In that case it’d be impossible to turn the switch off because VB would always be less than VE.

I am confused because the part about the Arduino not being able to turn off a PNP transistor makes sense, but doesn't the circuit shown feature exactly the situation described that the transistor wouldn't work in? Is this an oversight by me and is there something else going on here that I don't understand, or is this a mistake in the article?


texts: Arduino Due works perfectly on Windows but doesn't on Linux (SAM-BA operation failed)

texts:
I've been working with the Arduino Due for a project, we have been setting up these Arduinos with an ARM Board that hosts a Linux System with Busybox that connects to the Arduino. Recently I got assigned the job of making it possible for the Arduino Due to be updated with the new code remotely so we don't have to travel to each location every time we need to update anything.

At first it seemed easy, crosscompile bossac for Arduino Due and use it in the ARM Linux Board, needing to open the port at 1200 bauds so the Arduino is available for a new upload.

The problem is, i've tested bossac and it works perfectly on Windows same as the Arduino IDE, it always uploads the sketch without a single problem. On Linux, however it doesn't seem to be working properly, not even the full Arduino IDE in AMD64, we have already tested it in 2 Vbox with Linux and in 2 native Linux installations, testing 32b and 64b, ARM and x86, i've tested everything I've seen on the web: up the permissions, add the user to the dialout group, reset the board manually...

I'm sure i'm missing something stupid but I don't know what and it's driving me crazy because the Arduino IDE is supposed to work properly on Linux. Just in case, these are the steps I've followed:

Download the latest version of the Arduino Due, untar it and sudo ./install.sh
Add my user to the dialout group, and log out.
In the Arduino IDE go to the Board Manager and install the SAM support for Arduino Due
Select Arduino Due (programming port) and /dev/ttyACM0
Upload any sketch (also tried with example sketches), it compiles but when uploading the next message appears

  SAM-BA operation failed

And if using the verbose output this always happens after the next output,it seems to fail the last write and tries to overwrite it again (this is not the full output, there are writes and reads before this)

Chip ID      : 285e0a60
version()=v1.1 Dec 15 2010 19:25:04
Version      : v1.1 Dec 15 2010 19:25:04
Address      : 524288
Pages        : 2048
Page Size    : 256 bytes
Total Size   : 512KB
Planes       : 2
Lock Regions : 32
Locked       : readWord(addr=0x400e0a08)=0x1
readWord(addr=0x400e0c08)=0x1
writeWord(addr=0x400e0a04,value=0x5a00000a)
readWord(addr=0x400e0a08)=0x1
readWord(addr=0x400e0c08)=0x1
readWord(addr=0x400e0a0c)=0
readWord(addr=0x400e0a08)=0x1
readWord(addr=0x400e0c08)=0x1
writeWord(addr=0x400e0a04,value=0x5a00000a)
readWord(addr=0x400e0a08)=0x1
readWord(addr=0x400e0c08)=0x1

Almost every time it crashes it's like that but sometimes it even starts uploading and showing the percentage of upload but again "SAM-BA operation failed" before finishing the upload.

What irks me is that in Windows it works flawlessly so the board is all good and even compiling bossac from the sources produces the same error in Linux, I've also tested an Arduino Duemilanove and it works perfectly on Linux however it uses avr, not bossac. As i've said i've tested it in 4 machines and it's always the same, even in the ARM version.

What is it that I'm missing?

Thanks in advance.


texts:
I wrote code in Arduino to read SMS. I have a problem with receiving it from serial.

String str;

void setup() {
  Serial.begin(9600);
  Serial.println("AT+CMGF=1");
  delay(1000);
}

void loop() {
  Serial.println("AT+CMGF=1");
  delay(2000);
  Serial.println("AT+CMGR=1");
  delay(5000);
  while (Serial.available()>0) {
    str = char(Serial.read());
    Serial.print(str);
  }
  Serial.println();
}

I have an A6 GSM modem. When I read the serial I just get:

+CMGR: "REC READ

Nothing more!

I should get something like this:

+CMGL: 1,"REC READ","+989207201219",,"2017/08/26,21:54:56+05"
test 20

I changed my code to:

int readline(int readch, char *buffer, int len) {
  static int pos = 0;
  int rpos;
  if (readch > 0) {
    switch (readch) {
      case '\n': // Ignore new-lines
        break;
      case '\r': // Return on CR
        rpos = pos;
        pos = 0;  // Reset position index ready for next time
        return rpos;
      default:
        if (pos < len-1) {
          buffer[pos++] = readch;
          buffer[pos] = 0;
        }
    }
  }
  // No end of line has been found, so return -1.
  return -1;
}

void setup() {
  Serial.begin(9600);
  Serial.println("AT+CMGF=1");
  Serial.println("AT+CPMS=\"SM\",\"SM\",\"SM\"");
}

void loop() {
  Serial.println("AT+CMGF=1");
  Serial.println("AT+CMGR=1");
  static char buffer[80];
  if (readline(Serial.read(), buffer, 80) > 0) {
    Serial.print("You entered: >");
    Serial.print(buffer);
    Serial.println("<");
  }
  delay(3000);
}

But I get nothing.


texts: I am using an ATtiny85 for making a smart watch. Bluetooth module HC-05 with ATtiny85 pins PB3->TX, PB4->RX and it works. Secondly I have connected a 0.96" OLED on PB0 (SDA) and PB2 (SCL) and this is also working perfectly. But once I combine both things, it doesn't work.


texts: How to transfer data from Arduino to some software in computer?

texts: My arduino gets some data from sensors and save it into EEPROM. Now, I want that when I connect my arduino to PC there should be a software(like sketch) which can fetch data from arduino's EEPROM processes it and saves it into a file in PC. I am willing to create such a software but how will I then communicate with arduino like Sketch does?


texts: RobotLinking 18B20 pinout and circuit board weirdness

texts:
I have a Dallas Semiconductors 18B20 temperature sensor on a RobotLinking board. It's part of the RobotLinking 37 Sensors Kit. The board has a LED to indicate activity. It resembles this:

Here's what's weird. All the guides I can find for the 18B20 say that the pin order is GND, DQ, VDD. That should mean pin 1 goes to GND, pin 2 goes to a GPIO, and pin 3 goes to 3.3V or 5V (this one can take either). Yes, I am looking at the sensor's pins from its bottom.

If I do this, the board's LED is lit solidly. I get 0 degree readings, the same as if no device was connected. (Infinite resistance?)

To make this work, and get valid temperature readings, I have to hook it up this way: sensor GND to the GPIO, sensor DQ to GND, and sensor VDD to 5V or 3.3V. The LED only flashes when the temperature is actually read.

Here's a twist: if you look at the circuit traces on the RobotLinking board, it looks like the paths between the male breadboard connectors and the sensor's pins 2 and 3 are reversed. This means if you think you are connecting to pin 3 via the male connectors, you are in fact connecting to pin 2, and vice versa. The path from pin 1 on the sensor to the male pin 1 where it plugs into the breadboard is straight, so pin 1 probably means pin 1.

When I described the above connections I made, I accounted for this apparent circuit pathing weirdness.

Another twist is in the manual, the sensor is soldered to the middle leads. My sensor is instead on the furthest leads from the pins, like in the attached image.

The manual with this kit didn't explain any of this. I'm at a loss to understand my observations. For a generic sensor kit for n00bs, why would one want the pins on the bottom of the circuit board not correspond to the pinout of the sensor?


texts: Reading a string from Firebase and storing it as a CString

texts:
I have a mobile app (done using MIT App Inventor) storing some values to a Firebase database. App inventor stores all the values as strings (i.e. with quotes, and strings have quotes enclosed within quotes eg. "\"hello\"").
I'm using this library to fetch data from Firebase to ESP8266. I'm using String var to store the value retrieved and then change it to a CString (trying to store it directly doesn't work) as below:
This doesn't work:
Firebase.get(firebaseData, "/SCHEDULE DETAILS/SCHEDULE1/FREQ FR");
Serial.print("node -- schedule1 /FREQ FR -- type: ");
Serial.println(firebaseData.dataType());
char * cstr1 = new char [33];
cstr1 = firebaseData.stringData();
Serial.print(" -- data: ");
Serial.println(cstr1);

This works:
Firebase.get(firebaseData, "/SCHEDULE DETAILS/SCHEDULE1/WEIGHT");
Serial.print("node -- schedule1/WEIGHT -- type: ");
Serial.println(firebaseData.dataType() ) ;
String dummy = firebaseData.stringData();
Serial.print(" -- data: ");
Serial.print(dummy);
char * cstr = new char [dummy.length()+1];
strcpy (cstr, dummy.c_str());
Serial.print(" -- data int type: ");
Serial.println(atoi(cstr)) ;

I have some more nodes to get data from and I've read that lots of Strings are a bad practice. While trying to find out more, I saw the source code and stringData function itself returns a CString:

I feel like I'm doing one step more than what is required! Any suggestions on how to go about this would be very useful!
Try1 Based on the answer from @Majenko, I tried this before adding to the library:
const char* get_cstring() {
  String str = "will it work" ;
  return str.c_str();
}

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

void loop() {
  const char *new_c = get_cstring();
  int len = strlen(new_c);

  for (int i = 0; i < len; i++) {
    Serial.println(new_c[i]);
    delay(1000);
  }
  Serial.println("----------");
}

But how do I access the contents, because it just prints garbage values; strlen(new_c) gives 2 (I'm guessing that's the amount of storage needed in bytes!?)
Thanks!


texts:
I want to include a dependency like Logging. On its page it says:

Download zip file
Put the Logging folder in "libraries\".

I don't want to believe (with a Maven mindset) that this is the way we manage dependencies in Arduino projects. That means, everybody who checks out my package would have to repeat those steps locally (or do you include "libraries\" in the version control) What's the best practice for dependency management?


texts:
I have a 7 segment clock with 4 digits, and 2 push buttons to control time (hours seconds days month etc). What is the best way to manage the settings of each sub menu when the user wants to change the time? Is coding it myself or using a menu library such as this one better for the task? https://playground.arduino.cc/Code/Menu

Thanks


texts: Why does the Arduino Due have a native and USB programming port?

texts:
According to the schematics, the Arduino Due has two USB inputs:

Native
Programming

Why is this? And when would I use the different ports?


texts: How can I get the count of pulses of two encoders on the serial monitor?

texts:
I have two encoders; I connected them to pin 2 and 3 and I want to count the pulses of them to make two DC motors to work until it reaches a specified number of pulses, than stop working. I have finished the code of one encoder, but the other one I can't put in the same code.

byte pin = 2;
volatile float elapsed;
volatile float previous;
float rpm;
volatile int pulses;
volatile bool flag;

void setup() {
  Serial.begin(9600);
  pinMode(pin, INPUT);
  attachInterrupt(0, elapse, RISING);
  previous = millis();
}

void loop() {
  pulses = 0; // reset pulses counter

  attachInterrupt(0, elapse, RISING); // attach interrupt for rpm counter
  delay(500);
  detachInterrupt(0); // detach interrupt for rpm counter

  if (flag == true) {
    attachInterrupt(1, count, RISING); // attach interrupt for pulses counter
    delay(elapsed);
    detachInterrupt(1); // detach interrupt for pulses counter
    flag = false; // reset flag
  }

  rpm = 1000 / elapsed * 60;

  Serial.print("elapsed: "); // print resuslts
  Serial.println(elapsed);
  Serial.print("rpm: ");
  Serial.println(rpm);
  Serial.print("pulses: ");
  Serial.println(pulses);
}

void elapse() {
  elapsed = millis() - previous;
  previous = millis();
  flag = true; // set flag to activate pulses counter
}

void count() {
  pulses++;
}


texts: How to supply more than 500mA while powered by USB

texts:
I'm about to build myself a new BrewPi and I have some Arduino power/USB questions.

Something smiliar to a combination of these projects:

https://imgur.com/a/Nval6

https://www.homebrewtalk.com/threads/how-to-brewpi-lcd-add-on.510036/

The device will have a Raspberry Pi Zero W, an Arduino UNO (clone?), a LCD screen with backlight, and some relays and probes. The Pi must be connected to the Arduino via USB. The Arduino will drive the screen and some relays/probes. For simplicity's sake, I would like to power everything from the same regulated 5V power supply, and for ease of wiring I would prefer to power the Pi only and have it power the Arduino via USB, with the Arduino then supplying power to the rest.

My preference:
5V ----> Pi Zero --(USB)--> Arduino --(5V)--> Screen/etc.

However, according to this datasheet the max draw of the screen might exceed 1000mA:
https://www.vishay.com/docs/37314/lcd020n004l.pdf

This obviously exceeds the 500mA limit from the Arduino's 5V pin while being powered via USB. However, a Pi Zero has few safety features and does not limit outgoing current from it's USB port:
https://www.reddit.com/r/raspberry_pi/comments/3zyhuq/pi_zero_usb_power_outputmilliamps/

Given this, is it feasible to short/bypass the Arduino's polyfuse and then draw more than 500ma from the 5V pin of the Arduino without too many problems?

If not, can I 'add' the power supply's 5V to the Arduino's 5V (either from the Pi's 5V pin, or direct from the power supply) at the same time as maintaining the USB connection (which uses the same 5V source)? I'm stretching the limit of my circuit understanding here. If not how should I power the other components?

Would it instead be better to have a 12V supply and power the Arduino directly, then attempt to power everything else from its 5V pin (remembering that there is still a USB connection from the Pi back to the Arduino). What I'd really like to avoid in this situation is having to provide a second 12V->5V conversion.

Any help or advice would be greatly appreciated.


texts: How does the dual 5V and 3.3V output on the Uno R3 work exactly?

texts:
I'm constructing a circuit that needs both voltage supplies (for 3.3V RFID and 5V relay, GPS and screen) but the Uno is physically too big so I need to use a nano or mini pro, both of which I can only get in 5V. I understand how to use a regulator to drop 5V to 3.3V for the RFID-IC power but I keep seeing instructions to use a level shifter between the IC outputs and arduino input pins. I was just wondering if the Uno has a built-in level shifter for all pins or some other method as the I/O pins do not have specified voltages or uses.

Thanks for your time.


texts: What's the best way to operate a remote control circuit board?

texts:
What would be the best way of using an Arduino to operate the pictured remote control circuit board? My initial instinct would be to leave the batteries in the remote and use a separate transistor for each of the five switches, connecting wires (solder or electrical tape) to the two sides of each button and the base to an Arduino output pin. I'm certainly not an expert, so I wanted to confirm whether (a) that would work and (b) if there's a much better way. The control is normally powered by two AAA batteries.

Edit: There's also a small capacitor on the underside of the circuit board, if that changes anything.

Thanks in advance for your help
Note: I've tried to simply record and emit the IR signals from the remote using my Arduino, but have thus far been unsuccessful, so want another way of using the Arduino to control my fan: Unable to control fan with IR circuit despite capturing and reproducing the IR transmissions


texts: ESP8266 WiFi Module disconnects from WiFi itself

texts:
#define id "qwerty"
#define password"123456789"
int relayPin= 4;
void setup()
{
  Serial.begin(115200);

  Serial.println("AT");
  pinMode(13, OUTPUT);
  pinMode(relayPin, OUTPUT);
  delay(3000);

  if (Serial.find("OK")) {
    Serial.println("AT+CWMODE=1");
    delay(2000);
    String connectionCommand= String("AT+CWJAP=\"") + id+ "\",\"" + password+ "\"";
    Serial.println(connectionCommand);
    delay(5000);
    Serial.println("AT+CIFSR");
    delay(50);
    Serial.println(Serial.read());
  }

  Serial.print("AT+CIPMUX=1\r\n");
  delay(200);
  Serial.print("AT+CIPSERVER=1,80\r\n");
  delay(1000);
}
void loop() {
  if (Serial.available() > 0) {
    if (Serial.find("+IPD,")) {
      String metin = " Hello World ";
      metin += "
<button type='button'>ON</button>";
      metin += "
<button type='button'>OFF</button>";
      String cipsend = "AT+CIPSEND=";
      cipsend += "0";
      cipsend += ",";
      cipsend += metin.length();
      cipsend += "\r\n";
      Serial.print(cipsend);
      delay(500);
      Serial.println(text);
      lock_open_close();
      //Serial.println("AT+CIPCLOSE=0");

    }
  }
}

void lock_open_close() {
  String coming= "";
  char readonserial;
  while (Serial.available() > 0) {
    readonserial= Serial.read();
    coming+= readonserial;

  }
  Serial.println(coming);
  if ((coming.indexOf(":GET /?pin=on") > 1)) {
    digitalWrite(13, HIGH);
    digitalWrite(relayPin, HIGH);
    delay(200);
  }
  if ((coming.indexOf(":GET /?pin=off") > 1)) {
    digitalWrite(13, LOW);
    digitalWrite(relayPin, LOW);
    delay(200);
  }
}

Here's my code. I connected ESP8266 with a relay and a solenoid lock, so that I am expecting to control the lock with the buttons. But ESP8266 disconnects itself. Any suggestions?

Thanks a lot.
Sincerely,
Y.


texts: How to connect MPU6050 to arduino using only digital pins

texts:
I am relatively new to Arduino and microchips, but I am good at electronics. I want to connect MPU6050 accelerometer+gyroscope module to Arduino. I searched on the internet and everywhere it is said to connect the SCL and SDA pins to two analog pins of the Arduino. As far as I know, the MPU6050 is a digital sensor, so why 2 analog pins are required for the sensor?

Also, is there any way to connect the sensor with only digital pins? because I need the analog pins for some other purpose.


texts: Connecting 12V WS2811 RGB LEDs to Arduino Uno & 5V Power Source (Breadboard needed?)

texts:
I have an Arduino Uno, 12V WS2811 RGB LEDs (from Mokungit), a 5V power source, and DC power connector. I do not have a breadboard and hope I don't need one.

This is almost exactly what I need to follow this tutorial to build a Stranger Things wall. The LED strip listed shares the same name as the one I have, but the wiring is different.

Here's a photo from the Instructables site:

However, the wires coming from my strip don't match up to the instructions, and I can't seem to figure out how to get these bad boys burning.

Thanks to anyone who can help me get started!


texts: Program/Read 93LC46B with an Arduino with bit-banging

texts:
I'm Tom. I'm pretty new to electronics and programming but I've been getting better. So, recently I bought a 93lC46B EEPROM from Element 14 (It was $0.28! Why not!). I've been doing some research and reading the datasheet VERY carefully. But I still can't get the EEPROM to work right. I'm using an Arduino Uno to program the chip by using the Bit-Banging method. So what I've understood is that I need to cycle the clock, then pull the CS (Chip select) to high and then cycle the clock after each bit like this:

digitalWrite(CLK, LOW);
digitalWrite(DATAIN, VALUE);
digitalWrite(CLK, High);

But so far, that method hasn't been working right. I can't seem to read or write to the device properly. I'm using this set of bits to write 1 and 2 to the first address of the ROM: 1 0 1 0 0 0 0 0 0 0 0 1 1 0 0 0 1 0 0 1 1 0 0 1 0.

Here's my code so far (Sorry in advance on how bad it is):

#define DATAOUT 11//Comes from DO on chip MISO
#define DATAIN 13 //Goes to DI on chip    MOSI
#define CLK 10
#define CS 9

int data[] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
int inst1[] = {1,0,1,0,0,0,0,0,0,0,0,1,1,0,0,0,1,0,0,1,1,0,0,1,0};
int inst2[] = {1,1,0,0,0,0,0,0,0};

void setup(){
  Serial.begin(9600); //Start serial coms

  pinMode(CS, OUTPUT);
  pinMode(DATAOUT, OUTPUT);
  pinMode(DATAIN, INPUT);
  pinMode(CLK, OUTPUT);
  digitalWrite(CS, LOW);

  //Write 12 to address 1
  digitalWrite(CS, HIGH); //Enable device
  //Write to memory
  for(int i=0;i<25;i++){
    Write(inst1[i]);
  }
  digitalWrite(CS, LOW); //Disable device
  delay(250); //TCSL Delay
  Serial.print("Memory sucessfully written\n");

  //Read memory
  digitalWrite(CS,HIGH); //Enable device
  for(int i=0;i<9;i++){
    Write(inst2[i]);
  }
  Serial.print("Read instruction written\n");
  for(int i=0;i<16;i++){
    saveBit(i);
  }
  for(int i=0;i<16;i++){
    Serial.print(data[i]+"\n");
  }
  digitalWrite(CS,LOW);
  delay(250);
  Serial.print("Read successful!\n");
}

void Write(int Bit){
  digitalWrite(CLK, LOW);
  if(Bit==0){
    digitalWrite(DATAIN, LOW);
  }
  if(Bit==1){
    digitalWrite(DATAIN, HIGH);
  }
  digitalWrite(CLK, HIGH);
  delay(1);
}

void saveBit(int outbit){
  digitalWrite(CLK, LOW);
  if(digitalRead(DATAOUT) == HIGH){
    data[outbit] = 1;
  }
  if(digitalRead(DATAOUT) == LOW){
    data[outbit] = 0;
  }
  digitalWrite(CLK, HIGH);
  delay(1);
}

void loop(){

}


texts:
I am a bit confused about how memory works in Arduino.  I have created an integer array like so:

int* arr = new int[3] {1, 2, 3};

When I go to delete it:

delete[] arr;

The first element is deleted, and all the remaining ones are still  present and accessible.

Serial.println(arr[0]); // prints 0
Serial.println(arr[1]); // prints 2
Serial.println(arr[2]); // prints 3


texts: Temperature and Humidity Sensor TinyShield (No device found on com5)

texts:
Hi i have recently started working on a Temperature and Humidity Sensor TinyShield (ASD2511-R-T) and faced the issue as shown in the image below: No device found on com5.

I have followed the tutorial as shown in the TinyShield webpage and worked through the steps. 1) Installed the Arduino IDE, 2) Installed the Si7021 Arduino Library, 3)Download the .zip file of the example program and open it in the Arduino IDE.

This is the following example code provided by the tutorial.

/*
  TinyCircuits Si7020 Temperature and Humidity Sensor TinyShield Example Sketch

  This demo shows the bare minimum to read temperature and humidity data from
  the Si7020 sensor using the Si7020 library written by Marcus Sorensen.

  This example is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  Written 20 March 2016
  By Ben Rose
  Modified 07 January 2019
  By Hunter Hykes

  https://TinyCircuits.com
*/

#include <Wire.h>
#include <SI7021.h>

SI7021 sensor;

void setup()
{
  Serial.begin(115200);
  Wire.begin();
  Serial.print("Initializing sensor... ");
  if(!sensor.begin()){
    Serial.println("Sensor not found!");
    while(true);
  }
  Serial.println("Success!");
}

void loop()
{
  int celcius=sensor.getCelsiusHundredths()/100;
  int relativeHumidity=sensor.getHumidityPercent();
  Serial.print(celcius);
  Serial.print(" deg Celsius\t");
  Serial.print(relativeHumidity);
  Serial.println("% relative humidity");

  delay(500);
}

However, when I proceed to upload the program, the following error had occurred. This is the first time i am working on a TinyShield product.

Any help is appreciated! Thanks!

Do let me know if i need to provide any further information.

The options for COM 5 the only one avaliable.


texts: EEPROM Arduino library for ESP8266 is not working

texts:
I am trying to use EEPROM library from Arduino framework for my ESP8266 project (NodeMCU). I am using Atom with Platformio.
Initialization of EEPROM is attempted at void setup() in main.cpp:
EEPROM.begin(80);

The compiler throws an error at this line with:
request for member 'begin' in '0', which is of non-class type 'int'

This is strange as I just follow a simple example from GitHub.
I include <EEPROM.h> just as <Arduino.h> and many others (<ESP8266WiFi.h>, <ESP8266WebServer.h>, <ESP8266mDNS.h>). Platformio has created .pio\build\nodemcuv2\lib32c\EEPROM directory with EEPROM.cpp.o inside but compilation fails.
How can I make it work and what else should I check to find the problem?


texts: I snapped off these pins... Now my Arduino Clone seems to be dead

texts:
To save space for a project, i cut of these pins, thinking they are only used for writing a new bootloader onto the Arduino, but now it doesn't turn on, not even the LED, it also isn't visible in the COM selection

I tried 3 wires, all usb ports, and everything works for my ESP8266, but not for the Arduino...

Thanks for any help. I wonder if i bricked it.


texts: Why does my servo execute an action in the beginning when the odds are almost 0?

texts:
I made a servo motor turn if the result of random(0, 10000) is less than or equal to 1. If that is the case, the motor turns to 130 degrees, to 50 degrees, and then to default position(90 degrees). It works well except whenever I turn on the Arduino, it automatically executes the turning maneuver. It usually takes dozens of seconds for the randomNum to be 1 or 0. However, the servo always turns right away at the beginning. Here is my code. I will make comments to help you understand what I was thinking. I used no delays.

#include <Servo.h>
Servo servo;
unsigned long timer=millis();//counter
unsigned long servoTimer;
boolean turned130 = false;
int randomNum;//will hold value 0-9999
bool backCheck = false;//variables to keep track which code block to call
bool checkingAllowed = false;
bool turned50 = false;
bool startChecking = false;

void setup() {
servo.attach(12);
servo.write(90);//set default position
servoTimer=millis();
}

void loop() {
timer=millis();//update counter each time
if(checkingAllowed==false){
randomNum = random(0, 10000);//random number generator
if(randomNum<=1){//small odds
  checkingAllowed = true;//makes this codeblock unable to run
  servoTimer=millis();
  servo.write(130);
  turned130=true;/sets variables to allow other if statements to run
  turned50=false;
}
}
if(timer-servoTimer>=1000 && turned130==true && checkingAllowed==true && turned50==false){//next codeblock that runs if random <= 1 after 1 second
turn50();
}
if(timer-servoTimer>=1000 && turned130==false && checkingAllowed==true && turned50==true){
turnBack(); one second later this runs
}
if(timer-servoTimer>=1000 && checkingAllowed==true && backCheck==true){
  backCheck=false;//servo turns back to 90
  checkingAllowed = false;//allows the main code block to be called
}

delay(2);//small delay
}

void turnBack(){
random50 = random(0, 160);
servoTimer=millis();
servo.write(90);
backCheck = true;
turned50=false;
}
void turn50(){
turned130 = false;
random130  = random(0, 160);
servoTimer = millis();
servo.write(50);
turned50=true;
}

It takes a while for the random number to be 1 or 0. I do not understand how 100% of the time, the servo executes the maneuver in the beginning. I will give any more information if you need it to aid me. The random() will soon be replaced by ping() of ultrasonic sensor. Then, the problem will probably disappear. I just want to be clear on what is happening here.


texts: Get a specific item from comma separated text

texts:
I use bluetooth (works like serial monitor).
Let me say i send a text to my hc-05 (same as sending to serial monitor)
My current code is displaying text from serial monitor/HC-05 TO LCD
#include <LiquidCrystal.h>

LiquidCrystal lcd(4, 6, 10, 11, 12, 13);
String readString;

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

void loop() {
  while(Serial.available()){
    delay(50);
    char c=Serial.read();
    readString+=c;
  }
  if(readString.length()>0){
    Serial.println(readString);
      lcd.clear();
      lcd.print(readString);
    readString="";
  }
}

from serial monitor i type `a,b,c,d`

now my goal is to just get the a and display in lcd

or

in other words i want to get the value of a b c d in the text that is CSV to list or array and get value for index 1,2,3,4

OR

split string by delimiter

so how can i do it
details-ARUINO UNO


texts:
I want to save the file as date and time  and I want to open the file mySensorData = SD.open(filename, FILE_WRITE); in the set up. It shows "insert SD card" when I try to open the file in setup.

The data is not being written into the SD card. It is creating the file but not writing into file.


texts:
I got a TFT display module from China.
The TFT does not has D/C pin, how could I connect TFT to UNO or which library should I need to use??

Here is the pin name print on PCB:

VCC
TFT_CS
SDI (SDA)
SDO
SCK (SCL)
RST
SD_CS
TFT_BL
GND

According to my experence for another 2.2" LCD display with D/C Pin, I am using CD4050BE to convert the UNO pin 5v to 3.3v to fit to the TFT signal standard.

The product page (china seller) said it is using ILI9341, but I read the attachment which seller send to me, attachment said it is ILI9340. And I did a research from google, someone said it is HX8347A.

PS: I have tried using Adafruit_ILI9340 & Adafruit_ILI9341 with Adafruit_GFX, but I am no luck to see anything, the screen just got some flash (slightly dimmed and go back to bright).

Questions:

Which IC (ILI9341, ILI9340, HX8347A) is it using ?? How can I check it ???
Which library I should use ???
Just in case AVR (Arduino UNO, ProMini, Nano) unable to use this TFT, is there any Library for STM32F103 ??


texts:
My wire schema ;

http://bloglug.com/wp-content/uploads/2015/08/Arduino-esp8266-baglantilari.png

And i'm using arduino, it has blank loop. I'm trying AT command by using Serial Monitor and I have no response..


texts: How can I pair a Bluetooth dongle on arduino Yun (openwrt-yun)?

texts:
On my Arduino Yun (openwrt-yun, updated to latest version), I have a bluetooth dongle in the usb port; I have installed bluez-libs and bluez-utils (and python-bluez).  They show up as version 5.13.  hciconfig and hcitool work properly.  There does not seem to be any utility installed to pair with a device, nor can I figure out how to get pairing to work by editing config files.

I can find the device with hciconfig and hcitool, but rfcomm can't connect without the pin.  If I try the same sequence on my Linux laptop after pairing with the gui, rfcomm is able to connect, so I know the device is working properly (JY-MCU HC-06 on another Arduino).

All the recommendations I can find on the web indicate I should be able to use simple-agent or bluez-simple-agent, but they are not installed with these packages (there is no bluez-tools package for this distro).  If I manually copy the python script for the agent to the device and run it, it fails, saying that org.bluez can't be found with dbus.  There is no bluetoothd running, and no init script for any bluetooth demon.  None of the bt* tools are available.

I also found a description of how to set a pin code in /var/lib/bluetooth/[bt-addr]/pincodes (where bt-addr is my dongle address) containing a line of the form:

[device-addr]  [pincode]

but this seems to have no effect.

I have also tried settings in /etc/bluetooth/main.conf and /etc/bluetooth/rfcomm.conf, but I think they may only be for incoming connections.

Any help would be greatly appreciated.


texts: sim 900 sending wrong sms -" Ü " to mobile phone from arduino

texts:
i am having a problem while sending sms from arduino to a specific number. cell phone getting sms but every time it gets same unicode -" Ü " . plz help us

//--------------------------
#include <SoftwareSerial.h>

SoftwareSerial mySerial(2, 3);

void setup()
{
    mySerial.begin(115200);
    mySerial.print("\r");
    delay(1000);
    mySerial.print("AT+CMGF=1\r");
    delay(20000);

    mySerial.print("AT+CMGS=\"+91..........\"\r");

    delay(20000);
    mySerial.print("Hello!\r");   //The text for the message
    delay(10000);
    mySerial.write(0x1A);  //Equivalent to sending Ctrl+Z
}

void loop()
{

}


texts:
I have two DC motors that I want to shut off when the servo is at 140 degrees and then turn back on when the servo is back to 0 degrees. So like if servo == 140 motor 1 and 2 speed == 0. I am using an Arduino Uno and an Arduino motor shield. This is the code I got so far:
EDIT: This is what I got now but I keep getting an error say that servo_test was not declared in this scope. Not sure what is going on
#include <AFMotor.h>

#include <Servo.h>

Servo my_servo;

AF_DCMotor motor1(3);
AF_DCMotor motor2(4);

void setup() {
  my_servo.attach(9);
  motor1.setSpeed(130);
  motor2.setSpeed(130);

}

int angle;
int motor1pin = 3;
int motor2pin = 4;

void loop() {
  motor1.run(BACKWARD);
  motor2.run(BACKWARD);

  for (angle = 0; angle <= 140; angle += 1) {
    // command to move from 0 degrees to 140 degrees

    servo_test.write(angle); //command to rotate the servo to the specified angle

    if (angle == 0) {
      digitalWrite(motor2Pin, HIGH);
      digitalWrite(motor1Pin, HIGH);
    }
    if (angle == 140) {
      digitalWrite(motor2Pin, LOW);
      digitalWrite(motor1Pin, LOW);
    }

    delay(15);
  }

  for (angle = 140; angle >= 0; angle -= 1) {
    // command to move from 140 degrees to 0 degrees

    servo_test.write(angle); //command to rotate the servo to the specified angle

    if (angle == 0) {
      digitalWrite(motor2Pin, HIGH);
      digitalWrite(motor1Pin, HIGH);
    }
    if (angle == 140) {
      digitalWrite(motor2Pin, LOW);
      digitalWrite(motor1Pin, LOW);
    }

    delay(15);
  }

}


texts: How to read temperature using arduino uno board with PT100 RTD sensor?

texts:
I am new to arduino programming. And almost inexperienced.

I am looking to program my arduino Uno board to read 2/3/4 wire configuration of PT100 RTD sensor (in accuracy levels of atleast 0.5°C). The temperature range is 0 to 400°C and -50 to 100°C.

Since I am totally new to this field I would appreciate a rather descriptive information with circuits and images and code.

I have researched a lot on the subject, but couldn't get anything useful or substantial to solve my problem.

Moreover, I cannot use thermistor or any IC to read the temperatures as the machine on which the RTD is installed has PIDs, but I would like to create a datalogger that can fetch temperatures on computer itself.


texts:
I've got an Arduino Uno.

I was building a simple circuit with only one switch and it doesn't seem to work (I followed the Arduino project book from the Arduino starter kit).

This is my circuit :

Then I try again to move the switch and then it works (but I don't understand why).

So I tried to understand where the error is and I try to read digital input from the simple circuit with only one LED :

And this is my code :

int SWITCH = 13;

void setup() {
    Serial.begin(9600);
    pinMode(SWITCH, INPUT);
}

// the loop routine runs over and over again forever:
void loop() {
    int val;
    val = digitalRead(SWITCH);
    if(val == HIGH) {
        Serial.println("OKAY");
    }
}

I expect to see on the Serial Monitor "OKAY OKAY" and so on... but nothing appears on the Serial monitor.

Then I try to change the condition :

if(val == LOW)

And now I see "OKAY OKAY" and so on...

I think that there is something wrong with this Arduino... Can someone tell me something about what is happening? Am I stupid or there is really something wrong with this?


texts: How do I stop 5v on the I2C port of a pro mini so I can use 3.3v devices?

texts:
The theory is that you can use 3.3v I2C devices from a 5v device as long as the pull ups are only to the 3.3v. I have a 5v pro mini connected to a bmp180 board which has a 3.3v regulator but no level shifters. It is working and giving me data but I am hoping I can get better quality measurements. One observation is the power rail on the BMP board after the 3.3v regulator is being pulled towards 5v. On the scope this looks to happen between i2c messages. I am using the "Adafruit-BMP085-Library" which is in turn using "Wire". In the wire library there is a comment that says that the writedigital() of 1 to the port is setting the pull ups.

Does anyone have any general advice on this issue?

What does the comment about setting the pull-ups mean? How is that function setting the pull ups?

When does the I2C switch back to being an GPIO? Are the lines being pulled high between messages because it is reverting to an GPIO?


texts:
I'm using an Arduino Uno with an Ethernet Shield and the arduino.cc Ethernet library for a custom TCP-based message-exchanging chat-like protocol. Specifically I'm using the Client class with its print()
and println() methods. It works.

But on each single print() or println() call a whole TCP packet is sent. Also if just one byte is printed, a whole TCP packet is sent over the IP layer. I mean there's a lot of TCP packets with very few data inside. In other words there's a big overhead.

For example take this message that my Arduino successfully sends and my server successfully receives:

i-am EEEEEEEE-EEEEEEEE-EEEEEEEE-EEEEEEEE\r\n

The code is the following:

stream.print("i-am");
stream.print(' ');
for (byte i = 0 ; i < SERIAL_CODE_LENGTH ; i++){
  if (  i % 4 == 0 && i != 0 ){
    stream.print('-');
  }
  if (serialCode[i] < 16){
    stream.print('0');
  }
  stream.print(serialCode[i], HEX);
}
stream.println();

All that EE are hexadecimal byte values from an array and they are fine. But I can see from Wireshark that those 42 bytes (that could be fit in a single packet) are sent in 22 TCP packets (one for each print call in my code)!

How can I avoid this fragmentation? Is there a way to use an hardware or software buffer to group data before to send (Nagle's algorithm)?

With other SDKs the data are buffered by default and they're sent when the buffer is full or when an explicit "push" or "flush" call occurs. I checked Client flush method and it looks to be a different beast...