texts:
bine
#include <LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);

#define sensor A0
#define led 13
#define ledd 8  // d out from mq3
#define buz 9
#define motor 10
void setup()
{
  Serial.begin(9600);
  lcd.begin(16,2);
  lcd.print("ALCOHOL MONITORING");
  lcd.setCursor(0,1);
  lcd.print(" VEHICLE SYSTEM ");
  delay(2000);
  pinMode(sensor, INPUT);
  pinMode(buz, OUTPUT);
  pinMode(led, OUTPUT);
  pinMode(ledd, OUTPUT);
  pinMode(motor, OUTPUT);
  lcd.clear();
}

void loop()
{
  float adcValue=0;
  for(int i=0;i<10;i++)
  {
    float actualanalogReading =  analogRead(sensor);
    adcValue = adcValue + actualanalogReading;
    Serial.println("In loop counter >"); // logging
    Serial.print(i);
    Serial.print(" input reading : ");
    Serial.print(actualanalogReading);
    Serial.print(" cumulative input reading : ");
    Serial.print(adcValue);

    delay(10);
  }
    float v= (adcValue/10) * (3.0/1024.0);
    float mgL= 0.67 * v;
    Serial.println("");
    Serial.print("Post calculation v value >" );
    Serial.print(v);
    Serial.print(" mg/L > ");
    Serial.print(mgL);
    Serial.println("");
    Serial.print("BAC:");
    Serial.print(mgL);
    Serial.print(" mg/L");
    lcd.setCursor(0,0);
    lcd.print("BAC: ");
    lcd.print(mgL,4);
    lcd.print(" mg/L        ");
    lcd.setCursor(0,1);
    if(mgL > 0.8)
    {
      lcd.print("Drunk ENGINE OFF ");
      Serial.println("Drunk ENGINE OFF ");
      digitalWrite(buz, HIGH);
      digitalWrite(led, HIGH);
      digitalWrite(ledd, LOW);
      digitalWrite(motor, LOW);
    }
    else
    {
      lcd.print("Normal ENGINE ON ");
      Serial.println(" Normal ENGINE ON ");
      digitalWrite(buz, LOW);
      digitalWrite(led, LOW);
      digitalWrite(ledd, HIGH);
      digitalWrite(motor, HIGH);
    }

    delay(100);

}

top code^^^
combines with this>>
const int LED = A5;
const int DO = 6;
void setup() {
 Serial.begin(9600);
 pinMode(LED, OUTPUT);
 pinMode(DO, INPUT);
}
void loop() {
 int alarm = 0;
 float sensor_volt;
 float RS_gas;
 float ratio;
//-Replace the name "R0" with the value of R0 in the demo of First Test -/
 float R0 = 0.10;
 int sensorValue = analogRead(A1);
 sensor_volt = ((float)sensorValue / 1024) * 5.0;
RS_gas = (5.0 - sensor_volt) / sensor_volt; // Depend on RL on yor module
 ratio = RS_gas / R0; // ratio = RS/R0
//------------------------------------------------------------/
 Serial.print("sensor_volt = ");
 Serial.println(sensor_volt);
 Serial.print("RS_ratio = ");
 Serial.println(RS_gas);
 Serial.print("Rs/R0 = ");
 Serial.println(ratio);
 Serial.print("\n\n");
 alarm = digitalRead(DO);
 if (alarm == 1) digitalWrite(LED, LOW);
 else if (alarm == 0) digitalWrite(LED, HIGH);
 delay(1000);
}


texts:
Schematic:

I am making some light fixtures controlled by an Arduino UNO. Each fixture will host two approx. 1 meter long analog RGB LED strips with a current draw at full power of ~1.2 A per meter. I have a 12 V power supply that I will wire directly to the strips, with the RGB channels wired to the Ardiino PWM pins via NPN MOSFET (note in the schematic I've only shown one color channel for simplicity, but there would of course be three transistors hooked up to three PWM pins). The Arduino itself will be powered by USB.

My main difficulty in wiring the system is that for so much current I need fairly thick wire. The pads on the LED strips are delicate and I have several times damaged them by mechanical stress from the wire while soldering. The thick wire also crowds the narrow space between the pads creating a risk of a short. Therefore my first question is (bear with me, I'm pretty new to this):

1) How should I wire the LED strips?

My thought is to wire up the strips in parallel with thinner, more flexible wires. This brings up two sub-questions:

1a) How should I join the thinner wires to the thick wire coming from the power supply?

1b) At the junction between the wires leaving the lights and running to the transistor, does the wire need to become thick again? (I think the answer is yes – the current should be the same as coming out of the power supply.)

I also am unsure about the ground.

2) Does the wire coming from transistor to ground need to be joined to the ground pin on the Arduino or can it run directly to the ground terminal of the power supply?

Sub-question:
2a) Does the wire coming from transistor to ground need to be thick?

I don't really understand how transistors work (basically my understanding is that the Arduino uses a small amount of current over the PWM pins to somehow control how much current is allowed to flow through the rest of the circuit.

I've drawn a schematic showing how I think maybe this system needs to be wired up. Do I need to make changes?


texts: What are the applicable processor for the ATmega32u4? And what are higher versions of ATmega32u4?

texts: Can arduino uno smd r3 version handle a Keyboard.h library?  it is not applicable for that arduino?


texts: WiFi thermometers: save different location string as const across many devices

texts: I've built a very simple WiFi thermometer out of an Adafruit ESP8266 HUZZAH breakout board and a TMP36 temperature sensor. I have it reporting the temperature over wifi to my computer which will be storing the data in a database for monitoring purposes. I'd like to make multiple of these devices and place them around the house. My question: I currently have the location of the board as a const char* on the board itself. Doing this for multiple devices is just a bad idea and a nightmare to manage. Is there some way of setting a location variable on the board that will persist across shutdowns? Or am I coming at the problem from completely the wrong direction?


texts:
My ESP8266 has stopped working.
The red power light comes on and the blue TX light is on solid.

Here's what I did.

Connecting

ESP8266  -> Arduino nano

VCC, CH_PD, RST  -> 5V (external supply)

TX -> TX

RX -> RX

I could send AT commands via the serial monitor.

Then I connected

RX -> 11

TX -> 10

and set up software serial intending to repeat the experiment.
I was getting garbage characters in the response, and found that I had to esp8266.println("AT+IPR=9600"); to reduce the baud rate.

Then the blue TX light cam on permanently and it's stopped working at all.


texts: Uno - ESP32 SoftwareSerial communication won't work

texts:
I have two boards, Uno and ESP32 and my goal is to send data from the Uno to the ESP. I made a voltage divider so my ESP doesn't get fried and I use the communication only in ONE way, strictly UNO -> ESP32. I use PIN 9 from my UNO to send data and RX2 (16) from my ESP to receive the data. How ever, I get errors and can't make it work.
This is my Uno code:
#include <SoftwareSerial.h>

SoftwareSerial softPort(-1, 9);

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

void loop() {
softPort.print("100");
delay(2000);

}

and my ESP code:
#include <SoftwareSerial.h>

#define RXD2 16
#define TXD2 -1

SoftwareSerial Serial2(RXD2, TXD2); // RX, TX

void setup() {
Serial.begin(115200);
Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);

}

void loop() {
Serial.println("Data received:");
Serial.println(Serial2.read());
delay(200);

}

I'm getting an error that says

no matching function for call to 'SoftwareSerial::begin(int, int, int, int)'


texts:
What I have:

1 x 8 channel relay
1 x IR receiver
1x Arduino Uno
1x momentary switch
1x breadboard
1x 10K resister

I think the wiring is all ok as for the most part things are working as they should..ish.

Just a few bugs I need to fix.

The goal was to toggle just 2 relays (at the moment) on/off with the hardwired switch and individually toggle the a relay using an IR remote control.

Like I said this sort of works....

If I press the momentary button it does indeed toggle both relays...yeah!
then as long as the 2 relays are toggled to the on position by the momentary switch I can toggle each relay using buttons on a remote.

However if I turn the relays off with the momentary button I can't turn them on with the remote. Also if I turn off one of the relays with the remote and then press momentary switch it alternates the toggle between the 2 relays rather than just turning the other one off.

I have been using various example sketches to achieve all this and just trying to stitch them together as best I can but something is telling me that the approach is all wrong and that I should maybe be looking into Boolean's perhaps?

Hope you can shed some light on this for me.

#include <IRremote.h>
#define irPin 8
IRrecv irrecv(irPin);
decode_results results;
const int buttonPin = 2;
const int relay1 = 13;
const int relay2 = 12;
int relay1State;
int relay2State;
int buttonState;
int lastButtonState;
long lastDebounceTime = 0;
long debounceDelay = 50;

void setup() {
  Serial.begin(9600);
  irrecv.enableIRIn();
  pinMode(buttonPin, INPUT);
  pinMode(relay1, OUTPUT);
  pinMode(relay2, OUTPUT);
  digitalWrite(relay1, relay1State);
  digitalWrite(relay2, relay2State);
}

void loop() {
  if (irrecv.decode(&results)) {
    switch (results.value) {
      case 0xFF30CF:
        Serial.println("Button 1 Pressed");
        relay1State = ~relay1State;
        digitalWrite(relay1, relay1State);
        delay(250);
        break;
      case 0xFF18E7:
        Serial.println("button 2 pressed");
        relay2State = ~relay2State;
        digitalWrite(relay2, relay2State);
        delay(250);
        break;
    }
    irrecv.resume();
  }

  int reading = digitalRead(buttonPin);
  if (reading != lastButtonState) {
    lastDebounceTime = millis();
  }
  if ((millis() - lastDebounceTime) > debounceDelay) {

    if (reading != buttonState) {
      buttonState = reading;

      if (buttonState == HIGH) {
        relay1State = !relay1State;
        relay2State = !relay2State;
      }
    }
  }

  digitalWrite(relay1, relay1State);
  digitalWrite(relay2, relay2State);
  lastButtonState = reading;
}


texts: Handle reading timing in Python using pySerial

texts:
I'm not sure about how to properly handle timing readings from serial inside a Python script. I need to read a value every 5 seconds.

From Arduino I could do,

Serial.println(value);
delay(5000); // should I wait here?

Inside Python script I could do,

import serial
import time

arduino = serial.Serial('/dev/ttyACM1', 9600, timeout=5) # should I set timeout?

while True and arduino.isOpen():

    try:
        value = arduino.readline().strip()
        print value

        time.sleep(5) # should I wait here?

    except KeyboardInterrupt:
        print "\nClosing..."
        arduino.close()

EDIT: Apart from that, the first reading is always wrong, like if there was something in the reading buffer.
I've found out that to solve that I should add arduino.flushInput() just after opening the port.


texts: Trigger countdown with 433MHz transmission

texts:
I would like to use an arduino to read 433 MHz transmission from multiple Soil Moisture Sensors. Since I can never be sure all transmissions reach the receiver I'd like to set a countdown from the moment the first transmission is received. If another transmission is received, the countdown starts again.
After a defined amount of time (e.g. 10 Minutes) without any more signals or if all signals have been received (e.g 4 Sensors) the receiving unit should stop and come to decision based on the data it got to the point.

For transmitting and receiving I am using the <RCSwitch.h>library.

The loop of the receiving unit and one Sensor looks like this:

