texts: Software PWM implementation on ATTiny44 screws up timing functions

texts:
I've came up with a poor man's implementation of software-based PWM for the ATTINY44 and I'm kinda stuck now. It works but it screws up the timing functions badly (delay, delayMicroseconds) no matter what timer I use for the ISR (timer 1 or 0). The delay in my example is more like 1 second than 100ms. Can somebody point out what I'm doing wrong? :)

uint8_t pwmled[11] = {0};
volatile uint8_t currentStep = 0;
uint8_t p[11] = {PORTA0, PORTA1, PORTA2, PORTA3, PORTA4, PORTA5, PORTA6, PORTA7, PORTB0, PORTB1, PORTB2};

void initTimer1() {
  cli();
  TCCR1B = (1 << WGM12) | (1 << CS10);
  OCR1A = 64;
  TIMSK1 = (1 << OCIE1A);
  sei();
}

ISR(TIM1_COMPA_vect) {
  if (currentStep < 100)
    currentStep += 1;
  else
    currentStep = 0;
  for (uint8_t x = 0; x <= 10; x++)
    (currentStep < pwmled[x]) ? (x < 8 ? PORTA |= (1 << p[x]) : PORTB |= (1 << p[x])) : (x < 8 ? PORTA &= ~(1 << p[x]) : PORTB &= ~(1 << p[x]));
}

void setup() {
  initTimer1();
  for (int i = 0; i <= 10; i++) {
    pinMode(i, OUTPUT);
    pwmled[i] = 1;
  }
}

void loop() {
  pwmled[random() % 11] = random() % 100;
  delay(100);
}


texts: What are the components of a Xively HTTP PUT request to send to my SIM800 GPRS module?

texts:
I have an Elecrow GPRS shield which I want to use to post temperatures from 3 x DS18B20s to Xively. The example code is a mystery to me. You can find in full at this link: http://www.elecrow.com/wiki/index.php?title=GPRS/GSM_Shield_v1.0#A_Simple_Source_Code_Example

The relevant function is here:

///send2Pachube()///
///this function is to send the sensor data to the pachube, you can see the new value in the pachube after execute this function///
void Send2Pachube()
{
mySerial.println("AT+CGATT?");
delay(100);

ShowSerialData();

mySerial.println("AT+CSTT=\"CMNET\"");//start task and setting the APN,
delay(1000);

ShowSerialData();

mySerial.println("AT+CIICR");//bring up wireless connection
delay(300);

ShowSerialData();

mySerial.println("AT+CIFSR");//get local IP adress
delay(2000);

ShowSerialData();

mySerial.println("AT+CIPSPRT=0");
delay(3000);

ShowSerialData();

mySerial.println("AT+CIPSTART=\"tcp\",\"api.cosm.com\",\"8081\"");//start up the connection
delay(2000);

ShowSerialData();

mySerial.println("AT+CIPSEND");//begin send data to remote server
delay(4000);
ShowSerialData();
String humidity = "1031";//these 4 line code are imitate the real sensor data, because the demo did't add other sensor, so using 4 string variable to replace.
String moisture = "1242";//you can replace these four variable to the real sensor data in your project
String temperature = "30";//
String barometer = "60.56";//
mySerial.print("\"method\": \"put\",\"resource\": \"/feeds/43634/\",\"params\"");//here is the feed you apply from pachube
delay(500);
ShowSerialData();
mySerial.print(": ,\"headers\": \"X-PachubeApiKey\":");//in here, you should replace your pachubeapikey
delay(500);
ShowSerialData();
mySerial.print(" \"_cXwr5LE8qW4a296O-cDwOUvfddFer5pGmaRigPsiO0");//pachubeapikey
delay(500);
ShowSerialData();
mySerial.print("jEB9OjK-W6vej56j9ItaSlIac-hgbQjxExuveD95yc8BttXc");//pachubeapikey
delay(500);
ShowSerialData();
mySerial.print("Z7_seZqLVjeCOmNbEXUva45t6FL8AxOcuNSsQS\",\"body\":");
delay(500);
ShowSerialData();
mySerial.print(" \"version\": \"1.0.0\",\"datastreams\": ");
delay(500);
ShowSerialData();
mySerial.println("[\"id\": \"01\",\"current_value\": \"" + barometer + "\",");
delay(500);
ShowSerialData();
mySerial.println("\"id\": \"02\",\"current_value\": \"" + humidity + "\",");
delay(500);
ShowSerialData();
mySerial.println("\"id\": \"03\",\"current_value\": \"" + moisture + "\",");
delay(500);
ShowSerialData();
mySerial.println("\"id\": \"04\",\"current_value\": \"" + temperature + "\"],\"token\": \"lee\"");

delay(500);
ShowSerialData();

mySerial.println((char)26);//sending
delay(5000);//waitting for reply, important! the time is base on the condition of internet
mySerial.println();

ShowSerialData();

mySerial.println("AT+CIPCLOSE");//close the connection
delay(100);
ShowSerialData();

}
void ShowSerialData()
{
while(mySerial.available()!=0)
Serial.write(mySerial.read());
}

Note that although this is called "send2Pachube" it uses the Cosm API, which still works.
The section following the line

mySerial.println("AT+CIPSEND");

is where the HTTP gets formulated. I've assembled the string in the example code and it looks odd. The API key goes on about four times longer than it should. I'm not sure what all those colons are doing in there, are they a String operator? Can anyone give me an example of an HTTP PUT request for Cosm or Xively that illustrates how this string should be assembled?
Thanks


texts:
I need to read two values from hx711 load cells connected to strain guages. Ive found the code below that reads one guage, but being self taught and with little experience I have no idea how to adapt it to work with two, is anyone able to help?
I need two individual readings not a combined one
Thanks in advance, and credit to sparkfun who wrote this code.
#include "HX711.h"

#define calibration_factor -7050.0 //This value is obtained using the SparkFun_HX711_Calibration sketch

#define DOUT  3
#define CLK  2

HX711 scale;

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

  scale.begin(DOUT, CLK);
  scale.set_scale(calibration_factor); //This value is obtained by using the SparkFun_HX711_Calibration sketch
  scale.tare(); //Assuming there is no weight on the scale at start up, reset the scale to 0

  Serial.println("Readings:");
}

void loop() {
  Serial.print("Reading: ");
  Serial.print(scale.get_units(), 1); //scale.get_units() returns a float
  Serial.print(" lbs"); //You can change this to kg but you'll need to refactor the calibration_factor
  Serial.println();
}


texts:
I am new to Arduino and I want to connect it to my 2.1 speakers and later to a 5.1 surround system.

The purpose is to play some wav sounds when a button is clicked or when a trip laser is cut. What should I do in order to play those wav around through the speakers? I also have an SD shield.


texts:
I'm new to arduino's and am currently working on a project which requires a lot of different sensors. I was just wondering if its possible to use all the following sensors on a single Arduino Uno:

2 Separate Load sensors (i.e giving different readings) controlled with an load cell amplifier
a Gyro Sensor
an Accelerometer
and an ESC

If its not possible, could someone please tell me what hardware I would need to run all these sensors together. Thanks :).


texts:
This is a newbie question but I'm not having much luck googling.

I'm wanting to write code that accesses an InvenSense MPU-6050 motion sensor package. I've obtained the Embedded Motion Driver 5.1.1 package. It contains example code plus a driver in the form of a directory tree of .c and .h files. The file structure of the driver is

\---msp430
    |   msp430USB.cmd
    |   msp430_clock.c
    |   msp430_clock.h
    |   msp430_i2c.c
    |   msp430_i2c.h
    |   msp430_interrupt.c
    |   msp430_interrupt.h
    |
    +---F5xx_F6xx_Core_Lib
    |       HAL_FLASH.c
    |       HAL_FLASH.h
    |       HAL_MACROS.h
    |       HAL_PMAP.c
    |       HAL_PMAP.h
    |       HAL_PMM.c
    |       HAL_PMM.h
    |       HAL_TLV.c
    |       HAL_TLV.h
    |       HAL_UCS.c
    |       HAL_UCS.h
    |
    +---USB_API
    |   +---USB_CDC_API
    |   |       UsbCdc.c
    |   |       UsbCdc.h
    |   |
    |   +---USB_Common
    |   |       defMSP430USB.h
    |   |       device.h
    |   |       dma.c
    |   |       types.h
    |   |       usb.c
    |   |       usb.h
    |   |       UsbIsr.h
    |   |
    |   +---USB_HID_API
    |   |       UsbHid.c
    |   |       UsbHid.h
    |   |       UsbHidReq.c
    |   |       UsbHidReq.h
    |   |
    |   +---USB_MSC_API
    |   |       UsbMsc.h
    |   |       UsbMscReq.c
    |   |       UsbMscReq.h
    |   |       UsbMscScsi.c
    |   |       UsbMscScsi.h
    |   |       UsbMscStateMachine.c
    |   |       UsbMscStateMachine.h
    |   |
    |   \---USB_PHDC_API
    |           UsbPHDC.c
    |           UsbPHDC.h
    |
    \---USB_eMPL
            descriptors.c
            descriptors.h
            eMPL_CDC.inf
            usbConstructs.c
            usbConstructs.h
            usbEventHandling.c
            UsbIsr.c

It's intended to be used with a development environment called "Code Composer Studio." I'm trying to use it with the stock Arduino development environment (1.8.1). I create a new sketch and copy the example code into it. It includes various files from the driver tree;

#include "USB_eMPL/descriptors.h"

#include "USB_API/USB_Common/device.h"
#include "USB_API/USB_Common/types.h"
#include "USB_API/USB_Common/usb.h"

#include "F5xx_F6xx_Core_Lib/HAL_UCS.h"
#include "F5xx_F6xx_Core_Lib/HAL_PMM.h"
#include "F5xx_F6xx_Core_Lib/HAL_FLASH.h"

#include "USB_API/USB_CDC_API/UsbCdc.h"

#include "usbConstructs.h"

I've read about how to import libraries. However this isn't a library- copying it into the "libraries" folder of the project and restarting the IDE doesn't make anything new appear in Sketch->Include Library and nor does it allow the program to compile.

Copying the driver files and subdirectories into the same folder as the sketch gets me past the first hurdle of those include files not being found, but then similar lines in files in the driver subdirectories also cause errors because the paths are wrong. The files are obviously intended to be in a central dev environment "include" directory so the search always starts from the same point in the filesystem.

I've therefore tried copying the driver files into C:\Program Files (x86)\Arduino\libraries as the folder "msp430." This added an "msp430" item to the "Include Library" menu, but compilation still fails with unresolved includes. Using trial and error, it seems that I can only get files to be recognised if they're in their own folder in 'libraries.' So by pulling all the nested subfolders out and changing the paths in the top level again gets me past the first hurdle of the include files in the top level of code, but all the includes in the driver files then fail because they're looking for files in nested directories. I could go through and remove all the path information from every #include, but then everything's in the same "namespace" and with such generic names as "types.h" I can see that screwing up very quickly. So I can't believe that's how included files are generally managed on here.

So having said what hasn't worked, does anyone know what I can do that will work?


texts:
What is a rev id? I have looked everywhere for a proper definition but I haven't found anything. I am trying to understand the code below. I don't understand why this read_rev_id function is necessary and yes, I tried to look in the user manual for the IMU I am using but it is practically none-existent. I am using the myAHRS IMU and the only manual I could find, on GitHub, didn't even show a register by this name.

void setup()
{
  //Initialization
  Wire.begin();
  Serial.begin(115200);
  who_am_i();
  read_rev_id();
  delay(1000); //Wait for 1second.
}


texts: How to learn electronics/programming with Arduino?

texts:
I want to learn core and mechanics of microcontrollers with Arduino, and I don't really know where to find good source of knowledge.

Every Arduino related tutorial is about very basic stuff like connecting the LCD display without explaining what every pin does. When it comes to programming tutorials only explain what functions are needed and do not explain what happens inside the hardware.

For example i know what delay() function does, and I know that I can find definition in the source files:

void delay(unsigned long ms)
{
    uint16_t start = (uint16_t)micros();

    while (ms > 0) {
        yield();
        if (((uint16_t)micros() - start) >= 1000) {
            ms--;
            start += 1000;
        }
    }
}