#include <RCSwitch.h>
RCSwitch mySwitch = RCSwitch();
void Setup(){
Serial.begin(9600);
mySwitch.enableReceive(4);
}
void loop() {
if (mySwitch.available()) {
int value = mySwitch.getReceivedValue();

if (value == 0) {
  lcd.clear();
  Serial.print("Unknown encoding");
  }
  else {
  Serial.print(mySwitch.getReceivedValue());
  Serial.print("%");
}

The full code includes some differentiation mechanism for all sensors but I figured that might not be relevant for my question.

Question:
What's the best way to do this without a real time clock module. As far as I know I can't wait by using delay(...)since then I won't receive any data while the processor waiting.


texts: Arduino - Calculating the time for which a Pushbutton is pressed and held without being released

texts: I'm working on a project that requires calculating the time for which a pushbutton is kept pressed without being released. Is there a code snippet that i can use for this particular need ?


texts: Explanation please, of hardware and software serial links

texts:
I am starting to use a Seeeduino GPRS shield (please see note), which is essentially an Arduino Leonardo that, among other things, can be used as a mobile 'phone for sending and receiving texts. I have successfully tried the "blink an led" and "fade an led" sketches, so the compiling and uploading are ok

I am using a desktop computer with Linux Fedora 20.

Now I want to go on to use the cell phone network to communicate with my mobile 'phone. However I am puzzled by something I assume everybody else understands already, and that is the references to "select either software serial port or hardware serial port to be connected to GPRS Shield". Please could someone explain what "software or hardware serial port" is, in simple terms, or point me to a web site that does so? Do I need any wired connection with my PC other than the USB link I use for uploading sketches?

Note: I bought a discounted GPRS shield labelled version 1.0a2. All the information on the 'net is of version 1.0 or 2.0 (with no "a2") and photos and diagrams do not correspond with what I have. I am awaiting official documentation, but meanwhile treating it as an Arduino Leonardo seems to be working.


texts: Can't get call / message from A7 gsm+gprs+gps module

texts:
I am making a project using arduino uno & A7 gsm+gps+gprs module.my circuit connection is like this:

A7 UTXD -> arduino RX
A7 RTXD -> arduino TX
A7 GND -> arduino GND
A7 pwr_key -> A7 VCC5.0

When i make call from my mobile to A7,it's ok.But i cannot get call/msg from A7.
Here is my code for making call:

char phone_no[]="phone_no";

void setup()
{
Serial.begin(9600);
delay(200);
Serial.println("AT");
delay(1000);
Serial.print("ATD");
Serial.println(phone_no);
//Serial.println(";");
delay(10000);
Serial.println("ATH");
}

void loop()
{
}

What can i do now??? Please help me to fix it.I apologize for my poor english.


texts:
I am building a ESP-07 based IOT device, that detects the status of 4 doors. The device must connect to WiFi and send an http request, when 1 of 4 doors is opened. I want to place a reed switch, for example on each door. The battery consumption should be minimal, so I thought of using deepsleep () or something similar to keep the device asleep most of the time, or keep it completely off (like most Dash buttons does).

I have studied several options, but almost all use a single GPIO to wake up the device. For example, this option wakes the device up if D3 goes high, and sleep if D3 is low.

    #include
    #include
    #define WAKE_PIN D3

const char* ssid = "SSID";
const char* pass = "PASSWORD";

extern "C" {
    #include "gpio.h"
}

extern "C" {
    #include "user_interface.h"
}

void setup(){
    WiFi.begin(ssid, pass);
    uint8_t i = 0;
    while (WiFi.status() != WL_CONNECTED && i++ < 10) delay(250);
    Serial.begin(115200);
    Serial.println("Setup");
    pinMode(WAKE_PIN, INPUT_PULLUP);
    pinMode(LED_BUILTIN, OUTPUT);
    digitalWrite(LED_BUILTIN, LOW);
    gpio_init(); // Initilise GPIO pins
}

void loop(){
    Serial.println("Do something...");
    if(!digitalRead(WAKE_PIN)){
        sleep();
    }
    delay(1000);
}

void sleep(){
    Serial.println("Going to sleep...");
    delay(10);
    wifi_fpm_set_sleep_type(LIGHT_SLEEP_T); // set sleep type
    gpio_pin_wakeup_enable(GPIO_ID_PIN(WAKE_PIN), GPIO_PIN_INTR_HILEVEL);
    wifi_fpm_open(); // Enables force sleep
    wifi_fpm_do_sleep(0xFFFFFFF); // Sleep for longest possible time
    delay(100);
    Serial.println("Woke up!");
}

Here, GPIO_ID_PIN(2) corresponds to GPIO2 on ESP8266-01 , GPIO_PIN_INTR_LOLEVEL for a logic low, can also do other interrupts.

My question is:

Can I use more than one GPIO, that is, one of 4 GPIOs to wake up the device?

I have the problem of knowing which of the four doors has been opened!

The other option I have thought is to use a latch circuit that turns on the (previously turned off) device using a single GPIO. Something like this:

What I meant is that ESP-07 can latch its own power on (and off) using an MOSFET pair connected in parallel with the physical (momentary contact) power switch. When the power switch is pressed (or a door is opened), one of the  first things the ESP8266 needs to do is latch the power on. When the current iteration of this programm is done, it simply turns it's own power off again.

#define POWER_SW   2   // GPIO connected to POWER_LATCH

void LatchOn() {
    pinMode(POWER_SW, OUTPUT);
    digitalWrite(POWER_SW, HIGH);
}

void LatchOff() {
    digitalWrite(POWER_SW, LOW);
}

What I want to know is how I can use more than one signal from each of the 4 doors, or, use 4 GPIOs to activate the latch circuit. I tried with one single door connected to the GPIO that wakes the chip up. I want to extend the functionality of my program so that any of the 4 doors turns the chip on.

Thanks in advance!

P.S.
I have opened a thread about this topic in Arduino Forum as well.


texts: Using two pins to sum maximum available current

texts:
I have a theoretical question about using digital pins of arduino. The specification of Arduino Uno (or any other I guess) says, that maximum current from digital pin is 40mA. If I would need more than 40mA and less than 80mA, can I use two pins to supply enough power to the sensor or would it burn the pins in the end?

Thanks


texts:
I am unable to get a button on my arduino board to control a servo. I'd like the servo to rotate 90 degrees on button push, but it is unresponsive.

Is there a flaw in my code or is it wiring?

#include <Servo.h>  // servo library

const int button1Pin = 2;  // pushbutton 1 pin
Servo servo1; // servo control object

void setup()
{
  pinMode(button1Pin, INPUT);
  servo1.attach(9);

  // Set servo 1 to output?
}

void loop()
{
  int button1State;
int position;

button1State = digitalRead(button1Pin);

if (button1State == LOW);
{
  servo1.write(90);  // move servo
}

}


texts:
I am trying to build a home automation system and i am unable to get data from a website using the arduino sketch, however i am able to get data from the website when i enter the AT commands into the serial monitor.Below is my sketch:

#include <SoftwareSerial.h>

SoftwareSerial esp8266(4,5);

void setup(){
  Serial.begin(9600);
  esp8266.begin(115200);
  esp8266.println("AT+CIPMUX=1\r\n");
  delay(2000);
  esp8266.println("AT+CIPSTART=0,\"TCP\",\"www.homeautomationserver.com\",80 \r\n");
  delay(2000);
  esp8266.println("AT+CIPSEND=0,75");
  esp8266.println("GET /f/pw9e1acqx7yb0gl.txt HTTP/1.1\r\n");
  esp8266.println("Host:www.homeautomationserver.com\r\n\r\n");
}

void loop(){

  if (esp8266.available()){
    Serial.write(esp8266.read());
  }
  if (Serial.available()){
    esp8266.write(Serial.read());
  }
}

I get a 501 not Implemented error from the server.

Please Help.

Thanks


texts:
All I need to do is generate a random integer between 0 and 3 for example.
I am using this function:

void Crossover(int parents[2][3])
{
  int ranDpart;
  int ranDparent;
  for(int i=0; i<10; i++)
  {
    for(int j=0; i<3; j++)
    {
      ranDpart = random(0,3);
      ranDparent = random(0,2);
      newGen[i][j] = parents[ranDparent][ranDpart];
    }
  }
}

where as you see parents is input with size of 2x3 and newGen is 10x3 2D array. As seen here in the code, this function is supposed to randomly take one of parent and a part of this parent to make a new "child". Am I doing something wrong? I think that random gives me bad results. I tried some online compiler and random gives me numbers like "1804289383" even if I tried to make it long. Can you guys help me with random int?


texts:
I have a project that requires  data to be sent online from a moving bus. I am using ESP8266F modules to send the data.

I am wondering what Arduino modules to buy that will act as an access point with wifi and will connect to the internet through GSM.

In this configuration, the ESP8266 will connect to the access point and will upload the data online.

I want to connect a DF robot "SIM808 GPS/GPRS/GSM Shield For Arduino" to an Arduino Yun and use them as a wifi access point to connect to the internet through GSM connection.

The ESP8266 (5 of them) will connect to the Arduino Yun and will then send variables to the internet through the internet connection provided by the GSM.


texts:
My project requires that a hinged box be opened approx 90 deg. with an servo controlled with an Arduino, staying open for approx. 90 seconds. When the lid is open, then a lift mechanism with a stepper motor, also controlled by the Arduino, will raise a platform for approx 60 seconds then lower the platform and close the lid. I an new to coding the Arduino but my research leads me to multitasking with millis().state machine, Can someone help with this

I want to "sandwich" the stepper action in between the servo action

Is changing the project to having the lid opening and the platform coming up (at an appropriate slower rate of course) together,and then reversing the action, then be multitasking? If so, can someone steer me to help with this scenario?

Thanks to all for their response's. I think that I am still to much of a "newbie 1.0" to understand (and modify) the solutions offered.
I did find this post.... https://learn.adafruit.com/multi-tasking-the-arduino-part-1/a-clean-sweep....which seems to be enough of a explanation (with code) for me to begin to get a grip on a solution to my project.
I'm sure that I will ask for help in the near future about certain aspects of this sketch. I welcome anyone's comments on O.O.P.


texts: Passing a time_t array as a function parameter

texts:
I'm trying to log reconnections and disconnections of a network. For that I've created 2 time_t arrays to store such occurances:
const int logSize = 10;
time_t conLog[logSize];
time_t disconLog[logSize];

Now, down the road, I have some manipulation and time calculation to do, and for that I wish to pass those log as a variable.
For example - zeroing its values:
void initLog(time_t log[], time_t init_val = 0)
{
        int sizeLog = sizeof(log) / sizeof(log[0]);
        Serial.print("size: ");
        Serial.println(sizeLog);
        for (int i = 0; i < sizeLog; i++)
        {
                log[i] = init_val;
        }
}

in order using it in a simple way : initLog(conLog);
But unfortunately this is wrong.
I've tried to replace time_t log[] with time_t &log - but still no luck.
What do I do wrong ?


texts: Serial monitor listing unreadable characters

texts:
My Serial Monitor is displaying unreadable characters.  If anybody can give me some insight on why this would be happening please let me know.

Thank You.


texts:
I working on a prototype with an Arduino UNO and an AdaFruit Low Energy Blue tooth

I have an array of uint32_t that I am trying to send via blue tooth to a given device.  I don't think i can send the array so I was trying to send it as a comma separated string.

I can print out each individual index of that array just fine, but its completely blank when i try to make a comma separated String..  See code and comments below.

Ay Array:

uint32_t items[]= {0,3513728,7925384,0,0,0};

In My Loop:

String output = "";

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

  BTLEserial.print(items[i]); // Prints as expected
  output += getStringForUI32_T(items[i]);
  output+=",";

 }
 BTLEserial.print(output); // prints BLANK

I imagine this has something to do with memory but I am at a complete loss.. Please help!


texts:
I´m building a system that has two arduinos (like the image on the botton) linked via ICSP. The "Programer"  programs the second one, called "Worker"( with a .hex file in the SD card of the Programer).

The Worker controls a LCD 16x4 and displays messages to the user.

What I´m tring to do is when the Programmer is programming the Worker it also displays a message like "Programming, wait" in the Worker LCD. But in code, just telling to the Worker displays a message is not going to happen because when it has been programmed it displays garbage in the LCD.

Q So is it possible the the Programmer takes control of the LCD before it begin to program the worker and displays its message?

The LCD works with normal 4-bit mode comunication and I would rather not converte it to I2C if it´s possible.


texts:
I have a file YunConfig.fzz file for arduino yun for map maker project with ultrasonic sensor.
How can I open or do with that file?
please answer me.


texts:
I'm working on a project using this board and wish to do so on a low level ,as in enabling certain registers to enable interrupts etc.
I can't seem to find the correct header files to support programming in this manner (Can't recognise the register names), I've tried using both Atmel Studio and the Arduino IDE but can't seem to get it to work.

Any help would be greatly appreciated


texts: Atmel studio 7 vs Arduino IDE for register level coding?

texts:
Which one is better to get started with register level embedded c coding?
Also which one is used professionally?


texts: Supplying near perfect DC signals from Arduino UNO

texts:
My problem seems very simple but has been impossible to find a straight forward answer searching online. I need my Arduino to output different DC voltages from six ports (probably PWM ports), like 2 V from port 3, 2.1 V from port 5 and so on. And then be able to quickly change to like 4 V from port 3, and 4.1 V from port 5 and so on. But these DC signals need to be near perfect for the highly sensitive sensor I am working with. Everywhere I've searched says to use the PWM outputs and then an RC filter but the ripple from this process is concerning, can I get the the ripple to be under a few mV amplitude? Is there more smoothing I can do beyond a simple RC lowpass filter?

TLDR: I basically need a DC voltage generator that can select between 1 and 5 volts at 0.1 V intervals, and I need to be able to do it with output from the Arduino and some external hardware that will provide a near perfect DC signal to a sensor.


texts:
I'm trying to send heximal values from arduino to PZEM-04 power module (it shows voltage, current and ect.) over serial communication in heximal format and get values in decimal format for further actions with them. Any help with the code please?
One of the commands:
Send command: B4 C0 A8 01 01 00 1E
Reply data: A4 00 00 00 00 00 A4

Edit: I am connecting wires from PZEM module TTL to arduino "serial port": TX-RX, RX-TX, VCC-VCC, GND-GND, so it's serial communication..
    PZEM module: http://www.aliexpress.com/store/product/PEACEFAIR-AC-100A-Electric-power-monitoring-and-communication-module-power-meter-power-energy-Volt-Ammeter/1773456_32373508101.html


texts: Multiple HC-SR04 with one 5v 7805 regulator

texts:
I am working on a autonomous track vehicle. I have mounted

3 HC-SR04 sensors
1 Sharp infrared distance sensor
3 infrared led distance sensors

1 Arduino Mega 2560
1 H-bridge Board HG7881

I am trying to use 7.5 v 1700 mAh Nicd battery (also tried 11.1 Lipo 2200 mAh)
For all sensors power (5v) I developed 5v regulator using 7805 which is connected directly from battery as input. The output 5v is going to power distribution board (used from quadcopter extra board) which provides 5v to every sensor.

The real problem starts here when I am not getting correct or nothing in reading from Ultrasonic sensors and my vehicle starts behaving abnormal. I checked that sensor reading is either 0 or wrong. I used both simple and with NewPing library.

I checked when using 7.2v battery the output from 5v regulator is 3.72v.

Now my question is if the power is below 5v, does sensors starts behaving like this? How can we supply voltage so every sensor will receive full 5v to work properly?

My vehicle will not work until sensors provide correct distance reading. I worked successfully with one sensor but with number of these, tired working since many days.


texts: Node.js cannot recognize characters from the serial port

texts:
The following script prints everything fine, it recognizes integers from the serial port, but cannot recognize characters.  The if statement does not work with characters.  I have tried both == and === in the if statement

var SerialPort = require('serialport')
var Readline = SerialPort.parsers.Readline
var serialPort = new SerialPort('/dev/ttyAMA0', {//ttyAMA0
  baudRate: 9600
})

var parser = new Readline()
serialPort.pipe(parser)
parser.on('data', function (data) {
if(data === 'c'){/// c is not recognized
  console.log('data received: ' + data)
}

})
serialPort.on('open', function () {
  console.log('Communication is on!')
})

The Arduino code is as follows:

#include <SoftwareSerial.h>
SoftwareSerial mySerial(12, 13); // RX, TX
int x = 0;
int y = -30000;
int z = 0;
String data;
char command = 'q';
int left = 0;
int right = 0;
int left_pwm = 0;
int right_pwm = 0;

void setup() {
  mySerial.begin(9600);     // opens serial port, sets data rate to 9600 bps
  Serial.begin(9600);
  }
void loop() {//map and compass data
if (y==30000) {
 mySerial.println('c');
 delay(5);
 mySerial.println(299);
 delay(5);
 z = -25000;
 }

 if(z==30000){
 mySerial.println('lon');
 delay(5);
  mySerial.println(529);
  delay(5);
  mySerial.println('lat');
 delay(5);
   mySerial.println(522);
          y = -30000;
    }
  y++; z++;

  if (!mySerial.available()) {
    return;
  }

  data = mySerial.readString();
   sscanf(data.c_str(), "%c%01d%01d%03d,%03d", &command, &left, &right, &left_pwm, &right_pwm);

  if (command == 'n') { // we got a navigation command
    // update the GPIO accordingly, this only happens once after a new 'n' command has been received
    Serial.print(command);
    Serial.print(left);
    Serial.print(right);
    Serial.print(left_pwm);
    Serial.print(",");
    Serial.println(right_pwm);
    }

    }////end loop


texts: How to Control 2-wire Rotary-Gear Linear Actuator

texts: Any ideas how to control a 2-wire DC 5V 10mm Stroke Mini Linear Actuator based Rotary Gear Motor? Most linear actuators (aside from solenoids) are controlled via 3-4 wires. Do I need a separate motor controller for the actuator to control it via an Arduino Uno?


texts: Can I connect my arduino ground to an external battery ground? Are they the same when said battery is powering the arduino?

texts:
I need to power my camera peripheral with an external power supply, since apparently I can't power both the camera and the camera's relay switch with my 5V out pin (My relays cut out and continually reset themselves if I try to run my 5V to both the camera relay switch and the relay board VCC.)

So I'm powering the camera with a 5V battery pack and my arduino with my PC, but I still need to communicate with it via UART, so I need the camera ground to be the same as my arduino ground. Can I connect the two? Is this a bad idea? Because I'm doing it now and it seems to work. I just don't want to cause a problem later on down the road, whether I'm connected to my computer or on battery power.Any advice would be greatly appreciated.


texts: I want to make my stepper motor work for 1 hour

texts:
I already tried code that makes the stepper motor work for a few minutes only. I'm using a clock module, a DS1302 and the stepper library already present. Also the driver I'm using is an L298n. If someone could help out it would be nice. Thanks.

#include <Stepper.h>
#include <virtuabotixRTC.h>

virtuabotixRTC myRTC(5, 6, 7);
const int stepsPerRevolution = 200;
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

const int OnHour = 12;
const int OnMin = 52;
const int OffHour = 12;
const int OffMin = 55;

void setup() {
  Serial.begin(9600);
  myStepper.setSpeed(100);
}

void loop() {
  myRTC.updateTime();
  Serial.print(myRTC.dayofmonth); //You can switch between day and month if you're using American system
  Serial.print("/");
  Serial.print(myRTC.month);
  Serial.print("/");
  Serial.print(myRTC.year);
  Serial.print(" ");
  Serial.print(myRTC.hours);
  Serial.print(":");
  Serial.print(myRTC.minutes);
  Serial.print(":");
  Serial.println(myRTC.seconds);
  if (myRTC.hours >= OnHour && myRTC.minutes >= OnMin && myRTC.hours <= OffHour && myRTC.minutes < OffMin) {
    Serial.print(myRTC.hours);
    Serial.print(":");
    Serial.print(myRTC.minutes);
    Serial.print(":");
    Serial.println(myRTC.seconds);
    myStepper.step(stepsPerRevolution);
  }
}


texts: Controlling a digital 12V addressable RGB led strip with Arduino?

texts: I have a 12V addressable RGB strip that I want to control with an Arduino, the chips are ws2811s, is there a way to do this as the Arduino is 5V and 3.3V?


texts: initial power output in the digital io pins of an Arduino controller

texts:
I am a newbie..  I am integrating Arduino controller with Matlab

I have connected my arduino DUE board in COM7. And I have also connected a DC Motor in one of the digital output pins (D3)

So when I just execute the matlab built in arduino function to initialise or establish a connection my motor runs for a second and then stops. I dont want my motor to run initially. Is there a solution or an alternative to do this.

a = arduino('COM7', 'Due');

Thanks in advance.


texts: how to know the channel i receive information from when i use nRF24L01 to connect between 3 of them

texts:
i am using nRF24L01 to connect between 3 of them ( 1 is master and the others are slaves) and i am using nRF24 library , my problem is that when the master receive something from the other slaves and do not know from which channel the infromation come so is there is a way to know from which channel

//master channel code:
  const byte addresses[][6] = {"00001", "00002","00003"};
  radio.openWritingPipe(addresses[1]); // mastr
  radio.openReadingPipe(2, addresses[0]); // carwl
  radio.openReadingPipe(2, addresses[2]); // carwl2

//slave 1 channel code :
  const byte addresses[][6] = {"00001", "00002","00003"};
  radio.openWritingPipe(addresses[0]); // carw1
  radio.openReadingPipe(2, addresses[1]); // mastr

//slave 2 channel code:
  const byte addresses[][6] = {"00001", "00002","00003"};
  radio.openWritingPipe(addresses[0]); // 00003
  radio.openReadingPipe(2, addresses[2]); // 00002

library i use: https://github.com/nRF24/RF24


texts:
I installed LininoIO (OS dated 02 06 2015).

Everything seems to work fine - but nothing works as expected.

I have a running Linux - but when I try to use GPIO, as described on Lilino.org -GPIO on lininoIO, I run into the first problems.

D13 doesn't exist (this should be the little red LED on board of the Yún).

Next I tested reading the analog inputs.

I can for example use cat /sys/bus/iio/devices/iio:device0/in_voltage_A0_raw. There are no errors, but I always get the value 0.

Checking with /etc/linino/test_avrdude.sh shows:

Testing AVRDUDE on ATMEL 32U4 ...

avrdude: Version 6.1-20140519, compiled on Jun  2 2015 at 12:34:59
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2014 Joerg Wunsch

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

         Using Port                    : unknown
         Using Programmer              : linuxgpio
Can't export GPIO 11, already exported/busy?: Device or resource busy
avrdude done.  Thank you.

Maybe this is "by design" or another sign of an error.

By the way - when I start a serial console I get the message:

avr-uart: switched to uart mode: mcuio

Further in kernel log I found:

[   42.480000] fuse init (API version 7.18)
[   42.620000] spi_tty_plain spi1.0: spi_tty_probe
[   45.380000] No need to change console settings
[   49.550000] mcuio-hc 0:0.0: unexpected reply
[   49.600000] gpiochip_add: registered GPIOs 100 to 139 on device: generic
[   49.630000] mcuio adc is 0:1:1
[   49.750000] mcuio-adc 0:1.1: 6 input channels detected
[   49.910000] mcuio-hc 0:0.0: unexpected reply
[   49.970000] mcuio pwm is 0:1:2
[   49.970000] mcuio-pwm 0:1.2: 6 pwm outputs detected
[   55.790000] busybox: sending ioctl 5310 to a partition!
[   55.800000] busybox: sending ioctl 5310 to a partition!
[   55.820000] busybox: sending ioctl 5310 to a partition!
[   55.830000] busybox: sending ioctl 5310 to a partition!
[   56.290000] EXT4-fs (sda2): couldn't mount as ext3 due to feature incompatibilities
[   56.310000] EXT4-fs (sda2): couldn't mount as ext2 due to feature incompatibilities
[   56.360000] EXT4-fs (sda2): mounted filesystem with ordered data mode. Opts: (null)
[   58.520000] cfg80211: Calling CRDA for country: AT

It seems as if there are problems with mcuio-hc.

Last thing - when I ran run-avrdude /etc/linino/bathos-one.hex
I get an error when comparing the written data (I found information that this can be ignored).

How can I fix this / find out what to fix / what's going wrong?


texts: How to setup HC05 Module to be distinguishable

texts:
I'm not sure if this is a dumb question, but here goes  :

I am developing an Android app that uses a custom Bluetooth device as a companion. I'm using an HC05 module to interface the device with my app. What I need is a way for me to distinguish my HC05 module from, say, some other HC05 module that might be in range.

The obvious way of doing this would be to set the device name in a certain format. But I was wondering if there was a more better approach to this.