But what I really want to know what that code does, and how to write own functions. I would appreciate if you could provide me with any starting point. Should I just follow the source files until I get it or is there any better reference?

I have Arduino Leonardo, and experience in programming in C/C++.


texts: Are there any GPS data pusher for Arduino?

texts:
I plan to build a GPS logger for my car using a GPS device, an Arduino board and a SD Card. The plan is that the GPS device forwards the position to the Arduino which is responsible for storing the data on the SD card. However, I would like to regularly (say every hour) send my current position to a server at home.

For that you can use GPS pusher or puller, but I couldn't find any such devices on the Internet. Do these devices exist? What are my (other) options?


texts:
I am trying to run a test of the speed of an Arduino, and how it's affected by different temperatures. Does the following code assess this properly?

long num = 0;
long startTime = 0;
long endTime = 0;
int duration = 0;
String buffer;

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

void loop(){
  startTime = millis();
  benchmark();
  endTime = millis();
  duration = endTime - startTime;
  Serial.print(startTime);
  Serial.print(", ");
  Serial.print(endTime);
  Serial.print(", ");
  Serial.println(duration);
}

void benchmark() {
  num = 0;
  for(num = 0; num < 1000000; num++);
}

I'm using an Uno, if that matters.


texts:
I'm following this tutorial to build an Arduino powered RGB led strip controller but I'm facing two problems:

When I use digitalOutput the lights are too dim.
When I use PWM the leds change so slightly that I can barely detect a change.

These are the parts I'm using:

Wemos D1 mini
a USB cable to power the Wemos
1k ohm resistors
TIP31c transistors
A power outlet 12V 1A to power the strip (which works fine with the original controller unit)

The circuit connected as presented in the tutorial (like the circuit below) doesn't work, the board does not start.

If I disconnect the board GND from the outlet GND then the board starts but the leds are too dim to be visible

What am I doing wrong?

simulate this circuit – Schematic created using CircuitLab


texts:
I've got just a simple question. What happens when I overload Force Sensitive Resistor (FSR). Example Here.

Let's say that it's got force sensitive range between 100g and 10 000g. What would happen if I'd create pressure about 100kg? I see that resistance is decreasing with bigger pressure. Will there be almost 0 ohm resistance? If so, can this FSR survive this overload? Has somebody test that?

Thank you for any answer.


texts: Switching external power supply to 5V cooling fan with an Arduino and 2N2222 transistor

texts:
I'm using a 2N2222 transistor as a low-side switch to turn a 5V computer fan on and off with an Arduino digital pin, which responds programmatically to a button press - i.e. the relevant digital pin is switched from LOW to HIGH for a determined time in response to a button press recorded on A0.

My circuit looks like this:

And here's my code:

#define btnPin A0
#define signalPin 6

void setup() {
  pinMode(btnPin, INPUT_PULLUP);
  pinMode(signalPin, OUTPUT);
  digitalWrite(signalPin, LOW);
}

void loop() {
  if(digitalRead(btnPin) == LOW){
  digitalWrite(signalPin, HIGH);
  delay(5000);
  digitalWrite(signalPin, LOW);
  }
}

For simplicity, I'm showing a separate button component in the diagram, but I'm actually using a button that's wired into an LCD shield.

My expectation is that, when I press the button, the digital pin wired to the transistor's base will cause the transistor to close the circuit and turn the fan (and LED) on for five seconds.

The problem that I have is that the Arduino's digital pin doesn't seem to be able to saturate the base, so not enough current passes through the transistor to power the fan. It does turn the LED on and off as expected, but the fan needs much more current than the LED. If I take a wire directly from VIN or the 5V pin and touch it to base (through a resistor, of course), it does succeed in saturating the base, and the fan turns on. Measuring the current from VIN (or the 5V pin) to base, I get 4mA, so my assumption is that 4mA is sufficient to saturate the base. My understanding is that an Arduino digital pin should easily supply this. But in my case, the current from the relevant digital pin to the transistor's base never goes higher than 1.4mA. I've tried different pins on the board, but always get the same result.

So the question is, why does the circuit work as expected for the LED, but not for the fan? Any help/suggestions will be greatly appreciated!


texts: Use an electromagnet for reading induction as well

texts:
I have an electromagnet that I wish to use to pull a neodyne magnet closer.

I'm thinking of having the electromagnet sensing when the magnet is close, but when the magnet is running I'm pushing 12 volts through it and I don't want to fry my Arduino. How can I do the wiring to achieve this?

I only have to be able to use the magnet as a sensor while it's turned off.


texts: Communication between Arduino and raspberry Pi

texts: So I am working on a ground surveillance robot using Arduino for coding the Gps, motors and ultrasonic sensors and coding in raspberry Pi for facial recognition but now what I want to do is when my robot has gotten to its final waypoint and has stopped it should excute the python file that does the facial recognition by calling it in the Arduino  sketch but I don't know how to do it would be nice if someone could please help me out I appreciate your help in advance thank you


texts: Replacing the IC (atmega328) if lifespan has been arrive

texts:
Consider if the lifespan of atmega328 has been wear out.
It said on datasheet of atmega how many times we can upload sketch about 10.000times (cmiiw), should i change the arduino or only the microcontroller after 10.000 times have been arrive? what if that times has been arrive? What happened with that IC? If it will starting problem, can we change only the microcontroller (atmega328PU)?? Or any there's thing or stuff we must change too?
Should i burn the bootloader to that IC after replace it?


texts: basic_insert with WAMP server doesn't connect with MySQL database

texts:
I'm trying to establish a connection with a MySQL database on a local server wirelessly using the following script:

The wireless connection with my router is successful but then connection with database results in

I'm using a WeMos D1 mini ESP8266, Windows 10, WAMP64, MySQL 5.7.14.

I get ping responses from MySQL at 127.0.0.1, and my host computer and also the ESP8266.  I've disabled my Windows Firewall to test it temporarily.  After the wifi connects with the ESP8266 and confirms the correct WiFi.localIP, 'Connection failed' error with additional text below.

I can manually enter data into the test_arduino table so I think it's a connection issue with the database server. Maybe something to do with my router's handling of of Port 80.

I am able to send sensor data to remote sites such as ThingSpeak.

Any help would be appreciated.

// Created by: Dr. Charles A. Bell

#include "ESP8266WiFi.h"
#include <MySQL_Connection.h>
#include <MySQL_Cursor.h>

IPAddress server_addr(192,168,0,10);  // IP of the MySQL *server* here
char user[] = "root";              // MySQL user login username
char password[] = "PASSWORD";        // MySQL user login password

const char* SSID = "MYSSID";         // Your network SSID
const char* PASS = "MYPASSWORD";

// Sample query
char INSERT_SQL[] = "INSERT INTO test_arduino.hello_arduino (message) VALUES ('Hello, Arduino!')";

WiFiClient client;
MySQL_Connection conn((Client *)&client);

void setup() {
  Serial.begin(115200);
  while (!Serial); // wait for serial port to connect

  Serial.print("Connecting to "+*SSID);
  WiFi.begin(SSID, PASS);
  Serial.println("going into wl connect");

  while (WiFi.status() != WL_CONNECTED) //not connected,  ...waiting to connect
    {
      delay(1000);
      Serial.print(".");
    }

  Serial.println("wl connected");
  Serial.println("");
  Serial.println("Credentials accepted! Connected to wifi\n ");
  Serial.println(WiFi.localIP());
  Serial.println("");

  if (conn.connect(server_addr, 3306, user, password)) {
    delay(1000);
  }
  else
    Serial.println("Connection failed.");
}

void loop() {
  delay(2000);

  Serial.println("Recording data.");

  // Initiate the query class instance
  MySQL_Cursor *cur_mem = new MySQL_Cursor(&conn);
  // Execute the query
  cur_mem->execute(INSERT_SQL);
  // Note: since there are no results, we do not need to read any data
  // Deleting the cursor also frees up memory used
  delete cur_mem;
}

The following is the Serial COM4 readout:

Connected to wifi
 going into wl connect
.......wl connected

Credentials accepted! Connected to wifi

192.168.1.XX (intentionally deleted)

Connection failed.
Recording data.

Exception (3):
epc1=0x402050ea epc2=0x00000000 epc3=0x00000000 excvaddr=0x402315cc depc=0x00000000

ctx: cont
sp: 3ffef5a0 end: 3ffef7d0 offset: 01a0

>>>stack>>>
3ffef740:  0a00a8c0 00000001 3ffe8785 402050f4
3ffef750:  3ffee524 0000000e 3ffe850e 3ffee79c
3ffef760:  3fffdad0 00000000 3ffee770 402048fd
3ffef770:  402315cc 00000000 3ffee770 3ffee79c
3ffef780:  3fffdad0 00000000 3ffee770 40204945
3ffef790:  402010ae 00000000 3fff061c 4020292e
3ffef7a0:  3ffe8780 00000000 3fff061c 40201d3e
3ffef7b0:  3fffdad0 00000000 3ffee794 40204c34
3ffef7c0:  feefeffe feefeffe 3ffee7b0 40100718
<<<stack<<<

 ets Jan  8 2013,rst cause:2, boot mode:(3,7)

load 0x4010f000, len 1384, room 16
tail 8
chksum 0x2d
csum 0x2d
v09f0c112
~ld


texts:
I am new to Arduino and electronics in general and I can't get my MKR1000 to read correct data from a DS18B20 temperature sensor.

Here is the tutorial I followed.

The issue is: I always get the same readings from the sensor: -127.00.

I should mention I have tried 2 different sensors and get the same readings.

From the sensor, GND goes directly to GND on the board, and I have the 4.7kΩ resistor in between the data and power wires.

According to the sensor manufacturer, output leads: Yellow (VCC), Red (DATA), Black (GND).

Data line is connected to the pin ~2 on the MKR1000.

/********************************************************************/
// First we include the libraries
#include <OneWire.h>
#include <DallasTemperature.h>
/********************************************************************/
// Data wire is plugged into pin 2 on the Arduino
#define ONE_WIRE_BUS 2
/********************************************************************/
// Setup a oneWire instance to communicate with any OneWire devices
// (not just Maxim/Dallas temperature ICs)
OneWire oneWire(ONE_WIRE_BUS);
/********************************************************************/
// Pass our oneWire reference to Dallas Temperature.
DallasTemperature sensors(&oneWire);
/********************************************************************/
void setup(void)
{
 // start serial port
 Serial.begin(9600);
 Serial.println("Dallas Temperature IC Control Library Demo");
 // Start up the library
 sensors.begin();
}
void loop(void)
{
 // call sensors.requestTemperatures() to issue a global temperature
 // request to all devices on the bus
/********************************************************************/
 Serial.print(" Requesting temperatures...");
 sensors.requestTemperatures(); // Send the command to get temperature readings
 Serial.println("DONE");
/********************************************************************/
 Serial.print("Temperature is: ");
 Serial.print(sensors.getTempCByIndex(0)); // Why "byIndex"?
   // You can have more than one DS18B20 on the same bus.
   // 0 refers to the first IC on the wire
   delay(1000);
}

Any idea what I am doing wrong?


texts: Converting the 3.3V PWM signal to 5V PWM signal

texts:
I am using ESP32....the max Pwm signal of it is 3.3V...And I have to control two motors speed by TB6612FNG motor driver...when i was using Arduino.. The arduino can send max 5V Pwm signal to the motor drivers PWM pin.. And the motor runs at the exact speed...but now i have to use ESP32..which sends 3.3V and the motors slow down..

So what should I do to convert the ESP32's PWM signal to 5v and according If i change the PWM value at the program..the output will also change similarly as Arduino??
Please help me


texts: I'm trying to use a CONZIR CO2 sensor to find CO2 concentration

texts:
Hey I’m a beginner Arduino user trying to use a CO2/Humidity/Temperature sensor to read in the atmospheric conditions near the sensor and then control a heating pad and solenoid valve to adjust the conditions to what I need. I am having a lot of trouble simply getting realistic values that are usable. It would be awesome if someone could point me in the right direction. I am trying to use sample code provided to me by CO2 meter and am not having any luck having the conditions update in the serial monitor. Any help would be greatly appreciated. Below is the code I am trying to use and linked below is the manual. After figuring out how to simply read the CO2 values, I would like to expand it to temperature and humidity.