On searching, I found that UUID's are used for a similar purpose (i.e. service discovery), but I couldn't find any further info. Is it at all possible to set a custom UUID for the HC05 module so that I can filter devices in my Android app based on that?


texts:
I am using an amazing code to send/read infrared pulses without any external library. The code is fine and I took about 1 hour to fully understand it. The only thing I didnt understand is the variable RESOLUTION. I believe it should be 0 not 20. I think it should be as low as possible.

You can see the code at:

https://learn.adafruit.com/ir-sensor/using-an-ir-sensor

or below:

/* Raw IR decoder sketch!
This sketch/program uses the Arduino and a PNA4602 to
decode IR received. This can be used to make a IR receiver
(by looking for a particular code)
or transmitter (by pulsing an IR LED at ~38KHz for the
durations detected
Code is public domain, check out www.ladyada.net and adafruit.com
for more tutorials!
*/

// We need to use the 'raw' pin reading methods
// because timing is very important here and the digitalRead()
// procedure is slower!
//uint8_t IRpin = 2;
// Digital pin #2 is the same as Pin D2 see
// http://arduino.cc/en/Hacking/PinMapping168 for the 'raw' pin mapping
#define IRpin_PIN PIND
#define IRpin 2
// for MEGA use these!
//#define IRpin_PIN PINE
//#define IRpin 4

// the maximum pulse we'll listen for - 65 milliseconds is a long time
#define MAXPULSE 65000

// what our timing resolution should be, larger is better
// as its more 'precise' - but too large and you wont get
// accurate timing
#define RESOLUTION 20

// we will store up to 100 pulse pairs (this is -a lot-)
uint16_t pulses[100][2]; // pair is high and low pulse
uint8_t currentpulse = 0; // index for pulses we're storing

void setup(void) {
  Serial.begin(9600);
  Serial.println("Ready to decode IR!");
}

void loop(void) {
  uint16_t highpulse, lowpulse; // temporary storage timing
  highpulse = lowpulse = 0; // start out with no pulse length

// while (digitalRead(IRpin)) { // this is too slow!
    while (IRpin_PIN & (1 << IRpin)) {
     // pin is still HIGH

     // count off another few microseconds
     highpulse++;
     delayMicroseconds(RESOLUTION);

     // If the pulse is too long, we 'timed out' - either nothing
     // was received or the code is finished, so print what
     // we've grabbed so far, and then reset
     if ((highpulse >= MAXPULSE) && (currentpulse != 0)) {
       printpulses();
       currentpulse=0;
       return;
     }
  }
  // we didn't time out so lets stash the reading
  pulses[currentpulse][0] = highpulse;

  // same as above
  while (! (IRpin_PIN & _BV(IRpin))) {
     // pin is still LOW
     lowpulse++;
     delayMicroseconds(RESOLUTION);
     if ((lowpulse >= MAXPULSE) && (currentpulse != 0)) {
       printpulses();
       currentpulse=0;
       return;
     }
  }
  pulses[currentpulse][1] = lowpulse;

  // we read one high-low pulse successfully, continue!
  currentpulse++;
}

void printpulses(void) {
  Serial.println("\n\r\n\rReceived: \n\rOFF \tON");
  for (uint8_t i = 0; i < currentpulse; i++) {
    Serial.print(pulses
* RESOLUTION, DEC);

    Serial.print(" usec, ");
    Serial.print(pulses[1] * RESOLUTION, DEC);
    Serial.println(" usec");
  }

  // print it in a 'array' format
  Serial.println("int IRsignal[] = {");
  Serial.println("// ON, OFF (in 10's of microseconds)");
  for (uint8_t i = 0; i < currentpulse-1; i++) {
    Serial.print("\t"); // tab
    Serial.print(pulses[1] * RESOLUTION / 10, DEC);
    Serial.print(", ");
    Serial.print(pulses[i+1][0] * RESOLUTION / 10, DEC);
    Serial.println(",");
  }
  Serial.print("\t"); // tab
  Serial.print(pulses[currentpulse-1][1] * RESOLUTION / 10, DEC);
  Serial.print(", 0};");
}


texts:
I'm writing a helper class to manage timers, and I'm writing a lot of code like

if (timer == 1)
        ICR1 = icr;
    else if (timer == 3)
        ICR3 = icr;
    else if (timer == 4)
        ICR4 = icr;
    else if (timer == 5)
        ICR5 = icr;

Is there a better way to store these registers?
e.g. an array

timers {
{ ICR1, TCCR1A, OCR1A, OCR1B },
{ ICR2, TCCR2A, OCR2A, OCR2B }

etc.

to be accessed like

timers[1][0]

for ICR1.

And ultimately, how would I assign a value? e.g.

*timers[1][0] = 100;

UPDATE:

I solved the problem with

volatile uint16_t* ICRs[5];
ICRs[1] = &ICR1;
ICRs[3] = &ICR3;
ICRs[4] = &ICR4;
ICRs[5] = &ICR5;

*ICRs[1] = x;


texts: Arduino -> Processing conversion: creating mux channels


texts:
The USB cable that came with the Arduino board is not easily recognized by the computer for selecting the appropriate COM port,
For powering the Arduino it works fine (the board will light up when plugged), so why it is not easily recognized by the computer in the device manager?


texts:
This is probably a simple question but I am a beginner with these things. What does the micro C part of the circuit diagram mean? The diagram is from the datasheet of the tssp77038 IR receiver. Does it want there to be a capacitor on the output?
(http://www.farnell.com/datasheets/1915248.pdf?_ga=1.234529246.1943069395.1480959857)


texts: Every time I connect the Arduino Uno to the Mac through USB port, the Mac restarts. Why is this happening? How can Arduino make such a sophisticated machine reset? This also happens with my ESP12E Node MCU.


texts:
I want to use the Arduino IDE using a raspberry pi with raspbian OS because it's the only way I can read a Digispark usb (I don't have 2.0 usb ports in my laptop so I can't read the usb with it).
I installed arduino IDE 1.8.13 so I can add the Digistump package. The problem I got is that when I try to add the drivers from the link http://digistump.com/package_digistump_index.json, it returns Tool micronucleus is not available for your operating system..
I donwloaded micronucleus using
git clone https://github.com/micronucleus/micronucleus

and installed it. Now I have it but I don't know how the arduino IDE could detect it. Could someone help me on how to make the arduino IDE understand I have it (micronucleus) installed?


texts: Make a Robotic Arm move straight not curved

texts:
I am planning on a project that includes a robotic arm controlled by Arduino. A simplified program of this would be:

A robotic arm picks up an object
The robotic arm then moves the object in a straight line
The robotic arm releases the object

The problem with this is that every robotic arm that I have seen works with servos, which rotate precisely within 0 and 180 degrees. But, because the robotic arm moves with servos, it then moves in a curved path, rather than the desired straight path.

The two paths in this problem appear in this image. The one on the left is the desired, but the one on the right is the one that occurs when using any robotic arm.

Is there any way to make the robotic arm move in a straight path? Is there a specific robotic arm that moves in straight lines rather than curved lines?

Thanks for any help!

Here is the link to an example of a robotic arm picking up an object and moving in a curved path, and not a desired straight path.


texts:
This is the atmega328p code that is supposed to send a predefined message repeatedly.

#include <avr/io.h>
#include <util/delay.h>

#define BAUD 9600
#define BAUD_PRESCALLER (((F_CPU / (BAUD * 16UL))) - 1)

void USART_init(void) {
    UBRR0H = (uint8_t) (BAUD_PRESCALLER >> 8);
    UBRR0L = (uint8_t) (BAUD_PRESCALLER);
    UCSR0B = (1 << RXEN0) | (1 << TXEN0);
    UCSR0C = (3 << UCSZ00);
}

void USART_send(unsigned char data) {
    while (!(UCSR0A & (1 << UDRE0)));
    UDR0 = data;
}

unsigned char USART_receive(void) {
    while (!(UCSR0A & (1 << RXC0)));
    return (unsigned char) UDR0;
}

void USART_putstring(char *StringPtr) {
    while (*StringPtr != 0x00) {
        USART_send((unsigned char) *StringPtr);
        StringPtr++;
    }
}

char String[] = "Hello world!!";

int main(void) {
    USART_init();
    while (1) {
        USART_putstring(String);
        _delay_ms(1000);
    }
    return 0;
}

If I try and listen to my serial port screen /dev/tty.wchusbserial141120 9600, only unicode nonsense comes back.

���

I am not quite sure what's the issue here.


texts: Arduino code not working properly (Please Help)

texts:
I am having some trouble getting my board to perform the function I want it to perform. This is a project I have due in a few days, and I have hit a wall I just can't seem to get past. Now, I will say the issue is definitely in the way I coded the program, but I don't really know enough about Arduino (and coding) to understand why it is not working. My board is properly hooked up to use 3LEDs, a speaker, a photoresistor, and an ultrasonic sensor (detects distances). My Arduino program takes serial input from a GUI that I created in MATLAB. I have verified the MATLAB code is good, and the serial port is communicating properly. I have made an alarm that goes off when light or motion is detected. It has 3 basic functions:

Set the alarm
Turn off the alarm
"snooze" which just delays for 5 minutes and then the alarm goes off

The snooze and turn off alarm parts of my code are working great, but the set alarm is where I am having trouble. The snooze option sets off the yellow LED to verify it is on "snooze". The red LED comes on when the alarm is currently going off. The green LED comes on when the alarm is set. When I try to activate the "Set Alarm" function, which is case 'O' in a switch case, the light does come on, but the sensors are not picking up any input as far as I can tell. Again I have verified the pins and everything are set up correctly as I have isolated those and verified they work. I have a suspicion that the problem is because I have the sensors initialed within the switch case of the "Set Alarm" (case 'O', not 0). I don't really know how to get the sensors to run continually within that switch case until the "turn alarm off" case is activated. I need the sensors to be activated/reset by "Set Alarm" case.
**I am also new to this forum so please let me know if I am missing anything!
here is my code:

void setup()
{
  Serial.begin(115200);
  pinMode(12,OUTPUT); //RED
  pinMode(13,OUTPUT); //GREEN
  pinMode(14,OUTPUT); //YELLOW
  pinMode(16,OUTPUT); //SPEAKER
  pinMode(4,INPUT); //Echo
  pinMode(2,OUTPUT); //Trig
}

void loop()
{
 if(Serial.available() >0)
 {
 char b = Serial.read();

  switch(b)
  {
    //Turn Alarm off
    case 'A' :
    {
    digitalWrite(12,LOW);//red off
    digitalWrite(13,LOW); // green off
    digitalWrite(14,LOW); //yellow off
    noTone(16);
    delay(500);
    }
    break;

    // Set alarm
    case 'O' :
    {
      int light;
  light = analogRead(0);
  unsigned long distance;
    digitalWrite(2,LOW);
  delayMicroseconds(2);
  digitalWrite(2,HIGH);
  delayMicroseconds(10);
  digitalWrite(2,LOW);
  distance = pulseIn(4,HIGH);
  distance = distance/58; //centimeters
  delay(500);

    digitalWrite(12,LOW); //red off
    digitalWrite(14,LOW); //yellow off
    digitalWrite(13,HIGH); //green on

  if (light < 400)
    {
     digitalWrite(12,HIGH);//red on
    digitalWrite(13,LOW); // green off
    digitalWrite(14,LOW); //yellow off
    tone(16,832);
    delay(500);
    }

  if (distance < 50)
    {
     digitalWrite(12,HIGH);//red on
    digitalWrite(13,LOW); // green off
    digitalWrite(14,LOW); //yellow off
    tone(16,832);
    delay(500);
    }

    }
    break;

    // snooze option
    case 'Z' :
    {
    digitalWrite(14,HIGH); //yellow on
    digitalWrite(12,LOW); //red off
    digitalWrite(13,LOW); // green off
    noTone(16);
    delay(300000UL);
    digitalWrite(12,HIGH); //red on
    digitalWrite(13,LOW); // green off
    digitalWrite(14,LOW); //yellow off
    tone(16,832);
    delay(500);
    }
    break;
   }

  }
}

Any help would be very much appreciated!


texts: Trying to get my HC-06 to work. The idea is to control a addressable RBG LED strip in the future. Currently I'm using a Arduino UNO, some wires and a HC-06. I connect the VCC pin to 5V, GND to GND, RXD to TX and TXD to RX. The module has a red light flashing for a second and after that nothing happens. Any idea what I should do next?


texts: RGB Matrix flickering every ~5 seconds when paired with SoftwareSerial

texts:
I'm running an RGB matrix through an Uno and trying to run it alongside SoftwareSerial so that I can integrate an ESP8266 into things. The trouble is, when I start introducing the SoftwareSerial into things, the screen flickers every few seconds, consistently. For example, with this function, it flickers exactly every 10 seconds. Any ideas what might be causing this or how to fix it?

Below is the arduino code. The RGB matrix is configured like this.

#include <RGBmatrixPanel.h>
#include <SoftwareSerial.h>

#define CLK  8   // USE THIS ON ARDUINO UNO, ADAFRUIT METRO M0, etc.
//#define CLK A4 // USE THIS ON METRO M4 (not M0)
//#define CLK 11 // USE THIS ON ARDUINO MEGA
#define OE   9
#define LAT 10
#define A   A0
#define B   A1
#define C   A2
#define setDelay 500

RGBmatrixPanel matrix(A, B, C, CLK, LAT, OE, false);

SoftwareSerial mySerial(11, 12); // RX, TX

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

  Serial.println("Start Serial!");

  // set the data rate for the SoftwareSerial port
  mySerial.begin(9600);
  mySerial.println("Hello, world?");

  matrix.begin();
}

void loop() {

  // draw a pixel in white
  matrix.drawPixel(0, 0, matrix.Color333(7, 7, 7));
  delay(setDelay);

  // fix the screen with green
  matrix.fillRect(0, 0, 32, 16, matrix.Color333(0, 7, 0));
  delay(setDelay);

  // draw a box in yellow
  matrix.drawRect(0, 0, 32, 16, matrix.Color333(7, 7, 0));
  delay(setDelay);

  // draw an 'X' in red
  matrix.drawLine(0, 0, 31, 15, matrix.Color333(7, 0, 0));
  matrix.drawLine(31, 0, 0, 15, matrix.Color333(7, 0, 0));
  delay(setDelay);

  // draw a blue circle
  matrix.drawCircle(7, 7, 7, matrix.Color333(0, 0, 7));
  delay(setDelay);

  // fill a violet circle
  matrix.fillCircle(23, 7, 7, matrix.Color333(7, 0, 7));
  delay(setDelay);

  // fill the screen with black
  matrix.fillScreen(matrix.Color333(0, 0, 0));

  // draw some text!
  matrix.setCursor(1, 0);  // start at top left, with one pixel of spacing
  matrix.setTextSize(1);   // size 1 == 8 pixels high

  // print each letter with a rainbow color
  matrix.setTextColor(matrix.Color333(7,0,0));
  matrix.print('1');
  matrix.setTextColor(matrix.Color333(7,4,0));
  matrix.print('6');
  matrix.setTextColor(matrix.Color333(7,7,0));
  matrix.print('x');
  matrix.setTextColor(matrix.Color333(4,7,0));
  matrix.print('3');
  matrix.setTextColor(matrix.Color333(0,7,0));
  matrix.print('2');

  matrix.setCursor(1, 9);  // next line
  matrix.setTextColor(matrix.Color333(0,7,7));
  matrix.print('*');
  matrix.setTextColor(matrix.Color333(0,4,7));
  matrix.print('R');
  matrix.setTextColor(matrix.Color333(0,0,7));
  matrix.print('G');
  matrix.setTextColor(matrix.Color333(4,0,7));
  matrix.print("B");
  matrix.setTextColor(matrix.Color333(7,0,4));
  matrix.print("*");
  }


texts:
I have a Nokia 5110 screen using u8gliv. I have it displaying an image and I can get it to display text:

   u8g.setFont(u8g_font_osb18);
   u8g.drawStr(0, 20, "PRESS START");

The problem is that this font size is way too big. How can I make it smaller? Do I have to use different fonts? If so how do I do that?


texts: strcmp() returns 0 when chars are different

texts:
I am trying to build a sketch that reads a single number from the Serial Monitor and uses it to light a 7 segment display with this number.

I need to compare the input with the known values, stored in a char array, to know which character was typed in and associate the matching binary combination to light the 7 segment display.

I have made a sample code extracted from the sketch, just to test if I am able to pass a char and get the correct result back:

char nums[] = "0123456789."; // The characters we will check against

/* Tried also these, same results
      char nums[12] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '\0'};
      char nums[] = "456789.0123";
*/

void setup() {
  Serial.begin(9600);
  Serial.println("Write a single character"); Serial.println(" ");
}

void loop() {
  if (Serial.available() > 0) {
    char text = Serial.read(); // Read a single char from serial
    Serial.print("Character provided is: "); Serial.println(text);
    char c = parseChar(text); // Evaluate the char
    Serial.print("Character returned is: "); Serial.println (c);
    if (strcmp(c, text) == 0) { // Check if the returned char is the same
      Serial.print("      CORRECT character returned");
    } else {
      Serial.print("      WRONG character returned");
    }
    Serial.println(" ");
  }
}

char parseChar(char c) {
  int comp = 0;
  Serial.println("----- parseChar() START-----");
  Serial.print("  Parameter 'c' is: "); Serial.println(c);
  for (int i = 0; i < sizeof(nums) ; i++) { // Check the values of the array one by one
    comp = strcmp(c, nums[i]); // Compare the chars
    Serial.print("  Compare to nums["); Serial.print(i); Serial.print("] = "); Serial.print(nums[i]); Serial.print(" --> Result: "); Serial.println(comp);

    /* If the check matches, return the character at that index.
       For simplicity, it just returns the matching char of the array,
       that should be the same as the one sent in to the function.
    */
    if (comp == 0) {
      Serial.println("----- parseChar() END (found) -----");
      return nums[i];
    }
  }
  Serial.println("----- parseChar() END (not found)-----");
  return 0;
}

The function works well for all numbers from 0 to 6. However, for any number over 6, or any other character, the strcmp() function returns always 0, so the returned character is the index 0 of the array, regardless of the character typed.

This is the Serial Monitor output for different characters:

Write a single character

Character provided is: 3
----- parseChar() START-----
  Parameter 'c' is: 3
  Compare to nums[0] = 0 --> Result: 1
  Compare to nums[1] = 1 --> Result: 1
  Compare to nums[2] = 2 --> Result: 1
  Compare to nums[3] = 3 --> Result: 0
----- parseChar() END (found) -----
Character returned is: 3
      CORRECT character returned

Character provided is: 6
----- parseChar() START-----
  Parameter 'c' is: 6
  Compare to nums[0] = 0 --> Result: -6
  Compare to nums[1] = 1 --> Result: 1
  Compare to nums[2] = 2 --> Result: 1
  Compare to nums[3] = 3 --> Result: 1
  Compare to nums[4] = 4 --> Result: 1
  Compare to nums[5] = 5 --> Result: 1
  Compare to nums[6] = 6 --> Result: 0
----- parseChar() END (found) -----
Character returned is: 6
      CORRECT character returned

Character provided is: 7
----- parseChar() START-----
  Parameter 'c' is: 7
  Compare to nums[0] = 0 --> Result: 0
----- parseChar() END (found) -----
Character returned is: 0
      WRONG character returned

Character provided is: g
----- parseChar() START-----
  Parameter 'c' is: g
  Compare to nums[0] = 0 --> Result: 0
----- parseChar() END (found) -----
Character returned is: 0
      WRONG character returned

As you can see, the parseChar() function never returns a "not found" result, even for chars that are not in the array. In fact, it never loops through the array, as the first comparison returns 0 always.

I can't figure out why the strcmp() function returns 0 when the chars are different. Am I missing something?


texts:
Trying to shift out from ATtiny85 to a shift register using the USI in SPI mode. I have Timer 0 running as slowly as possible (checked it was running by temporarily changing it to toggle a pin with an LED attached.) I have LEDs hooked up to USCK and DO so by rights I should be able to see them blinking as it sends.

What else do I need to do in order to get it shifting out in sync with Timer 0? All the examples I've looked at so far strobe the USI clock manually.

#include <avr/io.h>

int main(void){
    DDRB = (1 << DDB2) | (1 << DDB1); // USCK & DO Output
    DDRB &= ~(1 << DDB0); // DI Input
    PORTB |= (1 << DDB0); // Pullup Resistor for DI

    TCCR0A = (1 << WGM01); // Timer 0 in CTC Mode
    OCR0A = 0xFF; // Timer 0 Compare A
    TCCR0B = (1 << CS02) | (1 << CS00); // Prescaler / 1024

    USICR = (1 << USIWM0); // USI 3 Wire Mode
    USICR |= (1 << USICS0); // Timer 0 for USI 4-bit Clock Source

    USIDR = 0x7F; // Why you no go? :c

    USISR |= 0x08; // Set Counter to 8
    USISR = (1 << USIOIF); // Clear Counter Overflow

    while(1);
    return 0;
}


texts:
I'm trying to set up SPI communication between two Arduinos (UNO and Mega),
I want to read the status of the slave output pin from the master.

I connected a diode to pin 9 of Mega and I wanted to display its state on the virtual terminal of the master (Uno). The problem is that when the LED flashes I do not receive values just at the terminal level but when I hold it to zero or 1 the display is correct.
I used another code I found online.

MASTER code

#include <SPI.h>
const byte btn =8;

void setup(void) {

Serial.begin (9600);
pinMode (btn, INPUT_PULLUP);
digitalWrite (SS, HIGH);
SPI.begin ();
SPI.setClockDivider (SPI_CLOCK_DIV8);

}

void loop(void) {

byte Mvalsent,Mvalreceived;
digitalWrite (SS, LOW);
for (int jj=0; jj<255; jj++)
  {
      Mvalsent =jj;
      Mvalreceived =SPI.transfer (Mvalsent);
      Serial.print ("Retou d'etat ");
      Serial.print (Mvalsent);
      Serial.print ("\t ,l'etat de la diode est ");
      Serial.println (Mvalreceived);
      delay (400);
  }

  digitalWrite (SS,HIGH);

}

SLAVE Code

#include <SPI.h>
byte state;
const byte led =9;
volatile boolean process_it;
volatile byte Svalreceived, Svalsent;
int jj=0;
void setup (void)
{
  Serial.begin (9600);
pinMode (led,OUTPUT);
//set MISO pin as output
pinMode (MISO, OUTPUT);
//turn on SPI in slave mode
SPCR |= _BV (SPE);
//get ready for an interrupt
process_it = false;
//now turn on interrupts
SPI.attachInterrupt ();
}
ISR (SPI_STC_vect)
{
  Svalreceived = SPDR;
  process_it =true;
}
void loop (void)
{
 if (process_it)
 {

   digitalWrite (led, LOW);
   state =digitalRead(led);
   SPDR = state;
   Serial.print("l'etat de la diode est: ");
    Serial.println (state);
    delay (400);

    process_it =false;
  }
}


texts: I2C Wire.write function doesn't seem to work

texts:
Using the simplest code possible to test the library:

#include <Wire.h>

void setup()
{

  Wire.begin(); // join i2c bus

  Wire.beginTransmission(44); // transmit to device #44 (0x2c)
                              // device address is specified in datasheet

  Wire.write(0xA);             // sends value byte
  Wire.write(0xA);             // sends value byte
  Wire.write(0xA);             // sends value byte

  Wire.endTransmission();     // stop transmitting
}

But my data (three test byte of 0xA) is not getting sent. See image. As you can see, I get start bit, address, and then the stop bit. No data. Where am I going wrong?


texts:
I want my Attiny85 to communicate with another attiny85.
one attiny should send a message to my other attiny. When he receives the correct message he should turn one led on. Just a very simple test scatch.
I don't know why but the led never turns on.

Here is my code:

1st attiny85:

int clk_pin = 4,
    data_pin = 3,
    led = 0;

void setup() {
  pinMode(clk_pin, INPUT);
  pinMode(data_pin, INPUT);
  pinMode(led, OUTPUT);
}

void loop() {
  byte incoming = shiftIn(data_pin, clk_pin, LSBFIRST);

  if (incoming == 2)
  {
    digitalWrite(led, HIGH);
    delay(1000);
    digitalWrite(led, LOW);
    delay(1000);
  }
}

2nd attiny:

int clk_pin = 0,
    data_pin = 1;

void setup(){
  pinMode(clk_pin, OUTPUT);
  pinMode(data_pin, OUTPUT);
}

void loop(){
  byte test = 2;
  shiftOut(data_pin, clk_pin, LSBFIRST, test);

  delay(5000);
}

I think there might be something wrong with my shiftIn/shiftOut command. It's actually the first time I'm using this.

Thanks for helping!


texts: Does anyone know how to connect 2 digipots to Arduino? (MCP4141)

texts: I'm struggling with getting the code right. I'm trying to connect 2 digipots (MCP 4141) to Arduino to work separately over SPI. Has anyone got any experience with that?


texts:
With reference from http://www.gammon.com.au/i2c I tried the example there. However I am getting the wrong response and readings. At startup the Master will request for slave address. I should get a reading of "8" but I don't get it. Subsequently, A0 on the slave is connected to a miniature solar panel, that I have tested and it is working, however I keep getting a value -1 from it. No doubt I did modify a little bit to suit my inputs not sure if what I did affected the program.

This is the master code:

    #include <Wire.h>

const int slaveAddressA = 8;

enum {
  cmd_slaveAddress = 1,
  cmd_read_A0 = 2,
  cmd_read_A1 = 3
};

void sendCommand_toSlaveA (const byte cmd, const int responseSize)
{
  Wire.beginTransmission(slaveAddressA);
  Wire.write(cmd);
  Wire.endTransmission();

  Wire.requestFrom(slaveAddressA, responseSize);
}

void setup() {

  Wire.begin();
  Serial.begin(9600);

  sendCommand_toSlaveA(cmd_slaveAddress, 1);

  if(Wire.available())
    {
     Serial.print ("Slave address is: ");
     Serial.println (Wire.read (), DEC);
    }
  else
    {
     Serial.println ("No response to slave address request");
    }

}

void startupTest() {
  Wire.beginTransmission(slaveAddressA);

}

void loop() {

  int val;

  sendCommand_toSlaveA(cmd_read_A0, 2);
  val = Wire.read();
  val <<= 8;
  val |= Wire.read();
  Serial.print("Value of A0: ");
  Serial.println(val, DEC);

  delay(500);

}

This is the slave code:

#include <Wire.h>

const byte my_address = 8;

enum{
  cmd_address = 1,
  cmd_read_A0 = 2,
  cmd_read_A1 = 3
};

char command;

void setup() {

  command = 0;

  pinMode (A0, INPUT);
  digitalWrite (A0, LOW);  // disable pull-up
  pinMode (A1, INPUT);
  digitalWrite (A1, LOW);  // disable pull-up

  Serial.begin(9600);

  Wire.begin (my_address);
  Wire.onReceive (receiveEvent);  // interrupt handler for incoming messages
  Wire.onRequest (requestEvent);  // interrupt handler for when data is wanted
}

void loop(){
  //everything is done using interrupts
}

void receiveEvent(int howMany)
{
  command = Wire.read();
}

void sendSensor (const byte which)
{
  int val = analogRead (which);
  byte buf [2];

    buf [0] = val >> 8;
    buf [1] = val & 0xFF;
    Wire.write (buf, 2);
}

void requestEvent ()
{
  switch (command)
  {
    case cmd_address: Wire.write(0x55); break;   // send slave address
    case cmd_read_A0: sendSensor(A0);   break;   // send A0 value
    case cmd_read_A1: sendSensor(A1);   break;   // send A1 value

   }

}

Also I'm wondering if I have to add a "Wire.begin(8);" at the slave program setup. ---------------------------I would like to know what did I do wrongly?

UPDATE: The 2 boards are now communicating with one another. However, requested address gives a '85' instead of an '8'. As for input A0, for example it should show '700' with a little bit of variant, but now it shows a repeated pattern of e.g '0 0 0 400 500 800 1040 1040 1040 800 500 400 0 0 0'


texts: Using Arduino Sensors with STM32 based NUCLEO boards

texts:
Right now I'm programming an Arduino Uno Rev3, I'm using a Sensor Shield v5 (image at the bottom) to be able to have several Ultrasonic sensors and Servos. Right now I'm thinking about getting a Nucleo board, due to the better CPU, more memory and more flash. Although on the page, Arduino compatibility is listed, I don't quite understand what it means in my case. I understand that it has the same pins as the Arduino, but can I be sure that my Sensor Shield (v5) will work?

I found too little resources about this, one concern was that Arduino and Nucleo board have separate needs (3V or 5V), but the Sensor Shield can get power separately. (Lower right corner.)

Also, there is a Bluetooth shield for the Nucleo, I will buy it if I buy the Nucleo board, how can I know that it will work with the Sensor Shield? Or how can I know how many shields can I connect to a Nucleo or an Arduino?


texts: Which wireless technology should I use for medium range, many to one, bidirectional communication?

texts:
Some clients, let's say 5 <= x <= 10, have to send information wirelessly to a server. Transmission does not need to be reliable (ACK).

The range would be between 50 and 100m, and may include soft obstacles like trees, cars, etc, but not major ones like whole buildings or concrete walls.

Also, as I plan to build about 20 clients, the price should be as low as possible.

Thoughts?


texts: Hello I want to make a simple home automation project and I'd like to use an arduino uno for prototyping and later a atmega for deployment. I need some sort of a mesh communication method. I was thinking about the NRF51822 chip but I can't find any arduino libraries for it.


texts: How to check if a GSM module is working or not?

texts: I wanted to know if my GSM sim800 is working or not. A mishap occured while I was experimenting around with my GSM module and I arduino uno. The link to the module which I bought: http://www.ebay.in/itm/SIM800-Quad-Band-GSM-Module-with-SMA-Antenna-Better-than-SIM900A-or-SIM900-/301782413058?hash=item4643a22f02:g:8LsAAOSwwbdWMidW I want to know ow can I check if my module is fine?


texts: How much time does the Arduino need to call a Function or to read a Variable?

texts:
How much time does an Arduino Uno or Mega need to only call a function. And how does the time change if this function is inside a Class, for example inside a Library?

The same thing for a variable. How much time does a micro-controller need to read a declared variable?

How to determine this values? Is there a mathematic formula? Can we predetermine this type of delays and other similar micro-controller related delays?


texts: How can I convert PID correction values to an PWM brushless command?

texts:
Please I'm working on a quadcopter, and I have to made my own flight controller based on arduino uno.
First of all please how can I get a filtred angular velocity and linear acceleration from the MPU6050, is the following code give us the angular velocity in deg/sec and the linear velocity in m/s² ?

accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);