(http://co2meters.com/Documentation/Manuals/Manual_GC_0024_0025_0026_Revised8.pdf)

#include <SoftwareSerial.h>

SoftwareSerial mySerial(12, 13); // RX, TX pins on Ardunio

int co2 =0;
double multiplier = 1;// 1 for 2% =20000 PPM, 10 for 20% = 200,000 PPM
uint8_t buffer[25];
uint8_t ind =0;
uint8_t index =0;

int fill_buffer();  // function prototypes here
int format_output();

void setup() {
  Serial.begin(9600);
  Serial.print("\n\n");
  Serial.println("             AN128 Ardunio to Cozir CO2 Sensor - Demonstration code 11/29/2017\n\n");
  mySerial.begin(9600); // Start serial communications with sensor

  // mySerial.println("G");

  pinMode(4, OUTPUT); //heating pad pin
  pinMode(3, OUTPUT); //heating pad pin
  pinMode(5, OUTPUT); //solenoid valve pin
  digitalWrite(4, LOW); //change between HIGH or LOW value to make the valve/heating pads turn on/off
  digitalWrite(3, LOW);
  digitalWrite(5, LOW);

  //mySerial.println("K 0");  // Set Command mode
  // mySerial.println("M 6"); // send Mode for Z and z outputs
  // "Z xxxxx z xxxxx" (CO2 filtered and unfiltered)
  //delay(20);

  mySerial.println("K 1");  // set streaming mode

}

void loop() {

  // Serial.println(" Hello World ");
  fill_buffer();  // function call that reads CO2 sensor and fills buffer

   Serial.print("Buffer contains: ");
  for(int j=0; j<ind; j++)Serial.print(buffer[j],HEX);
  index = 0;
  format_output();
   Serial.print(" Raw PPM        ");

   index = 8;  // In ASCII buffer, filtered value is offset from raw by 8 bytes
   format_output();
   Serial.println(" Filtered PPM\n\n");
}

int fill_buffer(void){

// Fill buffer with sensor ascii data
ind = 0;
while(buffer[ind-1] != 0x0A){  // Read sensor and fill buffer up to 0XA = CR
  if(mySerial.available()){
    buffer[ind] = mySerial.read();
    ind++;
     // Serial.println("Fill loop");
    }
     //Serial.println("Fill loop");
  }
  // buffer() now filled with sensor ascii data
  // ind contains the number of characters loaded into buffer up to 0xA =  CR
  ind = ind -2; // decrement buffer to exactly match last numerical character
  }

 int format_output(void){ // read buffer, extract 6 ASCII chars, convert to PPM and print
   co2 = buffer[15-index]-0x30;
  co2 = co2+((buffer[14-index]-0x30)*10);
  co2 +=(buffer[13-index]-0x30)*100;
  co2 +=(buffer[12-index]-0x30)*1000;
  co2 +=(buffer[11-index]-0x30)*10000;
  Serial.print("\n CO2 = ");
  Serial.print(co2*multiplier,0);
// Serial.print(" PPM,");
//    Serial.print("\n");
   delay(200);
 }


texts: DHT 11 temp. And hum. Sensor always 0 values

texts:
I am trying to get my DHT 11 from the official arduino store to work (https://store.arduino.cc/grove-temperature-humidity-sensor).

I am following this guide right here:
http://wiki.seeedstudio.com/Grove-TemperatureAndHumidity_Sensor/

But I'm only getting invalid output of 0 humidity and 0 degrees.

I hope the image helps in identifying my problem.

On a side note, my sensor looks like a part is missing which is very strange and makes me doubt the right product was sent to me.

Some more information:
- Black to GND
- Red to 5v
- White is wmpty
- Yellow to d2
- Using an arduino Uno
- Output does not change whether the sensor is actually connect or not.
- Total noob at this.

Help would be appreciated a lot!


texts: Auto acknowledge failed with nRF 24L01+ and Arduino

texts:
My transceivers are running fine. I've written a few code and got them running. Then I decided to check the auto acknowledgement feature wherein we can return data back to the sender WITHOUT manually changing the radio modes on both units. But I find that the serial monitor always shows "failed to transmit". Why is this happening, because otherwise they work fine?

I am using maniacbug's RF24master library.

The Tx code is:

#include<SPI.h>
#include<nRF24L01.h>
#include<RF24.h>

int msg[1] = {1};
int rec[1] = {0};
bool stat = true;
RF24 radio(9,10);
const uint64_t pipe[1] = {0xF0F0F0F0E1LL};

void setup()
{
  Serial.begin(57600);
  radio.begin();
  delay(1000);
  radio.setAutoAck(true);
  radio.enableAckPayload();
  radio.openWritingPipe(pipe[0]);
  radio.setRetries(15,15);
 }
void loop()
{
  if(stat)
  {
    radio.stopListening();
    bool ok = radio.write(msg,sizeof(msg));
    delay(100);
    if(ok)
    {Serial.println("transmitted successfully !!");}
    else
    {Serial.println("faileed to transmit");}
    msg[1]++;
    if(msg[1]>=200)
    {msg[1]=1;}
    stat = false;
    //delay(20);
  }
  if(!stat)
  {
    if(radio.isAckPayloadAvailable())
    {
      radio.read(rec,sizeof(rec));
      Serial.print("received ack payload is : ");
      Serial.println(rec[1]);
      stat = true;
    }
  }

}

and the Rx part is:

#include<SPI.h>
#include<nRF24L01.h>
#include<RF24.h>
const uint64_t pipe = 0xF0F0F0F0E1LL;
RF24 radio(9,10);
int rec[1] = {0};
int ack[1] = {1};
void setup()
{
  Serial.begin(57600);
  radio.begin();
  delay(100);
  radio.setAutoAck(true);
  radio.enableAckPayload();
  radio.openReadingPipe(1,pipe);
  radio.startListening();
  radio.setRetries(15,15);
}
void loop()
{
  if(radio.available())
  {
    Serial.println("payload available....");
    bool ok = radio.read(rec,sizeof(rec));
    if(ok)
    {
        Serial.println("message received !!");
        Serial.print("integer got is : ");
        Serial.println(rec[1]);
        radio.writeAckPayload(1,ack,sizeof(ack));
    }
    else
    {Serial.println("failed to receive the message");}
  }
}


texts: Why is my INA219 current sensor gives a negative currentmA and Shunt voltage?  My sensor is connected in a glucose test strip connector. The current is from a glucose biosensor? Is it possible that my INA219 is damaged?


texts: can we use TCRT5000 sensor instead of IR proximity sensor?

texts:
I am planning to make a human following robot which requires two IR proximity sensors.
I already have two TCRT5000 sensor. Can I use it instead of it?


texts: ESP32 Alexa Integration; Cannot correctly control more than one device

texts:
I created a garage door opener recently that is controllable through Alexa, using this library: https://github.com/Aircoookie/Espalexa

Everything is operating as expected, meaning I was able to detect my device and control the garage (using routines).

The issue came when I went to integrate Alexa into another previously completed/operational project. I was able to successfully discover and control the second board, kind of.

At this point I have added two ESP32 boards to Alexa, named differently of course. When I went to test the second board(meaning that it was successully discovered, and the ESP was receiving most commands) I noticed that Alexa was also opening my garage. If i unplugged my garage door opener(first board to be added) the second board starts to all receive commands, although degraded; for example;

In the above noted library Alexa should be able to control 'brightness' of dimmable lights. Of course this device is not a dimmable light but for the purposes of the integration, this library emulates smart lights. I am never able to see Alexa trying to set a brightness whose value is not 0.

Example, this is successfully executed on board 2, sometimes only when board 1 is unplugged:

void alexa_change_hdmi(EspalexaDevice* d) {
    Serial.println("Executing");
    uint8_t brightness = d->getValue();
    Serial.println(brightness);
    doing more things....

Here, brightness is always printed as 0.

So, after I added board X to alexa and tested successfully, I added board Y to alexa. Board X receives both commands for X and Y most of the time. Vice versa if board Y is the only device on. This is not intended by design. I would like to control them separately(preferably through the use of one alexa device).

I'm not sure if this (^) is related to the inability of Alexa to tell the two distinct board apart. I'm not sure why i'm not getting a brightness level, I would like to use it to make decisions, example;

if (brightness == '2.55') {
unsigned int irSignal[] = {9000, 4450, 600, 550, 550, 550, 600, 550, 550, 550, 600, 500, 600, 550, 550, 600, 550, 550, 600, 1650, 550, 1700, 550, 1700, 550, 1700, 550, 1700, 550, 1700, 550, 1650, 600, 1650, 550, 1700, 550, 550, 600, 550, 550, 1700, 550, 550, 600, 500, 600, 550, 550, 600, 550, 550, 600, 1650, 550, 1700, 550, 550, 600, 1650, 550, 1700, 550, 1700, 550, 1700, 550}; // NEC FF906F
irsend.sendRaw(irSignal, sizeof(irSignal) / sizeof(irSignal[0]), khz);
}

Has anyone seen this issue integrating several ESP32 devices with one Amazon Echo? Has anyone ever gotten brightness to successfully pass into the function that alexa triggers?

EDIT*

After doing some more testing it appears that ESPALEXAWITHASYNCWEBSERVER is causing Alexa to not be able to differentiate between the distinct boards. This implies that if you want to use more than one device with this library, you cannot use the async example.

As a side effect, brightness always returns 0 when not using the async library, meaning you can really only use this library to control on and off state, not brightness, if you have more than one ESP device. ASYNC example correctly returns brightness, all other examples return 0, no matter what you set the brightness to.


texts: Why am I getting "expected primary-expression before '.' token"?

texts:
I know this is a common question but the truth is every code is different. Sometimes it's hard to apply the concept to your code, it does not work. So please help me. What is wrong with this code? I got it from GitHub. I'm trying to compile it first before I can do a little modification, it sends temp and humidity data to ThingSpeak cloud servers.

#include <DHT.h>  // Including library for dht
#include <ESP8266WiFi.h>

String api_key = "YOUR API KEY"; // Enter your Write API key from ThingSpeak
const char *ssid = "YOUR WIFI SSID"; // replace with your wifi ssid and wpa2 key
const char *pass = "YOUR WIFI PASSWORD";
const char* server = "api.thingspeak.com";

#define DHTPIN 1 // pin where the dht11 is connected
DHT dht;

WiFiClient client;

void setup() {
  Serial.begin(115200);
  delay(10);
  pinMode(2, OUTPUT);
  digitalWrite(2, 0);
  Serial.println("Connecting to ");
  Serial.println(ssid);
  WiFi.begin(ssid, pass);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
}

void loop() {
  int chk = DHT.read(DHTPIN);
  float hum = DHT.humidity;
  float temp = DHT.temperature;
  if (isnan(hum) || isnan(temp)) {
    Serial.println("Failed to read from DHT sensor!");
    return;
  }
  if (client.connect(server, 80)) {
    // "184.106.153.149" or api.thingspeak.com
    String data_to_send = api_key;
    data_to_send += "&field1=";
    data_to_send += hum;
    data_to_send += "&field2=";
    data_to_send += temp;
    data_to_send += "\r\n\r\n";
    client.print("POST /update HTTP/1.1\n");
    client.print("Host: api.thingspeak.com\n");
    client.print("Connection: close\n");
    client.print("X-THINGSPEAKAPIKEY: " + api_key + "\n");
    client.print("Content-Type: application/x-www-form-
    urlencoded\n");
    client.print("Content-Length: ");
    client.print(data_to_send.length());
    client.print("\n\n");
    client.print(data_to_send);
    delay(1000);
    Serial.print("Temperature: ");
    Serial.print(temp);
    Serial.print(" degrees Celcius, Humidity: ");
    Serial.print(hum);
    Serial.println("%. Send to Thingspeak.");
  }
  client.stop();
  Serial.println("Waiting...");
  // ThingSpeak needs minimum 15 sec delay between updates, I've set it to 30 seconds
  delay(10000);
}

When I compile I get this error,

  Arduino: 1.8.10 (Windows 10), Board: "NodeMCU 1.0 (ESP-12E
  Module), 80 MHz, Flash,
  Legacy (new can return nullptr), All SSL ciphers (most
  compatible),
 4MB (FS:2MB OTA:~1019KB), 2, v2 Lower Memory, Disabled, None, Only Sketch, 115200"

    C:\Users\Agent 96\Desktop\thingspeak\thingspeak.ino: In function 'void loop()':

   thingspeak:37:20: error: expected primary-expression before '.' token

  int chk = DHT.read(DHTPIN);

                ^

  thingspeak:38:22: error: expected primary-expression before '.' token

  float hum = DHT.humidity;

                  ^

  thingspeak:39:23: error: expected primary-expression before '.' token

  float temp = DHT.temperature;

                   ^

  Multiple libraries were found for "DHT.h"
  Used: C:\Users\Agent
  Not used: C:\Users\Agent
  Multiple libraries were found for "ESP8266WiFi.h"
  Used: C:\Users\Agent
  exit status 1
  expected primary-expression before '.' token

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

Please help, I'm kind of a beginner.


texts: what is the difference between providing 7 volts or 12 volts to arduino uno?

texts:
according to this the recommended input voltage is between 7 and 12 volts.
The question is what is the difference between providing 7 volts(minimum recommended volts) and 12 volts(maximum recommended volts) ?.


texts: Can data be stored in program storage space instead of dynamic memory?

texts:
I'm declaring an array at top level like so:
constexpr byte a[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; // whatever data
I'm referencing the array in such a way that it's not optimized away. When compiling this from the Arduino IDE it informs me that it's using 1474 bytes of program storage space and 194 of dynamic memory. Curiously enough if my array is twice the size (20 elements) there are 10 more bytes of both program storage and dynamic memory used (1484 and 204 respectively).
Can I convince the compiler somehow to store all this in program storage space only? Any qualifiers or options I should be using instead? (and why would it take up space in both memory spaces anyway?!)
I'm using an arduino uno.


texts:
Recently I bought a B006RATC2E wireless shield for my Arduino One, but didn't notice that I had to buy a wifi module as well to let it work (bad surprise as the shield already cost me $30 + travel expenses to CR). Could someone be so kind to suggest me some compatible wifi modules for the shield?

I'm kind of newbie in this and when I search specs for Adafruit and XBee modules, the documentation is not explicit about the compatibility with Arduino shields, so I'm stuck.

I don't want to buy components that would't work together (my budget is limited). Is XBee XB24 a good module for the shield? Any other alternative?

Thanks in advance for any help!


texts: Arduino Nano not recognized on Windows 10

texts:
For some weeks my latest dozen of Nano's isn't recognized any more by Win 10 computer: After two days of experiments I have suspicions:

Is there any change in Win10 since all Arduinos now are only shown in "Hidden devices" in the device manager? However, my old Uno and also an old Nano are still working despite of that... (The old nano has a chip named CH340G on the downside; the new nano's chip has no name at all).
The Nanos I'm trying to program now I got from China (order date 26 sep 2019) and they are said to be compatible with CH340SER. In fact I have programmed several of them early this year - turning back to them in October, upload was no longer possible.
In the meantime, I have switched from Arduino IDE 1.8.6 to 1.8.13 - however, I guess this is not the reason for my troubles since not even Windows recognizes the device when I plug it in...
Any advices to this problem?
Dieter


texts:
I'm working on a project which needs better audio quality than just a piezo buzzer, so I went out and bought a pair of used cheap speakers for $3. It turns out that they have RCA audio inputs rather than 3.5mm inputs. There is a separated left and right speaker, with a left and right RCA audio wire coming out of each.

I've looked around on the internet about connecting speakers to Arduino, but I've only found ways to connect 3.5mm/TRRS to Arduino, or the RCA video jack to Arduino, but not the RCA audio.

How should I go about wiring the RCA audio wires to my Arduino Uno so that I can play basic melodies off it? Are any amplifier circuits, voltage dividers, etc. needed?

I am okay with splicing the cables.

Thanks


texts: How can one close a tab in the Arduino IDE? There is a Tab button (little triangle) with the Option "Delete"(kind of misleading term). There is no "Close" option. And the "Delete" option doesnt do the job for me either, because the tabs are write-protected, and I just get a prompt.


texts: How to change wifi credentials of multiple ESP8266 together

texts:
I need to change WiFi credentials of multiple ESP8266 in one go, without needing to change passwords for each of them individually. I know there is a WiFiManager library, which makes your ESP8266 access point when not connected to any network, but that will require me configure each of them individually.

How can I save the fatigue of changing their wifi credentials individually? All of them needs to connect to the same network, whose password is recently changed.


texts: Can I use a PIR sensor to turn on an arduino?

texts:
I'd like to use a PIR sensor (HC-SR501) to control the power to an Arduino Uno. Note that I'm not talking about using a PIR sensor as input to the Arduino and sensing the output pin from the PIR, I'm talking about using the output pin from the PIR to turn the Arduino itself on and off.

Hooking it up directly doesn't seem to work as I'm guessing the PIR doesn't handle that much current output. Would I use a transistor of some kind to do this?

My reason for wanting to do this is simple, power preservation. The PIR uses so little current when it doesn't sense anything that I thought it would be nice for something like a mailbox sensor that doesn't need to run that often. Thanks.


texts: i am working on rfid module and the module is not detecting sny of the cards

texts:
i am working on uno.
i am using mfrc522.
the module is not detecting aby of the cards. nothing is poping up on the screen.
this is the code-
#include <deprecated.h>
#include <MFRC522.h>
#include <MFRC522Extended.h>
#include <require_cpp11.h>

// RFID door access system.

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

#define SS_PIN 10
#define RST_PIN 9
#define LED_G 5 //define green LED pin
#define LED_R 4 //define red LED
#define BUZZER 2 //buzzer pin
MFRC522 mfrc522(SS_PIN, RST_PIN);   // Create MFRC522 instance.
Servo myServo; //define servo name

void setup()
{
  Serial.begin(9600);   // Initiate a serial communication
  SPI.begin();      // Initiate  SPI bus
  mfrc522.PCD_Init();   // Initiate MFRC522
  myServo.attach(3); //servo pin
  myServo.write(0); //servo start position
  pinMode(LED_G, OUTPUT);
  pinMode(LED_R, OUTPUT);
  pinMode(BUZZER, OUTPUT);
  noTone(BUZZER);
  Serial.println("Put your card to the reader...");
  Serial.println();

}
void loop()
{
  // Look for new cards
  if ( ! mfrc522.PICC_IsNewCardPresent())
  {
    return;
  }
  // Select one of the cards
  if ( ! mfrc522.PICC_ReadCardSerial())
  {
    return;
  }
  //Show UID on serial monitor
  Serial.print("UID tag :");
  String content= "";
  byte letter;
  for (byte i = 0; i < mfrc522.uid.size; i++)
  {
     Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
     Serial.print(mfrc522.uid.uidByte[i], HEX);
     content.concat(String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " "));
     content.concat(String(mfrc522.uid.uidByte[i], HEX));
  }
  Serial.println();
  Serial.print("Message : ");
  content.toUpperCase();
  if (content.substring(1) == "76 2B E3 93") //change here the UID of the card/cards that you want to give access
  {
    Serial.println("Authorized access");
    Serial.println();
    delay(500);
    digitalWrite(LED_G, HIGH);
    tone(BUZZER, 500);
    delay(300);
    noTone(BUZZER);
    myServo.write(180);
    delay(5000);
    myServo.write(0);
    digitalWrite(LED_G, LOW);
  }

 else   {
    Serial.println(" Access denied");
    digitalWrite(LED_R, HIGH);
    tone(BUZZER, 300);
    delay(1000);
    digitalWrite(LED_R, LOW);
    noTone(BUZZER);
  }
}

please help me


texts:
This is my first programme, which is to control a brushless ESC motor and an IR sensor to read the props' RPM. However I can't seem to figure out why it's not working. The reading keeps giving me 0, and after I edited the programme by changing while (millis()-start < 60000);to while (millis()-start < 1000);, it feeds me expected ';' before '{' token on if (start > millis(){, which makes no sense whatsoever. Here's the programme:

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Servo.h>

//Display&sensor
#define Backlight_Pin 13
int initial=0;
//int REV=0;
//int prevtime=0;
LiquidCrystal_I2C lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);

//ESC
Servo ESC;     // create servo object to control the ESC
int potValue;  // value from the analog pin

//Calculation
int sensorvalue;
int state1 = HIGH;
int state2;
float rps;
float rpm;
long prevMillis = 0;
long interval = 200;
long currentTime;
long prevTime = 1;
long diffTime;
int sensorthreshold = 1;
int Sensor = 8;
int photoPin = 2;               //
int val = 0;
int valold = 0;
int start;
unsigned int count = 0;

void setup() {
  pinMode(Sensor,INPUT);
  valold = digitalRead(photoPin);
  lcd.begin(16, 2);
  lcd.clear();
  ESC.attach(9, 1000, 2000);
  Serial.begin(9600);
}
void loop() {
  if (initial==0)
  {
    lcd.setCursor (6,0);
    lcd.print("RPM:");
    lcd.setCursor (0,1);
    initial=1;
  }
  //REV= digitalRead(Sensor);
  //lcd.print(REV);

  //Calculation
 start = millis(); // take the start time
 count = 0; // reset couter
 // do the following loop for 60000ms = 1min
 while (millis()-start < 1000);
 {

    if (start > millis(){
      start = millis();
      count = 0;
    }
   val = digitalRead(photoPin);
   if (val==LOW)
   {
     digitalWrite(ledPin, LOW);
   }
   else
   {
     digitalWrite(ledPin, HIGH);
     if (val <> valold) {
       count ++;
       valold = val;
     }
   }
 }

      lcd.print("RPS = ");
      lcd.setCursor(7,1);
      lcd.print(count);
      delay(1000);
      lcd.setCursor(0,1);
      lcd.print(" ");

//ESC
  potValue = analogRead(A0);   // reads the value of the potentiometer (value between 0 and 1023)
  potValue = map(potValue, 0, 1023, 0, 180);   // scale it to use it with the servo library (value between 0 and 180)
  ESC.write(potValue);    // Send the signal to the ESC
}

And if I put ";" in front of "{", I get this error

  expected primary-expression before '{' token

How could I fix this? Any help is appreciated. Thanks!

p.s. I had a rig holding the sensor and rotor stationary and waited 5 minutes for results, no luck, so I thought I would change the time to 1 second and measure RPS, then manually time the result by 60, but then the code broke. I don't think it was hardware failure as almost all joints are soldered, and the wires are solid copper.


texts: Is there any arduino microphone that can record heart sound?

texts:
I'm currently undergoing a project where I record heart sound (mechanical response) and send it over bluetooth to an app.

However I'm finding it really hard to find an arduino microphone or just general microphone that can listen to heart sound.

Any guide would be highly appreciated.

Thanks


texts:
I am doing a project where I need to send some numbers between arduinos. But it has to be wirelessly because they will be moving. How to Communicate between arduinos wirelessly? I need to send data between them. Wifi would be preferred.

Thank You.


texts: Incompatible types in assignment of 'uint8_t {aka unsigned char}' to 'uint8_t [1] {aka unsigned char [1]}'

texts:
I'm trying to send custom data. But it doesn't seem to work. I can't find a way to parse my string to a unit8_t. I tried to follow other people's solutions but they don't seem to work for me.

// Declaration
uint8_t myData[] = "";

void loop(){
    myData = *(uint8_t*)atoi("custom string".c_str());
}

This is the error message that I keep getting:
Incompatible types in assignment of uint8_t {aka unsigned char}' to 'uint8_t [1] {aka unsigned char [1]} .


texts: I have a total of 15 sensors (analog and digital) connected to an arduino mega.  For my real-time control application, it's really really important that all data be collected simultaneously at regular intervals in time.  Is there any way to ensure that all data is collected at the same time?  How can I minimize the total lag time between the first and last sensors?


texts: Arduino pin 13 as PWM output, not possible?

texts:
I have noted on more than one occasion the comments in sketches "reserving pin 13 for future PWM backlight dimming of the LCD" while using Uno and Nano boards.
Am I missing something ?  I always considered it NOT possible as PWM output is only available on pins 3,5,6,9,10 and 11 on most boards.


texts: MPU6050 Measure distance traveled or position

texts:
How can I use MPU-6050 with an arduino to measure the distance the robot traveled from it's starting point or just it's current position on the map?

The Robot should be moving in a map same as a 2D array and I need to detect it's position while it is moving and send the data to a station.


texts: Arduino code for continuous rotation for 3 servos with Bluetooth

texts:
This code is working, any ideas?

Please check the code - Bluetooth is connecting but the servo motors are not varying with respect to the app sliders.

#include <SoftwareSerial.h>
#include <Servo.h>
Servo myservo1, myservo2, myservo3;

int bluetoothTx = 1;
int bluetoothRx = 0;

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

void setup()
{
  myservo1.attach(9);
  myservo2.attach(10);
  myservo3.attach(11);

  //Setup usb serial connection to computer
  Serial.begin(9600);

  //Setup Bluetooth serial connection to android
  bluetooth.begin(9600);
}

void loop()
{
  //Read from bluetooth and write to usb serial
  if (bluetooth.available() >= 2 )
  {
    unsigned int servopos = bluetooth.read();
    unsigned int servopos1 = bluetooth.read();
    unsigned int realservo = (servopos1 * 256) + servopos;
    Serial.println(realservo);

    if (realservo >= 1000 && realservo < 1360) {
      int servo1 = realservo;
      servo1 = map(servo1, 1000, 1360, 0, 360);
      myservo1.write(servo1);
      Serial.println("servo 1 ON");
      delay(10);
    }

    if (realservo >= 1000 && realservo < 1360) {
      int servo2 = realservo;
      servo2 = map(servo2, 1000, 1360, 0, 360);
      myservo2.write(servo2);
      Serial.println("servo 2 On");
      delay(10);
    }

    if (realservo >= 1000 && realservo < 1360) {
      int servo3 = realservo;
      servo3 = map(servo3, 1000, 1360, 0, 360);
      myservo3.write(servo3);
      Serial.println("servo 3 On");
      delay(10);
    }
  }
}


texts: Flash an ESC Through Serial USB without Arduino Interrupting the Signal

texts:
So I have four Electronic Speed Controllers (ESC's), each connected to a motor. I am building a drone with an Arduino UNO board as my flight controller. For convenience, I have soldered the signal wires on each of the four ESC's onto the bottom of the Arduino where the Arduino's pin headers are soldered on. The serial ground pins on the ESC's are soldered to the ground pins on the Arduino.

The ESC's I am using can be found here.

In order to change settings on my ESC's, I am trying to use this Turnigy USB linker to connected to the BLHeli software on my computer.
The linker has a signal and a ground wire for Serial Communication, as well as a positive wire (I think this is just to fit the connector on ESC's with a BEC, but mine are OPTO, and have none). To connect the USB Linker to an ESC, I should be able to plug it into appropriate female pin headers on the Arduino using some breadboard-type jumper cables.

At least that's what I thought...

Whenever I try to connect to an ESC with the BLHeli software, I get a message:
Please Connect ESC and power up or cycle power.

Earlier, I was able to make the connection and change the settings on my ESC's when they weren't connected to the Arduino board, but now that they are soldered and hot-glued on there, they won't work. So the question is: What is the Arduino doing to the Serial connection, and how can I fix it without desoldering my ESC's whenever I need to change some settings?

Now before you ask:

Yes, the ESC is powered up and connected to a motor. It gives me a happy beeping sound.
Yes, I definitely have the signal and ground wires connected correctly. I have been trying to figure this out for days, and have even tried switching them.
The Arduino is turned off when I try to connect an ESC to the USB Linker.
Only one ESC is powered on at a time.

Maybe the Arduino has some kind of protection circuit for the IC that is messing up the signal, or maybe the ESC's have something similar that's messing it up too, because some of the ground wires are connected together. I'm going to have a very difficult time figuring this out myself, so hopefully someone out there has an idea of what's going on.

Thanks for any help you have to offer.

-- Ember


texts: Olimexino 32u4: Wire.endTransmission() hangs

texts:
I'm trying to get a TAE5767 (FM radio) to work. According to this instructable I'm trying it on a 5V-Olimexino 32u4 (Leonardo-compatible) with following code (Arduino 1.6.3):

#include <Wire.h>

void setFrequency(float frequency) {
  unsigned int frequencyB = 4 * (frequency * 1000000 + 225000) / 32768;
  byte frequencyH = frequencyB >> 8;
  byte frequencyL = frequencyB & 0xFF;
  Wire.beginTransmission(0x60);

  Wire.write(frequencyH);
  Wire.write(frequencyL);
  Wire.write(0xB0);
  Wire.write(0x10);
  Wire.write(0x00);
  Serial.println("sending");
  Wire.endTransmission();
  Serial.println("sent");
}

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

  Wire.begin();
  setFrequency(89);
}

void loop() {
}

Unfortunately, it only prints

sending

First, I thought I'd damaged my chip, but I'm now using the second with the same result. I've also tried the I2C-Scanner from Nick Gammon, but it prints nothing. I've tried adding 2.2k resistors from SCL and SDA to 5V without success. Does someone has a clue what I can try?


texts: Reading and writing to GD25B32CPIG flash memory

texts:
I recently removed a GD25B32CPIG flash memory chip from a commercial coin-operated arcade game. Apparently it has all the game's sounds stored directly on the chip. I decided to see if I can learn to communicate with the chip to read the current data and write new data to it so that I can possibly change the game's sounds as the game itself doesn't have the ability to do that.
After searching online, I found schematics for the chip, including its functions and pinouts.

I've wired it up to my Arduino Uno's MOSI, MISO, CK, and SS pins as well as the 3.3V and GND for power. This is the only part I know is correct.
Unfortunately, I am lost on what to do next since I've never used the SPI library by itself (normally other libraries handle the SPI connections in my other projects). Nobody else has a tutorial on this particular chip and I'm a little bit lost by the datasheet's commands. I also did some research on SPI and found the tutorials to be a bit confusing.
I haven't tested anything because I don't want to alter the data unless I know what I'm doing.
The question:
Is there a way to read all data at once and write to a particular register?


texts: Controlling multiple 24V solenoids with Arduino

texts:
I'm building a pump for which I need 4 medium strength solenoids (20-50N). 24V is probably the minimum I will need to put through them, but this is something I need to test, once I've got them working. At 24V they draw 400mA.

I've found various posts with very useful info, especially https://playground.arduino.cc/Learning/SolenoidTutorial and https://forum.arduino.cc/index.php?topic=417030.0

Will the attached sketch below work for one? If so what resistance should R1 be?
And if so can you see any problems with hooking up 4 working at different intervals?

The power supply is an LRS-350-24RS, and the Mosfet has a max gate source voltage of 35V. The 5v-24v optocoupler is off ebay -  https://www.ebay.co.uk/itm/152904980799

Many thanks for your help!!


texts: Timer CTC Set and Clear modes -- How to un-Clear and un-Set?

texts:
Nick Gammon's cheatsheet for the Ardunino UNO's ATmega328P (below) shows some hints on the Clear Timer on Compare (CTC) modes of AVR chips.  Most of the examples for CTC mode I find use the COMxxx registers of 01 = toggle to control the OCxx pin, which would give a 50% duty cycle at 1/2 the frequency of the timer clearing.

My question is about using the non-toggling COMxxx modes of Clear and Set, which don't seem to provide an automatic way to reset into the opposite state, as in the PWM modes.

For example:

void setup() {
  // put your setup code here, to run once:

   // Timer 1 CTC mode Clearing OC1B at 0.25Hz using OCR1A to set frequency
   // Output on OC1B
   // Clear at OCR1B
   // WGM =15 0b0100

   DDRB |= bit(DDB5)| bit(DDB6);  // Teensy2.0 atmega32u OC1A and OC1B outputs
  // DDRB |= bit(DDB1)| bit(DDB2);  // atmega168/UNO OC1A and OC1B (Tested by OP/Luis)
   TCCR1A =  bit(COM1A0) | bit(COM1B1)  ; // Toggle OC1A, Clear on OC1B
   TCCR1B =  bit(WGM12)  | bit(CS12);  // Set /1 prescaler
   TCCR1C = 0;  // Note that it is good to initialize the timer
                // into a known mode before trying to set interesting TOPs
   OCR1A  = 62500U ;    // Set TOP count to 16000000/(PreScaler *Ftimer)
   OCR1B  = OCR1A/2;    //  ~50% duty cycle
   TCCR1A =  bit(COM1A0) | bit(COM1B1)  ; // Toggle OC1A, Clear on OC1B
   TCCR1B =  bit(WGM12)  | bit(CS12) | bit(CS10);  // Set /1024 prescaler
   TCNT1 = 0 ;
}

void loop() {
  // put your main code here, to run repeatedly:
  //OCR1B = 62500U/4-1; // 25% duty cycle.
}

If I try the above code, I get a 0.125Hz ( 8s period signal) on PB5 and a constant low on PB6.

What is the way to set OC1B high to be cleared by the timer match?  And similarly, vice versa: clearing OC1B to be set by the timer match?

Is there a direct way or do you fiddle with COM1Bx, trigger FOC1B, and then fiddle COM1B back?

This code uses the TCCR1C:FOC1B register to set the bit by messing with the TCCR1A:COM1Bx bits, but it seems awkward:

void setup() {
   // Timer 1 CTC mode Clearing OC1B at 0.25Hz using OCR1A to set frequency
   // Output on OC1B
   // Clear at OCR1B
   // WGM =15 0b0100

   DDRB |= bit(DDB5)| bit(DDB6);  // Teensy2.0 atmega32u OC1A and OC1B outputs
  // DDRB |= bit(DDB1)| bit(DDB2);  // atmega168/UNO OC1A and OC1B (Tested by OP/Luis)
   TCCR1A =  bit(COM1A0) | bit(COM1B1)  ; // Toggle OC1A, Clear on OC1B
   TCCR1B =  bit(WGM12)  | bit(CS12);  // Set /1 prescaler
   TCCR1C = 0;  // Note that it is good to initialize the timer
                // into a known mode before trying to set interesting TOPs
   OCR1A  = 62500U ;    // Set TOP count to 16000000/(PreScaler *Ftimer)
   OCR1B  = OCR1A/2;    //  ~50% duty cycle
   TCCR1A =  bit(COM1A0) | bit(COM1B1)  ; // Toggle OC1A, Clear on OC1B
   TCCR1B =  bit(WGM12)  | bit(CS12) | bit(CS10);  // Set /1024 prescaler
   TCNT1 = 0 ;
}

void loop() {
  int saveCOM;
  Serial.println(TCCR1A,BIN);
  delay(7000); // 7 seconds
  saveCOM = TCCR1A;
  TCCR1A |= bit(COM1B1) | bit(COM1B0) ; // config for set OC1B
  TCCR1C = bit(FOC1B); // force a compare to set bit
  TCCR1A = saveCOM ; // restore mode
}

This code has the 0.125Hz on OC1A, and a semi-random series of 1-4 second long pulses on OC1B.

I was interested in playing with the CTC modes for doing long cycle/low frequency PWM.  With the normal PWMs you could range from a 1-bit 50% PWM at 8MHz to a 16 bit PWM at a frequency of 0.119Hz (8.388s)  With the CTC modes, if you could manage the sets and clears in an TIMERx_OVF_vect with a couple 16 bit registers, you could extend it to 32 bits of PWM resolution with a period up to 152 hours.


texts: how to move my robot to the assigned coordinates

texts: I am working on an ground surveillance robot using an Arduino mega for programming, am using components like the HMC5883L compass, Adafruit GPS for assigning of coordinates (latitude and longitude) which are the way points, I have written up the code for both the compass and the GPS and am able to get information from them, but now what I want for my robot to move to those specified coordinates (latitude and longitude waypoints) which I don't know how to do please do pardon me for asking such question cause I am new to coding GPS and compass and I would appreciate it if anyone could help me out or explain a bit in details what I need to do please find my code here http://textuploader.com/drqwv


texts: What component can I use with an Arduino to measure the capacitance of objects?

texts: What component can I use with an Arduino to measure the capacitance of objects like a glass bottle or a roll of paper?


texts: Voltage meter ADC + serial: Bytes lost during communication

texts:
I want to make a simple digital voltage monitor. So I have a sketch:

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

void loop() {
  int val = analogRead(A4);     // read the input pin
  val = 1;
  byte buf[4];
  buf[0] = 0;
  buf[1] = 0;
  buf[2] = val & 255;
  buf[3] = (val >> 8) & 255;
  Serial.write(buf, 4);             // report voltage value
}

When I tried to read serial buffer on PC host, I noticed that sometimes 1 byte can be lost, which lead to shifts and headache. How should the streaming be done?

PS.

host os: win7 x64;
language: c/c++
com port library: CSerial

Loop is as follows:

typedef int32_t sample_t;
while (true) {
    int nBytesRead = serial.ReadData(lpBuffer, bufSize * sizeof(sample_t));
    size_t numRead = nBytesRead / sizeof(sample_t);
    if (numRead > 0)
        std::cout << "read: " << numRead << " samples\n"; // Calculate average here!
}


texts:
Could someone give me some advice related to building a menu for a 128x64 LCD using 5 pushButtons?
i have 5 screens.
btn1 is for display MainMenu and Selection.
btn2 and btn3 is for up and down scrolling
btn 4 and btn4 is for switching on/off and increase decrease values.

the problem which i encounter is related to btn2 and btn3.
i don;t know how to use them for scrolling in in another screen except screen1 (MainMenu).

#include "U8glib.h"
U8GLIB_ST7920_128X64_1X u8g(13,12,11); //Enable, RW, RS, RESET

int selectionButton = A1, selectionButtonState, selectionButtonLastState = 0, cntSelectionButtonPressed = 0, cntSelectionButtonPressed2ForMenu2 = 0;
int menuButton = A0, menuButtonState, menuButtonLastState = 0;
int scrollDownButton = A3, scrollDownButtonState, scrollDownButtonLastState = 0;
  boolean mainMenu = false;

void setup()
{
    Serial.begin(9600);
    if ( u8g.getMode() == U8G_MODE_R3G3B2 )
    u8g.setColorIndex(255);     // white
    else if ( u8g.getMode() == U8G_MODE_GRAY2BIT )
    u8g.setColorIndex(3);         // max intensity
    else if ( u8g.getMode() == U8G_MODE_BW )
    pinMode(selectionButton,INPUT);
    pinMode(menuButton,INPUT);
    pinMode(scrollDownButton,INPUT);

}

void loop()
{

 scrollDownButtonState = digitalRead(A3);
 selectionButton = digitalRead(A1);
 menuButton = digitalRead(A0);

//pin A1 = RiGHT
 if(selectionButton != selectionButtonLastState)
 {
  if(digitalRead(A1) == HIGH)
  {
    cntSelectionButtonPressed += 1;
    if(cntSelectionButtonPressed == 4)
    {
      cntSelectionButtonPressed = 0;
    }
  }
  selectionButtonLastState = selectionButton;
 }

////////////////////////
 if(menuButton != menuButtonLastState)
  {
    if(cntSelectionButtonPressed == 1 && digitalRead(A0) == HIGH)
    {
         cntSelectionButtonPressed2ForMenu2 += 1;
    }
      if(cntSelectionButtonPressed2ForMenu2 == 4)
      {
        cntSelectionButtonPressed2ForMenu2 = 0;
      }
       u8g.firstPage();
       do{
           Menu2();
         }while(u8g.nextPage());

       menuButtonLastState = menuButton;
  }
 else
 {
 u8g.firstPage();
  do{
    MainMenu();
  }while(u8g.nextPage());
 }

}

void MainMenu(){
switch(cntSelectionButtonPressed)
{

  case 1:
           u8g.setFont(u8g_font_6x13);
           u8g.setPrintPos(15,15);
           u8g.print("> Ceas");
           u8g.setPrintPos(15,25);
           u8g.print("  Interior casa");
           u8g.setPrintPos(15,35);
           u8g.print("  Exterior casa");
           break;
  case 2:
           u8g.setFont(u8g_font_6x13);
           u8g.setPrintPos(15,15);
           u8g.print("  Ceas");
           u8g.setPrintPos(15,25);
           u8g.print("> Interior casa");
           u8g.setPrintPos(15,35);
           u8g.print("  Exterior casa");
           break;
           break;
  case 3:
           u8g.setFont(u8g_font_6x13);
           u8g.setPrintPos(15,15);
           u8g.print("  Ceas");
           u8g.setPrintPos(15,25);
           u8g.print("  Interior casa");
           u8g.setPrintPos(15,35);
           u8g.print("> Exterior casa");
           break;
}
}

void Menu2()
{

  switch(cntSelectionButtonPressed2ForMenu2)
{
  case 1:
           u8g.setFont(u8g_font_6x13);
           u8g.setPrintPos(15,15);
           u8g.print("> Stil1");
           u8g.setPrintPos(15,25);
           u8g.print("  Stil2");
           u8g.setPrintPos(15,35);
           u8g.print("  Stil3");
           break;
  case 2:
           u8g.setFont(u8g_font_6x13);
           u8g.setPrintPos(15,15);
           u8g.print("  Stil1");
           u8g.setPrintPos(15,25);
           u8g.print("> Stil2");
           u8g.setPrintPos(15,35);
           u8g.print("  Stil3");
           break;
           break;
  case 3:
           u8g.setFont(u8g_font_6x13);
           u8g.setPrintPos(15,15);
           u8g.print("  Stil1");
           u8g.setPrintPos(15,25);
           u8g.print("  Stil2");
           u8g.setPrintPos(15,35);
           u8g.print("> Stil3");
           break;
}
}


texts: how to use arduino to detect an 8Mhz ultrasonic pulse using piezo disc as receiver?

texts: i need a code to detect an 8MHz ultrasonic pulse and show its properties eg wave pattern and amplitude on serial plotter( like an oscilloscope)


texts: I have made a Nano send 4 pot values to an Uno please help with code

texts:
Happy New Year!
So I have made a Nano send 4 pot values to an Arduino Uno over serial but I have a problem: I don't know how to separate these values. Here's the code:
Master:
    int Pot = A0;
    int Pot2 = A1;
    int Pot3 = A2;
    int Pot4 = A3;

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

    void loop() {
      int Value = analogRead(Pot);
      int Value2 = analogRead(Pot2);
      int Value3 = analogRead(Pot3);
      int Value4 = analogRead(Pot4);
      Serial.write(Value); //Write the serial data
      Serial.write(Value2); //Write the serial data
      Serial.write(Value3); //Write the serial data
      Serial.write(Value4); //Write the serial data
      delay(150);
    }

Slave:
    int incomingByte; // for incoming serial data

    void setup() {
      Serial.begin(115200); // opens serial port, sets data rate to 9600 bps
    }

    void loop() {
      // send data only when you receive data:
      if (Serial.available() > 0) {
        // read the incoming byte:
        incomingByte = Serial.read();

        // say what you got:
        Serial.print("I received: ");
        Serial.println(incomingByte, DEC);
      }
    }

And a bit from the serial logs:

    I received: 255
    I received: 247
    I received: 11
    I received: 0

It updates and sends these four values for the four pots, it can read them but they are together, and it sometimes also kind of lags if I can say it like that; it sometimes takes longer to update but then it goes to normal again.
Thanks!


texts:
Does anyone know of a library that works with the WiFly-RN171?
I've tried all that I could find (WiFly, WiFlyHQ and WiFlySerial) but none of them work.

WiFly and WiFlySerial both hang on WiFly.begin().

WiFlyHQ fails to enter command mode and hence proceeds no further.

I'm using the WiFly-RN171 with an Arduino Uno and Communication Shield (XBee, Bluetooth, RFID) - XBee Shield as seen below.

Has anybody gotten this configuration to work?


texts: How to connect 3 MPU9250 to Node Mcu together?

texts:
I don't know how to connect 3 MPU9250 together on Node Mcu. There is not much information available. I am using bolder flight library for imu sensor - https://github.com/bolderflight/MPU9250

Can anyone post the image of connection on sensor and example of code? Thanks a lot.


texts:
I am having this problem when trying to compile my sketch. I am using RF frequency modules to send data between devices and a servo motor to control the tilt of a ramp. I understand that both libraries use TIMER 1 but I am unsure how to change one of them to use TIMER 2 thanks.

Arduino: 1.8.7 (Windows 10), Board: "Arduino/Genuino Uno"

libraries\Servo\avr\Servo.cpp.o (symbol from plugin): In function `ServoCount':

(.text+0x0): multiple definition of `__vector_11'

libraries\RadioHead\RH_ASK.cpp.o (symbol from plugin):(.text+0x0): first defined here

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino/Genuino Uno.
Board at COM4 is not available

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


texts: Do addressable RGB's need to be programmed differently from normal RGB's?

texts:
I bought these rgb's from Sparkfun, however I have no idea how to hook them up or how to program them. Obviously the data sheet was somewhat helpful, however I have no idea how the IC's in the LED's work themselves or how to control them separately, or even how to string them together. My best guess is currently going for what the led's appear as in the example picture by connecting the first and last pins and putting the respective Vcc and ground pins to Vcc and ground.

Is there any good examples for hooking these up and coding them, or a basic understandable explanation for how they work?

Thanks, I can't find a great resource yet.


texts: Is replacing USB serial WITH ESP8266+ESP link feasible?

texts:
ESP8266 (01-512k,) Arduino Uno (clone), Arduino IDE, Python 2.7.6 on Macbook pro running OSX 10.10.4 64-bit.

Hello!

I'm using a motion sensor with the following setup:

Arduino Uno+motion sensor >>>sensor values>>>USB Serial>>>Laptop running Python code>>>Notification>>>WiFi>>>Web

The sensor generates a value. The value is displayed on the serial monitor. The python program is triggered into action by a specific value appearing on the serial monitor and the program sends an email notification.

I would like to replace that setup with the following:

Arduino Uno+motion sensor>>>sensor values>>>ESP8266 as transparent WiFi to Serial bridge>>>Laptop running Python code>>>Notification>>>WiFi>>>Web

Essentially, I want to get rid of the USB cable and use the ESP8266 as a transparent WiFi to Serial bridge. Of course, a battery would power the Arduino and ESP8266.

I read this post  and the Jeelabs/ ESP Link Readme. It seems that the ESP8266, once flashed with ESP Link, could replace a serial cable. But, can ESP Link replace the USB Serial in my current setup? If so, are there tutorials explaining how this can be done?

I did some further reading and researched the matter but so far I only found one use case similar to what I want to do. In the said use case, a virtual serial connection through WiFi was being executed via a server within the ESP8266. Unfortunately, there were no detailed explanations on how this was achieved and I don't think this would be suitable for my specific use.

Please let me know if further information or clarification is needed.


texts: External vs arduino power supply for servo motors?

texts:
I recently created a project that involves the control of three SG90 servo motors. I started off by controlling this through the 5V output pin of the Arduino Uno, with the Arduino powered through the barrel plug with a 9V mains power supply.

However, the servos couldn't perform the full 180° sweep, it would appear to be due to the high torque at the end of the motion for my application.

I then switched to powering the servos separately to the Arduino using four AA batteries in series. I now had no issues with the servos stalling and could perform the full sweep.

I am not sure why this is though?

Four AAs in series will result in 6V, which is not that different to the 5V Arduino output pin? And it seems the current is the issue with servo stalling? and surely the number of batteries makes no difference to this as connected in series it stays the same? Is the current of the AA battery just higher than the 5V Arduino output pin?

Any help would be greatly appreciated, I'd really like to have a better understanding of this.


texts: How do I make Arduino IDE use a specific version of GCC in Debian?

texts:
Using Raspbian Stretch.

I installed gcc-4.9 with specified version. Then I installed arduino (2.1.0.5) which in turn pulled gcc 4.6. When I try to compile Marlin in it, it says

  Marlin requires C++11 support (gcc >= 4.7, Arduino IDE >= 1.6.8).
  Please upgrade your toolchain.

How do I make Arduino IDE use the correct version of GCC?


texts: Is it possible to accept multiple web requests at once?

texts:
I have an Arduino with ethernet shield and there are 8 different URLs that can be called to perform different actions.

The program loads and runs as expected for the most part, but, if it is busy doing an action, it won't accept the next one until the current action has finished.

Basically, the code's main loop listens for a client connection, then has a bunch of ifs that look in the URL that was called (for a query string) and then process the command.

I have looked at a few answers on here, but none deal with listening to HTTP requests. One recommended a library, but, I couldn't quickly get it to compile, and the other answer recommended a state machine - I do like this approach, however, I haven't had time to implement and it doesn't "feel" right as the listening for a HTTP request works on a if(client) basis.

I was wondering if anyone has done this before and/or has any advice?


texts: How to receive commands to a running arduino program from a raspberry pi?

texts:
I have looked all over for a solution to this. I'm a noob in the arduino space and am really just getting my feet wet. It's possible that I am interpreting what I am reading wrongly. If so I apologize. Here is my problem/question. I want to create an autonomous driving small land drone. It would connect to some drive sensors, dc motors and do some stuff all by itself. In addition to this I want a raspberry pi with a camera surveying the scenery. Because it is unknown if/when the raspberry PI will see something that is interesting i want this default behavior to occur. The reason I want to do it like this is that I read it is better performance to drive from the Arduino because a linux based computer has so much stuff running on it there could be more lag in the response. In addition the python program will be making HTTP requests, doing image processing, and potentially doing even more. If the image processing software on the PI picks up something interesting then I want this functionality to override the Arduino default program. I was thinking to create a program in Arduino for the basic drive functionality but then be listening to a python process that is running on the PI. If it hears a command to go do something, then of course it will drop the default program, go complete the python generated task and once it is done then it will continue with the arduino default program.
How do I in effect listen to a python process from the Arduino? Or would the proper solution be to not even use the Arduino but drive it all from python on the PI? Any suggestions for how to solve this would be great to hear. I feel like there is an obvious best practice way to do this that I am not aware of. Thanks in advance!


texts:
Something happened to my mega2650 as I was experimenting the other day.  It no longer turned on when powering from the 2.1mm jack or from Vin, regardless of the voltage applied.  A plastic bubble had formed on the 5V regulator, I assumed I had shorted something and fried it.  If I applied 5V to the 5V pin everything worked fine.  It also works fine when powered from USB.  So I replaced the 5V regulator with a NCP1117 version.  But I have the same situation.  If I apply voltage directly to the 5V regulator input pin I get 5V on the output pin and everything is fine.  I tested up to 12V and it is dead on at 5V.  I also checked the PNP switching transistor, and found it was working correctly.  As far as I can tell, the only thing remaining is that the trace is severed somewhere between just after the Vin pin and the 5V regulator, maybe the regulator input is not soldered well to the trace?  But this was one of the better solder joints I made, so I thought.  Any other ideas as to the root cause?

Thanks


texts:
I am trying to create a wireless remote control to control a servo motor via Bluetooth. What all do I need to establish this? I did some research and found the following:

Tinyduino

Bluetooth low energy shield

Would these be enough (in addition to the servo motor) to establish my needs? Any advice on how I would go about coding this? I can research on the specifics but hints on functions to use would be greatly appreciated. Thanks!

I need to be able to control the system wirelessly (may it be Bluetooth or whatever) through a remote control. This remote control could be a push button system or an app on the phone. I do not have this designed yet. I do not know how to make iPhone apps so the best solution for me would be a simple push button on/off switch that can wirelessly tell the servo motor to either turn 90º clockwise or counterclockwise.

The RFDuino suggestion is very helpful, thank you for that. Can anyone recommend a push-button switch (small) that can wirelessly transmit the signal to the servo motor on the device? I hope this clears things up. Thanks!


texts: Joysitck with servo, LED array and buzzer

texts: Does anybody know of a sketch that can turn a single servo 180 degrees clockwise/counterclockwise with the x axis of a joystick, light a bar graph LED with the Y axis, and sound a buzzer when the joystick button is depressed.


texts: Changing parameters of pulseIn() to sense different materials

texts:
I have a ultrasonic sensor and in order to get the distance I use the pulseIn() function included in the arduino library, and then change it to distance. As the ultrasounds does not work equally in different materials as i have seen in Performance comparison of Infrared and Ultrasonic sensors for
obstacles of different materials in vehicle/ robot navigation
applications. My question is if there is a way of changing the pulseIn() to have different materials, function:

unsigned long pulseIn(uint8_t pin, uint8_t state, unsigned long timeout)
{
    // cache the port and bit of the pin in order to speed up the
    // pulse width measuring loop and achieve finer resolution.  calling
    // digitalRead() instead yields much coarser resolution.
    uint8_t bit = digitalPinToBitMask(pin);
    uint8_t port = digitalPinToPort(pin);
    uint8_t stateMask = (state ? bit : 0);

    // convert the timeout from microseconds to a number of times through
    // the initial loop; it takes approximately 16 clock cycles per iteration
    unsigned long maxloops = microsecondsToClockCycles(timeout)/16;

    unsigned long width = countPulseASM(portInputRegister(port), bit, stateMask, maxloops);

    // prevent clockCyclesToMicroseconds to return bogus values if countPulseASM timed out
    if (width)
        return clockCyclesToMicroseconds(width * 16 + 16);
    else
        return 0;
}

or the countPulseASM, which I translate from the asembled code, which can have some errors) as:

// wait for any previous pulse to end
while ((*port & bit) == stateMask)
{
        if (--maxloops == 0)
        {
           return 0;
        }
}

// wait for the pulse to start
 while ((*port & bit) != stateMask)
{
    if (--maxloops == 0)
    {
       return 0;
    }
}

// wait for the pulse to stop
 while ((*port & bit) == stateMask)
 {
    if (++width == maxloops)
    {
        return 0;
    }
 }
return width;

Another way of doing that is having a correction factor while changing the time into the distance, but for that I shold have the differences of all the materials.


texts:
I am trying to update a db table using a WIFI Bee.

For the life of me, I can't figure out how to connect to and program the WiFi Bee ESP card. I've looked on DFRobot's website and other websites to no avail.

The PHP code is

try {
        include "../Common/ConnectionStringArduino.php"; // Create a connection

        // Update state
        $sql    = "Update `Status` SET `DateTime`='".time()."',`State`='".$_GET["CurrentState"]."' WHERE `Device`='Arduino';";
        $result = $con->query( $sql ); if($result === FALSE) { die(mysqli_error());}
        mysqli_close($con);
        echo "Success";
    } catch (Exception $e) {
        echo "Error";
    };

If i call the page by typing the URL of this page on a browser window it updates the database on a Raspberry Pi but so far I had no luck in doing it via the WiFi Bee module.

I have a Rome v2 board with inbuilt WiFi Bee socket.

I am familiar with AT commands (but not a ginus)

My Arduino code

#include "esp8266.h"

#define ssid "XXX"
#define pass "YYY"
Esp8266 wifi;

void setup() {
  delay(2000);            // It will be better to delay the setup for 2 seconds for esp8266 module to initialize
  Serial.begin(9600);     // Terminal serial port baud rate for USB debugging on the pc serial monitor
  Serial1.begin(115200);  // Xbee Serial port baud rate should be set the same to 115200

  // Items for WiFi Communication
  wifi.begin(&Serial1, &Serial);    // Setup the WiFi to use Setial1 and Serial to debug
  if (wifi.connectAP(ssid, pass)){  // Connect to the AP
    wifi.debugPrintln("Connection to AP sucessful!");
  } else {
    while(true);
  };
  wifi.debugPrintln("esp8266 ip:" + wifi.getIP());
  wifi.setSingleConnect();
  if (wifi.connectTCPServer("192.168.1.17", "80")) { wifi.debugPrintln("Connection to Pi Successful!");}
  else                                             { wifi.debugPrintln("Connection to Pi Failed!!!");};
}

void loop(){
  if(Serial1.available()) {
   ....
   For god sake how do I call this page : "http://192.168.1.17/Arduino/IAmAlive.php?CurrentState=1" to update the database entry using this beeeeeee
   ....
  }
}

The bee gets an IP upon successful connection

Connection to AP successful!
esp8266 ip:192.168.1.23

and i can ping the bee

Reply from 192.168.1.23: bytes=32 time=78ms TTL=255
Reply from 192.168.1.23: bytes=32 time=99ms TTL=255
Reply from 192.168.1.23: bytes=32 time=25ms TTL=255
Reply from 192.168.1.23: bytes=32 time=6ms TTL=255

But have no idea how to call the page to update the db. I have read endless blogs with no luck of solving my simple issue

Please help


texts:
My son and I are attempting to connect a TCS230 Color Sensor to an Arduino Nano using the tutorial at TopTechBoy.com (http://www.toptechboy.com/arduino/lesson-15-super-cool-arduino-color-sensor-project/) as guidance.

Everything seems to be working except that the conversion from pulseIn to RGB used on TopTechBoy is expecting a maximum pulse count of 102,400. Instead I am receiving pulseIn readings with a maximum of 2000.

Our Wiring

S0  - GND
 S1  - 5V
 OE  - No Connection (Tried GND)
 GND - GND
 S2  - D8
 S3  - D7
 OUT - D4
 VCC - 5V

Our Code:

int S2 = 8;
int S3 = 7;
int OUT = 4;

void setup() {

Serial.begin(9600);
pinMode (S2, OUTPUT);
pinMode (S3, OUTPUT);
pinMode (OUT, INPUT);

}

void loop() {
  // put your main code here, to run repeatedly:
  int red , green, blue;

  red = getRed();
  Serial.print("Red : "); Serial.println(red);
  Serial.println("**********************");
  Serial.println();

  blue = getBlue();
  Serial.print("Blue : "); Serial.println(blue);
  Serial.println("**********************");
  Serial.println();

  green = getGreen();
  Serial.print("Green : "); Serial.println(green);
  Serial.println("**********************");
  Serial.println();

  delay(3000);

}

int getRed(void){ return getColor(0, 0, 19000, 24000); }

int getGreen(void){return getColor(1, 1, 13600, 19200);}

int getBlue(void){return getColor (0, 1, 16400, 21600);}

int getColor(int s2Value, int s3Value , int typicalPulseWidth, int maxPulseWidth){

  long divideForScale = typicalPulseWidth / 255 ;

  digitalWrite(S2, s2Value);
  digitalWrite(S3, s3Value);

  unsigned int pulseWidth = pulseIn(OUT,LOW);

  Serial.print("Pulse Width : "); Serial.println(pulseWidth);

  unsigned int rColor = pulseWidth / divideForScale ; //401.5686274509804
  Serial.print("Response Color - Inverted : "); Serial.println(rColor);

  rColor = 255 - rColor ;
  Serial.print("Response Color - Final : "); Serial.println(rColor);

  delay(500);

  return rColor ;

}

The pulses appear correct, just out of scale. Red items produce short Red pulses and so on.

I tried to correct for the shorter pulses by using the Typical Output Frequency (f0) found on page 4 of the data sheet. I'm not sure if this is the right use of this frequency output spec.

http://www.unihedron.com/projects/darksky/tcs230-e33.pdf

Lowering the max possible pulses per second from 100,400 to around 20,000 gave us a little more variation between RGB values, but still the output is nothing like the expected color.

Can anybody offer some insight as to why the TCS230 pulse count is far fewer than the TTB code expects and what can I do to fix either the pulse count or the scale? Kind regards.

Output from Measuring a Blue RFID Keyfob:
    divideForScale : 74
    Pulse Width : 673
    Response Color - Inverted : 9
    Respponse Color - Final : 246
    Red : 246
    **********************

divideForScale : 64
Pulse Width : 376
Response Color - Inverted : 5
Respponse Color - Final : 250
Blue : 250
**********************

divideForScale : 53
Pulse Width : 737
Response Color - Inverted : 13
Respponse Color - Final : 242
Green : 242
**********************


texts: Pressure transducer / sensor (0.5 - 4.5V) innacurate analog pin readings

texts:
I have a relatively cheap 0-15psi pressure transducer. It has 3 pins - ground 5V and signal. The signal outputs a voltage of 0.5V to 4.5V based on pressure from 0psi to 15psi. I can verify it does respond to significant pressure increases so it works at least to a point.

The issue is that the reading from arduino can differ by over 50% when at ambient atmospheric pressure (resting on a table). It should be significantly more accurate if the sensor data are to be trusted. The code is basic:

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

void measurePressure(){
  int rawReading = analogRead(A0);   // Range : 0..1024
  //float rawVoltage = (rawReading * (4.5 / 1023.0)) + 0.5;

  Serial.print("Raw reading: ");
  Serial.println(rawReading);

}

void loop() {
  measurePressure();
  delay(1000);
}

The output variations are not entirely random, it seems that the reading goes down and up in intervals of roughly 5-15 seconds. Below is a sample output:

Raw reading: 61
Raw reading: 67
Raw reading: 70
Raw reading: 73
Raw reading: 74
Raw reading: 78
Raw reading: 75
Raw reading: 82
Raw reading: 85
Raw reading: 90
Raw reading: 89
Raw reading: 97
Raw reading: 103
Raw reading: 119
Raw reading: 146
Raw reading: 165
Raw reading: 171
Raw reading: 168
Raw reading: 163
Raw reading: 150
Raw reading: 143
Raw reading: 118
Raw reading: 88
Raw reading: 70
Raw reading: 62
Raw reading: 64
Raw reading: 72
Raw reading: 78
Raw reading: 80
Raw reading: 82
Raw reading: 88
Raw reading: 92
Raw reading: 102
Raw reading: 134
Raw reading: 160
Raw reading: 170
Raw reading: 172
Raw reading: 166
Raw reading: 158
Raw reading: 149
Raw reading: 132
Raw reading: 100
Raw reading: 73
Raw reading: 63
Raw reading: 61
Raw reading: 71
Raw reading: 77
Raw reading: 79
Raw reading: 84
Raw reading: 90
Raw reading: 90
Raw reading: 99
Raw reading: 134
Raw reading: 161
Raw reading: 170
Raw reading: 166
Raw reading: 161
Raw reading: 151
Raw reading: 133
Raw reading: 103
Raw reading: 81
Raw reading: 68
Raw reading: 63
Raw reading: 63
Raw reading: 71
Raw reading: 73
Raw reading: 81
Raw reading: 83
Raw reading: 85
Raw reading: 89
Raw reading: 98
Raw reading: 128
Raw reading: 161
Raw reading: 171
Raw reading: 166
Raw reading: 159
Raw reading: 145
Raw reading: 120
Raw reading: 85
Raw reading: 67
Raw reading: 57
Raw reading: 63
Raw reading: 72
Raw reading: 75
Raw reading: 83
Raw reading: 85
Raw reading: 89
Raw reading: 97
Raw reading: 130
Raw reading: 164
Raw reading: 172
Raw reading: 163
Raw reading: 155
Raw reading: 135
Raw reading: 101
Raw reading: 69
Raw reading: 60
Raw reading: 62
Raw reading: 72
Raw reading: 78

I tried adding 4.7k pull down resistor with no change but that was just a blind try. I have a multimeter connected as well and the reading seems to be more stable ranging from about 0.495V to 0.535V (variations do not seem to match arduino output).

What could be causing the issue?


texts:
Imagine i have a code, that loops, and at one point there is i2c request.

Is loop() paused right away when there is Wire.onReceive() or loop is finished then Wire.onReceive() is called?


texts: I need to play sound on 10 piezos at once. How to do that without delay() function.


texts:
I designed a PWS (personal weather station) which will be placed in a difficult to access location.  In case of the master crashing and not requesting from the slave for a certain amount of time (stay alive protocol), is it possible to reset the master from the slave by powering a digital pin?

Note, I improvised a pull down circuit so that the Arduino Nano's D7 (or any other digital pin) 5V output could be pulled down to 3.3V.


texts:
I'm trying to build Bluetooth RC car, but I can't run only one DC motor.. only both of them. Everything works fine, the bluetooth, the app but when i try to go forward/backward/left/right nothing happens, only when i run both of them. I'm running the Arduino Nano with usb cable. The bluetooth connection is stable, The DC motors are working. I don't know what I'm doing wrong. Thanks!

const int AIA = 2;
const int AIB = 3;
const int BIA = 4;
const int BIB = 5;
byte vSpeed = 255;
int state;

void setup() {
pinMode(AIA, OUTPUT);
pinMode(AIB, OUTPUT);
pinMode(BIA, OUTPUT);
pinMode(BIB, OUTPUT);

// Initialize serial communication at 9600 bits per second:
    Serial.begin(9600);
}

void loop() {
  //Save income data to variable 'state'
    if(Serial.available() > 0){
      state = Serial.read();
    }

  /***********************Forward****************************/
  //If state is equal with letter 'F', car will go forward!
    if (state == 'F') {
      analogWrite(AIA, vSpeed);
      analogWrite(AIB, 0);
      analogWrite(BIA, 0);
      analogWrite(BIB, 0);
    }
  /**********************Forward Left************************/
  //If state is equal with letter 'G', car will go forward left
    else if (state == 'G') {
      analogWrite(AIA, vSpeed);
      analogWrite(AIB, 0);
      analogWrite(BIA, vSpeed);
      analogWrite(BIB, 0);
    }
  /**********************Forward Right************************/
  //If state is equal with letter 'I', car will go forward right
    else if (state == 'I') {
      analogWrite(AIA, vSpeed);
      analogWrite(AIB, 0);
      analogWrite(BIA, 0);
      analogWrite(BIB, vSpeed);
    }
  /***********************Backward****************************/
  //If state is equal with letter 'B', car will go backward
    else if (state == 'B') {
      analogWrite(AIA, 0);
      analogWrite(AIB, vSpeed);
    }
  /**********************Backward Left************************/
  //If state is equal with letter 'H', car will go backward left
    else if (state == 'H') {
      analogWrite(AIA, 0);
      analogWrite(AIB, vSpeed);
      analogWrite(BIA, vSpeed);
      analogWrite(BIB, 0);
    }
  /**********************Backward Right************************/
  //If state is equal with letter 'J', car will go backward right
    else if (state == 'J') {
      analogWrite(AIA, 0);
      analogWrite(AIB, vSpeed);
      analogWrite(BIA, 0);
      analogWrite(BIB, vSpeed);
    }
  /***************************Left*****************************/
  //If state is equal with letter 'L', wheels will turn left
    else if (state == 'L') {
      analogWrite(BIA, vSpeed);
      analogWrite(BIB, 0);
    }
  /***************************Right*****************************/
  //If state is equal with letter 'R', wheels will turn right
    else if (state == 'R') {
      analogWrite(BIA, 0);
      analogWrite(BIB, vSpeed);
    }
  /************************Stop*****************************/
  //If state is equal with letter 'S', stop the car
    else if (state == 'S'){
      analogWrite(AIA, 0);
      analogWrite(AIB, 0);
      analogWrite(BIA, 0);
      analogWrite(BIB, 0);
    }
}


texts:
I am looking to power a Trinket Pro 5V microcontroller using a 9V voltage source. I have logic running on this controller to gather the data from an accelerometer (powered off of the 5V pin on the controller) and output it to three strands of 21 RGB LEDs (https://www.adafruit.com/products/1655).

RGB LEDs cannot exceed a power source of 5V and after passing through the Trinket voltage regulator the 5V pin on the Trinket just does not have enough power for all three strands.

Please, advise on the appropriate hardware for this case. What is the maximum voltage that RGB LEDs can handle and how does the schematic look on the protoboard.

Thank you for your expertise.


texts: Measurement of pulse duration greater than 3mins

texts:
Is it possible to measure the width of a pulse which is longer than 3 minutes? The pulseIn function can only measure duration of maximum 3 minutes accurately.
I've tried using interrupts but haven't come up with a correct solution yet.

I'm measuring the duration of pulse (HIGH) generated by AND gate connected to the outputs of two comparators. AND gate output voltage is around 4.9 volts.

Any logical solution or idea would be appreciated. Thanks!


texts: Questions on how to connect Arduino to Matlab through the serial port

texts:
I have an Arduino board with Intel Edison on it. I have tried to read data in Arduino from MatLab through the serial port. I'm sure the Arduino board is working because when I use the serial monitor from Arduino, it shows the data read from the Arduino board. My command is like this in Arduino:

   reading = Wire.read();
   Serial.println(reading)

I got errors in Matlab when I tried to work with these piece of code:

   s=serial('COM4');
   set(s,'BaudRate',9600);
   fopen(s);

MatLab complains that "Port: COM4 is not available. No ports are available.
Use INSTRFIND to determine if other instrument objects are connected to the requested device." I have tried with "instrfind()" in matlab and got this:

   Instrument Object Array

   Index:    Type:     Status:   Name:
   1         serial    closed    Serial-COM4
   2         serial    closed    Serial-COM4
   3         serial    open      Serial-COM4
   4         serial    closed    Serial-COM4
   5         serial    closed    Serial-COM4

I still can't get any clue on this. Can anybody help me?


texts: Help Understanding FFT Analysis and analogRead()?

texts:
Here's the deal, I'm attempting to learn how to use an FFT (Fast Fourier Transformation) Library for sound analysis (link is here). My issue is that this comes with included C++ code to show users how to use the FFT library. There are three examples, but I'll show this one because it's closest to the application I have planned for it:

/*
fft_adc_serial.pde
guest openmusiclabs.com 7.7.14
example sketch for testing the fft library.
it takes in data on ADC0 (Analog0) and processes them
with the fft. the data is sent out over the serial
port at 115.2kb.
*/

#define LOG_OUT 1 // use the log output function
#define FFT_N 256 // set to 256 point fft

#include <FFT.h> // include the library

void setup() {
  Serial.begin(115200); // use the serial port
  TIMSK0 = 0; // turn off timer0 for lower jitter
  ADCSRA = 0xe5; // set the adc to free running mode
  ADMUX = 0x40; // use adc0
  DIDR0 = 0x01; // turn off the digital input for adc0
}

void loop() {
  while(1) { // reduces jitter
    cli();  // UDRE interrupt slows this way down on arduino1.0
    for (int i = 0 ; i < 512 ; i += 2) { // save 256 samples
      while(!(ADCSRA & 0x10)); // wait for adc to be ready
      ADCSRA = 0xf5; // restart adc
      byte m = ADCL; // fetch adc data
      byte j = ADCH;
      int k = (j << 8) | m; // form into an int
      k -= 0x0200; // form into a signed int
      k <<= 6; // form into a 16b signed int
      fft_input[i] = k; // put real data into even bins
      fft_input[i+1] = 0; // set odd bins to 0
     }
    fft_window(); // window the data for better frequency response
    fft_reorder(); // reorder the data before doing the fft
    fft_run(); // process the data in the fft
    fft_mag_log(); // take the output of the fft
    sei();
    Serial.println("start");
    for (byte i = 0 ; i < FFT_N/2 ; i++) {
      Serial.println(fft_log_out[i]); // send out the data
    }
  }
}

Now, with that said, I have a very general grasp of the idea that those lines referencing some variable called ADMUX and ADCSRA have to do with the analogRead() method and that the ADCH and ADCL refer to another two components that are combined to provide the returned integer that analogRead() spits out. What I don't understand whatsoever are those seemingly random strings of characters that these are being set equal to. For example, what does 0x40 or 0x01 or 0xe5 even refer to in the setup() method (if nothing else maybe somebody could point me in the right direction for this, because that part I really am entirely clueless about). And furthermore, why manipulate these directly in the first place, because if you reference the source code for analogRead() they look awfully similar. Thanks for any help in advance!