and is this pid value in this following code is right ?

  accel_reading = ax;
  accel_corrected = accel_reading - accel_offset;
  accel_corrected = map(accel_corrected, -16800, 16800, -90, 90);
  accel_corrected = constrain(accel_corrected, -90, 90);
  accel_angle = (float)(accel_corrected * accel_scale);

  err = angle_setpoint - accel_angle  ;

  P = Kp * err ;
  I += (Ki * err) ;
  D = Kd * (err - errp);

  pid = P + I + D;

Thank you.


texts: Why do I have to open Serial Monitor to display what is in loop function?

texts:
Why do I have to open Serial Monitor to display non-NaN values retrieved from DHT22,
what am I doing wrong in the code below?

#include <DHT.h>
#include <Wire.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
// OLED display TWI address
#define OLED_ADDR   0x3C
// reset pin not used on 4-pin OLED module
Adafruit_SSD1306 display(-1);  // -1 = no reset pin
// 128 x 64 pixel display
#if (SSD1306_LCDHEIGHT != 64)
#error("Height incorrect, please fix Adafruit_SSD1306.h!");
#endif
#define DHTPIN D3
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup() {

Serial.begin(115200);
delay(100);
  dht.begin();
  pinMode (DHTPIN, OUTPUT);
  /// initialize and clear display
  display.begin(SSD1306_SWITCHCAPVCC, OLED_ADDR);
  display.clearDisplay();
  //  display.drawRect(1, 1, display.width()-1, display.height()-1, WHITE);   // draws the outer rectangular boundary on the screen
  display.display();
  // display a pixel in each corner of the screen
  display.drawPixel(0, 0, WHITE);
  display.drawPixel(127, 0, WHITE);
  display.drawPixel(0, 63, WHITE);
  display.drawPixel(127, 63, WHITE);
  // display a line of text
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(20, 18);
  display.print("Welcome");
  display.setCursor(25, 40);
  display.print("San");

  // update display with all of the above graphics
  display.display();
}
void loop() {
  // put your main code here, to run repeatedly:
  float h = dht.readHumidity();
  float t = dht.readTemperature();
  display.clearDisplay();
  display.setTextSize(1);
  display.setTextColor(WHITE);
  display.setCursor(0, 1);
  display.print("Showing Temperature");
  // display Temperature
  display.setTextSize(2);
  display.setTextColor(WHITE);
  display.setCursor(1, 18);
  display.print("T : ");
  display.print(t);
  display.setTextSize(1);
  display.print((char)247);
  display.setTextSize(2);
  display.print("C");
  display.setCursor(1, 40);
  display.print("H : ");
  display.print(h);
  display.print(" %");
  // update display with all of the above graphics
  display.display();
}

After uploading code it does will display NaN but when I open serial monitor it works fine displaying actual values from DHT22  :o

below is the fritzing of the hookup, I do not have witty cloud in fritzing, so I have used wemos D1Mini instead. on wemos d1 mini 3v3 is VCC on witty cloud dev board.

It looks like loop function doesn't execute by itself unless I open the serial monitor, why is it so? please help


texts:
In my Uno code, I access to a page in my server and retrieve that value and make decision upon that value.

I get this kind of response,

Connected to server
on
on
off
off
on
off
[WiFiEsp] TIMEOUT: 116

Disconnecting from server.

Which should just be on or off.

This is my code for testing :

#include "WiFiEsp.h"

// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(2,3); // RX, TX
#endif

char ssid[] = "RPi";            // your network SSID (name)
char pass[] = "raspberry";        // your network password
int status = WL_IDLE_STATUS;     // the Wifi radio's status

char server[] = "192.168.50.1";

// Initialize the Ethernet client object
WiFiEspClient client;

int c =0;
int testLED = 12;

void setup()
{
  pinMode(testLED, OUTPUT);
  // initialize serial for debugging
  Serial.begin(9600);
  // initialize serial for ESP module
  Serial1.begin(9600);
  // initialize ESP module
  WiFi.init(&Serial1);

  // check for the presence of the shield
  if (WiFi.status() == WL_NO_SHIELD) {
    Serial.println("WiFi shield not present");
    // don't continue
    while (true);
  }

  // attempt to connect to WiFi network
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: ");
    Serial.println(ssid);
    // Connect to WPA/WPA2 network
    status = WiFi.begin(ssid, pass);
  }

  // you're connected now, so print out the data
  Serial.println("You're connected to the network");

  printWifiStatus();

  Serial.println();
  Serial.println("Starting connection to server...");
  // if you get a connection, report back via serial
  if (client.connect(server, 80)) {
    Serial.println("Connected to server");
    // Make a HTTP request
    client.println("GET /simple.txt HTTP/1.1");
    client.println("Host: localhost");
    client.println("Connection: close");
    client.println();
  }
}

void loop()
{
  // if there are incoming bytes available
  // from the server, read them and print them
  if (client.available()) {
     c = client.read();

     switch(c){
          case '0':
                 Serial.println("off");
                 digitalWrite(testLED, LOW);
                 delay(2500);
                 break;

          case '1':
                 Serial.println("on");
                 digitalWrite(testLED, HIGH);
                 delay(2500);
                 break;
      }
        }

  // if the server's disconnected, stop the client
  if (!client.connected()) {
    Serial.println();
    Serial.println("Disconnecting from server...");
    client.stop();

    // do nothing forevermore
    while (true);
  }
}

void printWifiStatus()
{
  // print the SSID of the network you're attached to
  Serial.print("SSID: ");
  Serial.println(WiFi.SSID());

  // print your WiFi shield's IP address
  IPAddress ip = WiFi.localIP();
  Serial.print("IP Address: ");
  Serial.println(ip);

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

My simple.txt file just has 1.

Why this code outputs a gibberish value? Is it a problem with the way I retrive data?
Raspberry pi is working as my network server.

Thanks in advance.


texts: DHT 11 sensors and i2c LCD to Wemos Wifi not Working

texts:
Its my first time make arduino project. I make wemos d1  project using DHT11 temperature sensor and LCD 20x4 with i2c. The temperature data will display in LCD and sending to the bot telegram. For sending to the bot telegram it works, but why the data cannot display to the LCD? When I tried common charachter like "Hello World!" in the LCD it works. Can you help me? What should I do? Thanks before.

#include "DHT.h"
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x3F,2,1,0,4,5,6,7,3, POSITIVE);
#define DHTPIN D14
#define DHTTYPE DHT11

byte degree[8] = {
  0b00110,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000,
  0b00000
};

DHT dht(D14, DHT11);

void setup() {
  lcd.createChar(0, degree);
  Serial.begin(115200);
  Serial.println("DHT11 test!");
  lcd.begin (20, 4);
  dht.begin();
}

void loop() {
  delay(2000);
  float h = dht.readHumidity();
  float t = dht.readTemperature();

  lcd.setCursor(0, 0);
  lcd.print("Humi : ");
  lcd.print(h);
  lcd.print(" %");

  lcd.setCursor(0, 1);
  lcd.print("Temp : ");
  lcd.print(t);
  lcd.print(" C");
}


texts: Sensirion library for SHT7x humidity sensor

texts:
I have following code (and it works great!) for SHT75 Sensirion sensor.

/*
 * Example code for SHT1x or SHT7x sensors demonstrating blocking calls
 * for temperature and humidity measurement in the setup routine and
 * non-blocking calls in the main loop.  The pin 13 LED is flashed as a
 * background task while temperature and humidity measurements are made.
 * In addition, the sensor may be placed in low resolution mode by
 * uncommenting the status register write call in setup().
 */

#include <Sensirion.h>

const uint8_t dataPin =  2;            // SHT serial data
const uint8_t sclkPin =  3;            // SHT serial clock
const uint8_t ledPin  = 13;            // Arduino built-in LED
const uint32_t TRHSTEP   = 3000UL;     // Sensor query period
const uint32_t BLINKSTEP =  250UL;     // LED blink period

Sensirion sht = Sensirion(dataPin, sclkPin);

uint16_t rawData;
float temperature;
float humidity;
float dewpoint;

byte shtState = 0;
byte ledState = 0;

unsigned long curMillis;               // Time interval tracking
unsigned long trhMillis = 0;
unsigned long blinkMillis = 0;

void setup()
{
  Serial.begin(9600);
  pinMode(ledPin, OUTPUT);
  delay(15);                           // Wait at least 11 ms before first cmd
//  sht.writeSR(LOW_RES);                // Set sensor to low resolution
  sht.measTemp(&rawData);              // Maps to: sht.meas(TEMP, &rawData, BLOCK)
  temperature = sht.calcTemp(rawData);
  sht.measHumi(&rawData);              // Maps to: sht.meas(HUMI, &rawData, BLOCK)
  humidity = sht.calcHumi(rawData, temperature);
  dewpoint = sht.calcDewpoint(humidity, temperature);
  logData();
}

void loop()
{
  curMillis = millis();

  if (curMillis - blinkMillis >= BLINKSTEP) {    // Time to toggle the LED state?
    ledState ^= 1;
    digitalWrite(ledPin, ledState);
    blinkMillis = curMillis;
  }

  switch (shtState) {
  case 0:
    if (curMillis - trhMillis >= TRHSTEP) {      // Start new temp/humi measurement?
      sht.meas(TEMP, &rawData, NONBLOCK);
      shtState++;
      trhMillis = curMillis;
    }
    break;
  case 1:
    if (sht.measRdy()) {                         // Process temperature measurement?
      temperature = sht.calcTemp(rawData);
      sht.meas(HUMI, &rawData, NONBLOCK);
      shtState++;
    }
    break;
  case 2:
    if (sht.measRdy()) {                         // Process humidity measurement?
      humidity = sht.calcHumi(rawData, temperature);
      dewpoint = sht.calcDewpoint(humidity, temperature);
      shtState = 0;
      logData();
    }
    break;
  default:
    Serial.println("How did I get here?");
    break;
  }
}

void logData() {
  Serial.print("Temperature = ");   Serial.print(temperature);
  Serial.print(" C, Humidity = ");  Serial.print(humidity);
  Serial.print(" %, Dewpoint = ");  Serial.print(dewpoint);
  Serial.println(" C");
}

How can I extend it for two sensors (by using of another pins, of course)?


texts:
I am having trouble figuring out the pinout of my 6 - pin USBasp Chinese clone that I got off eBay.
BEFORE YOU TELL ME TO LOOK AT THE PINOUT DIAGRAMS, I can tell you that my version of the usbasp has no way of telling which way is up and which ways is down. Images:


texts: How can I add additional boards to Eclipse with the Arduino add-on with only a URL, not a zip file

texts:
I want to add the following boards:

https://redbearlab.github.io/arduino/package_redbearlab_index.json

Which I can add in the Arduino IDE by going to File -> Preferences -> Additional Boards Manager URLs and just pasting it there

Where is the equivalent function in Eclipse, or how do I configure Eclipse to allow me to develop for those boards?

From Eclipse, I have tried Window-> Properties -> Arduino and from there "Private Library Path" and "Private hardware path", and I have tried pointing them to "C:\Program Files (x86)\Arduino\hardware" and "C:\Program Files (x86)\Arduino\libraries", but that didn't seem to change anything (i.e. no new board options, even after running Eclipse as admin) - while the boards show up (examples and all) in the Arduino IDE


texts: Do motors need to have capacitor even if being used with motor shield

texts:
I'm using a 12V DC geared motor with an Adafruit motor shield which is connected to Arduino.

So, I want to know inspite of using the motor shield, do I need to add capacitors to the motor?


texts: real-time reading of a quadrature encoder at full resolution with only one interrupt on ATmega328

texts:
I want to read a quadrature rotary encoders at full resolution with only one interrupt on Arduino Nano (ATmega328). So I found out that we can use XOR to reach a full resolution:

Where pin 3 is interruptable but 4 and 5 are not.

Our requirements are:

Full resolution: for example, the solution offered in this answer works at a half-resolution only, not detecting all the edges.
Real-time: being as fast as possible up to the level that this hardware allows and safe in terms of not missing any of the signal edges.
using only one interrupt. We need the other one for other purposes.

So far, I have developed two different codes, one aiming for safety and the other for performance:

Preamble:

#include "digitalWriteFast.h"

#define pinT 3 // trigger pin comming from XOR

#define pinA 4 // channel A
#define pinB 5 // channel B

volatile long counter = 0;
long counter_ = counter;

where the digitalWriteFast library can be downloaded from here.

Performant:

volatile short int increment = 0;
volatile bool tmpA;
volatile bool tmpB;
volatile bool lastA;

ISR(trigger) {
  tmpA = digitalReadFast(pinA);
  tmpB = digitalReadFast(pinB);
  counter += (1 - 2 * tmpA) * (1 - 2 * tmpB) * (1 - 2 * (lastA != tmpA));
  lastA = tmpA;
}

void setup() {
  pinMode(pinA, INPUT_PULLUP);
  pinMode(pinB, INPUT_PULLUP);
  pinMode(pinT, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(pinT), trigger, CHANGE);
  lastA = digitalReadFast(pinA);
  Serial.begin(9600);
}

void loop() {
  if (counter != counter_) {
    Serial.println(counter);
    counter_ = counter;
  }
}

Safe:

volatile unsigned long error = 0;
unsigned long error_ = 0;

volatile bool inputA;
volatile bool inputB;

volatile short state; // 100 110 101 111
volatile short state_;

void detectState() {
  inputA = digitalReadFast(pinA);
  inputB = digitalReadFast(pinB);

  if (inputA) {
    if (inputB) {
      state = 111;
    } else {
      state = 110;
    }
  } else {
    if (inputB) {
      state = 101;
    } else {
      state = 100;
    }
  }
}

ISR(trigger) {

  detectState();

  if (state_ != state) {
    switch (state_) {
      case 100:
        if (state == 110) {
          counter++;
        } else if (state == 101) {
          counter--;
        } else {
          error++;
        }
        break;
      case 110:
        if (state == 100) {
          counter--;
        } else if (state == 111) {
          counter++;
        } else {
          error++;
        }
        break;
      case 101:
        if (state == 100) {
          counter++;
        } else if (state == 111) {
          counter--;
        } else {
          error++;
        }
        break;
      case 111:
        if (state == 110) {
          counter--;
        } else if (state == 101) {
          counter++;
        } else {
          error++;
        }
        break;
      default:
        error++;
        break;
    }

    state_ = state;
  } else {
    error++;
  }
}

void setup() {
  pinMode(pinT, INPUT_PULLUP);
  attachInterrupt(digitalPinToInterrupt(pinT), trigger, CHANGE);

  pinMode(pinA, INPUT_PULLUP);
  pinMode(pinB, INPUT_PULLUP);

  detectState();
  state_ = state;

  Serial.begin(9600);
}

void loop() {
  if (counter != counter_) {
    Serial.print("counter: ");
    Serial.println(counter);
    counter_ = counter;
  }

  if (error != error_) {
    Serial.print(error);
    Serial.println(" errors");
    error_ = error;
  }
}

Now my questions are:

Is there any way to improve the speed/safety of the performant/safe code? Any way to improve this code is appreciated.
Is it possible to have maximum speed and safety together or some trade-off in between?
What is the maximum frequency we can get out of this configuration?

Thanks for your help in advance.


texts: Declare for loop as an array of variables

texts:
My goal is to store the variable in the for loop as an array rather than as a single 'ultrasoundValue'. Can some one help me structure the code?

I have this code:

int ultraSoundSignalPins[] = {5,7};
int tx = 4;
char *pingString[] = {"Ping1 ","Ping2 "}; // just something to print to             indicate direction

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

void loop()
{

 unsigned long ultrasoundValue;
 for(int i=0; i < 2; i++)
 {
   ultrasoundValue = ping(i);
   Serial.print(pingString[i]);
   Serial.print(ultrasoundValue);
   Serial.print("cm, ");
   delay(500);

 }
}

//Ping function
unsigned long ping(int i)
{
 unsigned long echo;

 pinMode(ultraSoundSignalPins[i], OUTPUT); // Switch signalpin to output
 pinMode(tx, OUTPUT);
 digitalWrite(ultraSoundSignalPins[i], LOW); // Send low pulse
 digitalWrite(tx, LOW);
 delayMicroseconds(2); // Wait for 2 microseconds
 digitalWrite(ultraSoundSignalPins[i], HIGH); // Send high pulse
 digitalWrite(tx, HIGH);
 delayMicroseconds(5); // Wait for 5 microseconds
 digitalWrite(ultraSoundSignalPins[i], LOW); // Holdoff
 pinMode(ultraSoundSignalPins[i], INPUT); // Switch signalpin to input
 digitalWrite(ultraSoundSignalPins[i], HIGH); // Turn on 0pullup resistor
 echo = pulseIn(ultraSoundSignalPins[i], HIGH); //Listen for echo
 return (echo / 29.1); //convert to CM then to inches
}


texts:
I am trying to upload longitude and latitude data into MySQK using a GPRS shield, Arduino Uno R3 and a GPS module. The idea is to get longitude and latitude data from the GPS and use the GPRS to post the information into my database.

I have to insert the latitude and longitude data into the URL like  this steetalert.co.zw/write_data.php?Longitude=12.124311,Latitude=27,766785. Values for longitude and latitude have to be dynamic not static. How do I go about this?


texts:
Is the Atmel STK500 worth using as a AVR programmer and Dev board? I am starting to get to into AVR programming with Atmel studio. I plan on purchasing the AVRDragon and also looking into purchasing the Atmel STK500. This might be too broad of a question, but are their any benefits in using the Atmel STK500?

Atmel STK500


texts:
I've a exhaust fan that runs when the humidity is high. When the exhaust fan is on it should work for 3 minutes and should wait another 5 minutes to on. I am a beginner to this struggling for almost 2 days now. with this code the led just blink and off
int ledPin =  2;      // the number of the LED pin
int ledState = LOW;             // ledState used to set the LED
unsigned long previousMillis2 = 0;
unsigned long previousMillis = 0;
long interval = 10000;           // in
long OnTime = 1000;           // milliseconds of on-time
long OffTime = 2000;          // milliseconds of off-time

void setup()
{

  Serial.begin(9600);
  // set the digital pin as output:
  pinMode(ledPin, OUTPUT);
}

void loop()
{

  unsigned long currentMillis2 = millis();

  if (currentMillis2 - previousMillis2 > interval) {
    // save the last time you blinked the LED

    // check to see if it's time to change the state of the LED
    Serial.print("hellohh ");
    unsigned long currentMillis = millis();

    if ((ledState == HIGH) && (currentMillis - previousMillis >= OnTime))
    {
      Serial.print("hellohh2 ");
      ledState = LOW;  // Turn it off
      previousMillis = currentMillis;  // Remember the time
      digitalWrite(ledPin, ledState);  // Update the actual LED
    }
    else if ((ledState == LOW) && (currentMillis - previousMillis >= OffTime))
    {
      Serial.print("hellohh 3");
      ledState = HIGH;  // turn it on
      previousMillis = currentMillis;
      previousMillis2 = 0; // Remember the time
      digitalWrite(ledPin, ledState);    // Update the actual LED

    }
  }
}


texts: Which Arduino microcontrollers are able to drive a parallel 8-bit ILI9341 display at 320x240@60fps with DMA or extra CPU core or both and how?

texts:
I've always wanted to make my own game console. I don't know why the existing Arduino game consoles have this issue with framerate when a 2006's Sony handheld PC had 1GB of RAM and an Intel CPU running Windows XP. Why haven't normal DIY open-sourcing copyright-libertarian hobbyists been able to make something at that magnitude? Don't say money because money is the reason I'm in gamedev scene; wanting to make a game console or anything that has a screen, characters, multimedia and nerdiness to make money.

So the issue has always been how do I find a microcontroller that's enough fast to run a 320x240 display like ILI9341 at 60FPS without stuttering or having to do lots of precalculations for partial screen updates. What about the NES/SNES consoles which didn't even have a framebuffer but which used discrete logic?

My scheme was to use ATXMEGA128A1U with a parallel bus and DMA, but it was hard to find a board containing all the stuff I needed and the External Bus Interface.
Then I tried to use ESP32 with SPI, but SPI would go max to 80MHz while the screen could only handle 40MHz.
Then I tried ESP32 again with 8-bit IO pin permutation which didn't work; it was too slow; maybe it would be faster if I used Xtensa assembly to take advantage of the CPU pipeline in case the dumb C++ compiler compiled machine code that waited 7 cycles for every next operation.
But now I'd like to use ESP32 with an I2S bus and DMA which was used for a camera demo and it was really really fast, but I'd like to use it for I2S output for that ILI9341 display. According to my calculations, it should take 10MHz to write out all of the bytes if the bus is 16-bit wide (8 bits for data and 1 bit for Data/Command register) + Read/Write/Select strobes controlled by the bus interface. However, Bitluni has been able to drive it to out of spec values of 580MHz for his VGA library that's superfast, but that month he had nothing to pay his rent with so he licensed the code under a copyleft license (ShareAlike). You know what they say, "The love of money and the lack of money are the roots of all evil.". Money is important, but really... this just makes money an even worse enemy than it was before.

So I guess I'm out of options. There have been many attempts and they have failed. Yes, there's Teensy and stuff, but I need something in the EU which I won't have to pay for more in shipping than the actual product.

So, what are the solutions?

P.S. if I get one of those "off-topic" or "too-broad" or dislikes to my question, I'm deleting it and moving to Reddit and screenshooting how yet again StackExchange is just too formalistic and banhammersome to open conversations.


texts: Is there a portable timer interrupt library?

texts:
I have a need for timer interrupt (for the sake of this exercise - say I need to execute something every second)

I found code in many places on the internets that does this using ISR for 328/Uno.  (or specifically for other chips) But of course that does not work on other chipsets.

Is there a portable timer library that works across many/most/all arduino boards/chipsets?

For now it is a simple project - I have no other motors or tones, etc.

In my current project I have conditional compiles for different chipsets, to set up a callback/interrupt but would rather use a library that hides this all.


texts:
I can't access my Arduino Micro's USB programming port when it's in my project. I want to reroute the RX and TX pins outside to a serial-to-usb adapter.

I have this on hand from a while ago. I found the RX and TX pins in the serial connector and I connected them to the RX and TX pins of the Arduino as well as GND but when I try and program the device nothing happens. I usually get an open port error or something like that but the programming LED on the adapter doesn't light up. Conversely if I try using the Basic Stamp software I at least get a programming LED to light up on the adapter.

Do I need an FTDI breakout instead? Or am I wiring something wrong?


texts:
I am working on a project which requires use of 16bit timer . I am using Arduino Uno (Atmega 328p) board and Timer_1 (16 bit timer ) in Overflow mode. i want to use 1024 prescaler settings.

According to the datasheet of the controller i have to set [b]CS10 and CS12[/b] bits to use 1024 prescaler but the problem is OverFlow interrupt routine is never fired when 1024 or 256 prescaler is selected .

The Following code works just fine with Prescaler set to 8 or 64.

#include <inttypes.h>

volatile uint8_t sCount = 0;

void setup()
{
      Timer_one_16_init(); // configure the timer

      pinMode(13,OUTPUT);

}

void loop()
{
    // do nothing
}

void Timer_one_16_init(){

    TCCR1A = 0;

    // set the pre-scaler to 1024 (slowest)

    TCCR1B |= (1<<CS12)|(1<<CS10);

    // set the bottom / starting value

    TCNT1 = 0x00;

    // set Overflow interrupt

    TIMSK1 |= (1<<TOIE1);

    // enable global interrupt
    sei();

}

ISR(TIMER1_OVF_vect){

    sCount++;

    if (sCount == 60)
    {
        digitalWrite(13,!digitalRead(13));
        sCount = 0;

    }

}

i have no idea why this is happening. i have done everything which is given in the datasheet .

Am i doing something wrong ?

Thanks in advance


texts: Arduino Yun C++ environment? Bridge + Cross-Compiler

texts: I'm creating an XMPP chatbot for the Arduino Yun. However, I'm not too confident in the Python performance on such a low performance device and I'm much more comfortable with C++. Is there a C++ crosscompile environment available, and is there a port of the Bridge library to C++? Alternatively, documentation on how to interface with the ATMega using raw serial communication?


texts: Is a solenoid piston strong enough to lock a water tubling?

texts:
My question is about hardware that i'll control with my arduino... Not Arduino itself (So I don't know if I'm in the right section ... :s)

My project is to create a cocktail machine at the cheapest price.

I was wondering if this kind of solenoid piston would be strong enough to seals a plastic pipe like this one ?

My idea from now is to use only 1 water pump (as this one) and connect all the pipes from the bottles with some Y and control which one is giving the liquid by controling pistons that are going to compress the tube.

I'm open to all advices you could give me and new ideas ... I saw that there's also solenoid valves ... But I only find it in 12V ... Does it exist in 5V ?


texts: RadioHead Library custom configuration for RFM96 LoRa

texts:
I have a pair of Adafruit RFM96W LoRa Transceiver Breakouts and want to use them with the RadioHead library.

My pair of radios works if I use the example sketches from the adafruit tutorial, but I want to change their default configuration.

From the Datasheet of RFM96:

  For maximum flexibility the user may
  decide on the spread spectrum modulation bandwidth (BW),
  spreading factor (SF) and error correction rate (CR).

I want to configure the BF, SF and CR. I also want to be sure that the radios are working with the LoRa Modulation and that CRC is enabled.
And how to set Header-Settings?

I did find the method rf.setModemConfig() which gives the capability to change the configuration to library-pre-defined ones, which is not what I want. I want to try different combinations of settings.

I did find the method rf.setModemRegisters() but I did not understand how to use it.

Any solution is welcome.


texts:
I want drive a large number of LEDS from an Arduino Pro Mini using a number of TPIC6B595. I purchased these on ebay, perhaps a mistake.
Initially I connected two TPIC6B595 as I would connect 74HC595 (with the exception of taking account of how the open drain outputs work) to the SPI pins of an Arduino Mega (my test bench system) and tried sending an alternating bit pattern to the LEDs. No alternating LEDs. I checked SRCLR was Vcc and OE (G) was Gnd. I poked about with my scope (Rigol DS1102D)  and SRCK, RCK and SERIN looked as expected. Suspiciously SEROUT (pin 18) of the first chip was permanently LOW. Note that this is all on a breadboard.
I have used the 74HC595 now many times and from time to time I have made stupid mistakes in wiring/software. These usually stand out on the scope like a sore toe. Not this time.
So I decided to simplify it all and clock some data into a single TPIC6B595 using a simple non-SPI sketch and see if anything comes out of the SEROUT.
Here are the connections to the TPIC6B595 and to the Mega:
1 Not connected,  20  Not connected,
2 Vcc             19  Ground,
3 Arduino pin 12  18  Not connected (except to scope when tested),
4 Not connected   17  Not connected,
5 Not connected   16  Not connected,
6 Not connected   15  Not connected,
7 Not connected   14  Not connected,
8 Vcc             13  Arduino pin 11,
9 Ground          12 Ground (See note 1),
10 Ground         11  Ground.

The chip is bypassed by a 1uF electro across pins 2 and 10. Not ideal but the clock rates are low and it isn't unreliable, it just doesn't work at all.
Note 1: I am not trying to test the transfer between the Shift Register and the output D flip-flops so RCK should be irrelevant. I just want to see data going in to SER IN , coming out on SER OUT.
Here's the Arduino code. It generates a slow clock and an alternating data bit every few clock cycles:
const int ser_clk = 11; // blue
const int ser_in  = 12; // white
byte data, count;

void setup()
{
  pinMode(ser_clk, OUTPUT);
  pinMode(ser_in,OUTPUT);

  digitalWrite(ser_clk, LOW);
  digitalWrite(ser_in, LOW);

  count = data = 0;
}

void loop()
{
  digitalWrite(ser_clk, HIGH);
  delay(1);
  digitalWrite(ser_clk, LOW);
  delay(1);

  count++;
  if (count >= 3)
     {
       count = 0;
       if (data == 0)
          {
            data = 1;
            digitalWrite(ser_in, HIGH);
          }
       else
          {
            data = 0;
            digitalWrite(ser_in, LOW);
          }
     }
}

Here's a screenshot of the wave-forms (photo of scope - sorry can't make UltraScope work):

The cyan trace is the "clock" from pin 11 of the Arduino feeding pin 13 (SRCLK) of the TPIC6B595. The yellow trace is the data from pin 12 of the Arduino feeding pin3 (SER IN) of the TPIC6B595. I am only looking to get the same data pattern out of SEROUT, pin 18 of the TPIC6B595 and this should do it. The clock is as slow as a wet week (see cursor) and even if I have bad set up and hold times and the wrong transitions the data is held for enough cycles for something to make it through surely?? Pin 18 is persistently and forever low. No screenshot - seems to be no point.
I bought several of these TPIC6B595. Tried 3 so far. All the same. Now I might have killed them with static. I am not using wrist straps, but I also don't believe I could have killed 3 of them.
As improbable as that is I think they are dead or duds, or is there something else wrong that is so obvious I cannot see it?
Regards, Fred.