texts: Using shiftin() and shiftout() with the same circuit - what to consider?

texts:
I am designing a smart (or at least I hope so) onboard bicycle light system. The system will have an Arduino (currently prototyping with UNO) and a subsystem composed of a "panel" of buttons and leds.

This panel should stay at the handlebar, connected by multi-wire cable to the Arduino located elsewhere on the bicycle.

In order to read an arbitrary number of push-buttons, I plan to use CD4021 IC with shiftIn() function. And, in order to turn an arbitrary number of leds on and off, I plan to use 74HC595 IC and the shiftOut() function.

My doubts are: what should I consider in order to do so?

How many wires should I need to connect an arduino to the panel circuit containing the ICs? I believe it is 8 wires (two for the power, three for shifting in [latch, clock, data], and three for shifting out), right?
Can I use any pin I want? Or is it required to use specific pins?
Is that the "right way" of doing this? Any suggestion or improvement is welcome!


texts:
I am starting some Arduino's projects with different sizes (very small based on Arduino Nano and bigger using Arduino Mega). These projects will be manipulated by students and they will connect and disconnect many times the wires. I will try to not use breadboard if I can. In order to develop very versatile projects, the idea will be to use very useful plug sockets. Currently I have no idea of which kinds of plug sockets I can use.

Do you have any idea about the existing plug sockets (from 2 to 6/8 wires) and which one it is preferable to use?

Complements:

Some shields and components I already have and want to use have sometimes some plugs sockets (similar to this) but sometimes only some classical pins
I want also to build my own shields by integrating plug sockets to the arduino or to another shield
Some parts will be also composed by small electrical circuit on which I want to integrate plug sockets aswell
I will also use LiPo batteries (for example this one which have a connector I can't buy currently because I don't know the reference)
Communications will be also achieved using SPI and I2C


texts: Sending and receiving data using 433 Mhz from Arduino to Arduino

texts:
Following this tutorial: https://tutorials-raspberrypi.com/let-raspberry-pis-communicate-with-each-other-per-433mhz-wireless-signals/ I was able to easily send code from one Raspberry Pi Zero to another using a RF 433 MHz Transmissor, Receiver pair using the Ninjablock's 433Utils library.

Now I'm trying to do the same between two Arduinos UNO. I'm following the explanations of the library itself: https://github.com/ninjablocks/433Utils, but until now without success.

  Arduino_Sketches

  Place the Sketches in your normal Arduino Sketches location. Install
  any required libraries:

1) Servo motor library (Should be included in the Arduino IDE)
2) Arduino rc_switch library

The Arduino rc_switch library is installed in my Arduino IDE.

What I would like to confirm is the following:

While with the Raspberry Pis I go to the folder 433Utils/RPi_utils and type the command sudo ./RFSniffer in one terminal and sudo ./codesend 1234 in another what I have to do with the Arduinos?

Upload the sketch RF_Sniffer.ino to one Arduino and the sketch Send_Demo.ino to the other and watch in the Serial Monitor the inputs/outputs appearing as magic?

That's unfortunately not working. :-(

May I install anything else? Modules and wiring is OK.


texts: little Code problem Servocity SPT 400 tilt kit

texts:
I hope you are in a helpful mood, today.
I have run into a little problem with my project. I wanted to mount my camera on a Servocity SPT 400 tilt kit  and control the thing via a bluetooth connection. The setup is as follows I have an Arduino Uno V3 board with an HC - 05 bluetooth module and hooked a Hitec HS-5485HB servo to the board.
Pretty straightforward but I managed to make it work as intended so far.

Here is a picture of how everything is connected, since it partially works I think it's not completely wrong.
The problem starts here though, the Servocity SPT 400 tilt kit comes with an external potentiometer,
The instructions sheet says to cut the internal potentiometer cables that were connected to the servo circuits and solder the three cables (red, yellow and green) to the external potentiometer.
With the coding skills I made the tilt mechanism move a few mm but that was not the desired result.
So what I need is a working code that allows me to control the whole thing via bluetooth.
I don't know how to control a potentiometer into my noobish code.

#include <SoftwareSerial.h> // TX RX software library for bluetooth

#include <Servo.h> // servo library
Servo myservo; // servo name

int bluetoothTx = 10; // bluetooth tx to 10 pin
int bluetoothRx = 11; // bluetooth rx to 11 pin

SoftwareSerial bluetooth(bluetoothTx, bluetoothRx);

void setup()
{
  myservo.attach(9); // attach servo signal wire to pin 9
  //Setup usb serial connection to computer
  Serial.begin(9600);

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

void loop()
{
  //Read from bluetooth and write to usb serial
  if(bluetooth.available()> 0 ) // receive number from bluetooth
  {
    int servopos = bluetooth.read(); // save the received number to servopos
    Serial.println(servopos); // serial print servopos current number received from bluetooth
    myservo.write(servopos); // roate the servo the angle received from the android app
  }

}

I really would appreciate some help.


texts: Millisecond timestamp (13 digits) in Arduino

texts:
How can I store a 13 digits int in Arduino?

For example, current timestamp is:
1500666822235

An uint32_t can only hold 10 digits max.

64 bits integer does not seem to be supported on RFduino.


texts:
I'm new to Arduino/C development (coming from a JavaScript/Ruby environment), but I was wondering if it was possible to include a library from a custom folder within a sketch?

So this is my situation;

project.ino
libs/
  MyNewLib/
    MyNewLib.h
    MyNewLib.ccp

Now my question is: how can I include my custom library? I've tried several variations on this;

# project.ino

#include <libs/MyNewLib/MyNewLib.h>
#include "libs/MyNewLib/MyNewLib.h"
#include <./libs/MyNewLib/MyNewLib.h>
#include "./libs/MyNewLib/MyNewLib.h"

But none of them works. Can anyone tell me if this is possible? I've looked into this question around the web, but I can't find any satisfying answer. Hopefully you guys can help.

Cheers.

UPDATE

I'm aware you can put your libraries in your global libraries folder, but I want them in my local project folder. I want to share them through git with my team.


texts: How do I control arduino uno multiplexed digital pin (using HC74595)

texts:
Edit:

I moved the whole initial post to avoid misunderstanding and confusing everyone, sorry

after all the reading i came up with this:

this is my code for ultrasonic sensor that going into digital pins in my arduino:

int trigPin1=2;
int echoPin1=3;

void setup() {
  Serial.begin (9600);
  pinMode(trigPin1, OUTPUT);
  pinMode(echoPin1, INPUT);
}

void loop() {
  long duration1, distance1;
  digitalWrite(trigPin1, LOW);  // Added this line
  delayMicroseconds(10); // Added this line
  digitalWrite(trigPin1, HIGH);
  delayMicroseconds(15); // Added this line
  digitalWrite(trigPin1, LOW);
  duration1 = pulseIn(echoPin1, HIGH);
  distance1 = duration1/58;

  Serial.print (distance1);
  Serial.print (",");
  delay(100);
}

and this is the idea i wrote to set the "extra digital outputs" on the 595 chip:

int DS_pin = 8;
int STCP_pin = 9;
int SHCP_pin = 10;

void setup()
{ // put your setup code here, to run once:
  pinMode(DS_pin, OUTPUT);
  pinMode(STCP_pin, OUTPUT);
  pinMode(SHCP_pin, OUTPUT);
  writereg();
}

bool registers[8];

void writereg()
{
  digitalWrite(SHCP_pin, LOW);

  for (int i = 0; i<=7; i++)
  {
    digitalWrite(STCP_pin, LOW);
    digitalWrite(DS_pin,registers[1]);
    digitalWrite(STCP_pin, HIGH);
  }
    digitalWrite(SHCP_pin, HIGH);
}

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

}

now if you guys have a little time to check it, and tell me what should i wrote so the ultrasonic sensor will be working with the 595 chip's outputs?

Let say im going to put the Trigger pin into Q0 and Echo pin into Q1

thanks in advance


texts: Measuring li-ion that arduino is running from

texts:
I am using a 5v Arduino pro mini (with regulator and power led removed).
I have been reading how to accurately measure Li-ion batteries when powering from the same battery you are trying to measure from. Using the 1.1V internal analog reference to measure a draining VCC source by using a voltage divider on it, and math to show that converted reading.
Reading the Arduino forums I came across this answer.
  long readVcc() {
  long result;
  // Read 1.1V reference against AVcc
  ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
  delay(2); // Wait for Vref to settle
  ADCSRA |= _BV(ADSC); // Convert
  while (bit_is_set(ADCSRA,ADSC));
  result = ADCL;
  result |= ADCH<<8;
  result = 1126400L / result; // Back-calculate AVcc in mV
  return result;
}

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

void loop() {
  Serial.println( readVcc(), DEC );
  delay(1000);
}

However, I cant see a analogRead anywhere in this sketch. (Is this a strictly internal reference?)
At the bottom of the thread someone is saying that you can do this without a voltage divider on the analog pin.
Can someone confirm or explain this? I don't want to fry my Arduino...


texts: Preventing relay switch-off crashing Ethernet controller

texts:
I have an Arduino Uno with Ethernet Shield controlling some relays. Initially everything works fine but then when switching the relay off, the Ethernet controller frequently 'crashes'. Ethernet stops responding to pings, although the Arduino Uno keeps running. Pressing the reset button brings the Ethernet controller back to life.

I am using three relays to control:

The 'Call for Heat' contact on the boiler (normally connected to a thermostat)
A Honeywell V4043 zone valve (6W / 0.42A)
A Grundfos UPS2 underfloor heating pump (0.06A - 0.42A)

This is my setup:

I am using 2N7002 MOSFETs to drive the relays
I have 1N4004 diodes across the coils

There is a circuit diagram for the 'Relay Driver Shield' part of the circuit here:
https://github.com/njh/relay-driver-shield

This is what I have done to attempt to solve the problem:

I have moved the Arduino + Ethernet further away from the relays
I switched to higher quality Omron Relays (G2R-1-S-DC12)
I have tried both Wiznet W5100 and ENC28J60 Ethernet controllers

But so far nothing has solved the problem.

Of the three relays, it appears to be the Honeywell V4043 zone valve that is causing the problem. While testing with no loads connected to the relays, it was working fine. My assumption is that the problem is related to discharges across the contacts, partly due to the inductive loads. But I am not sure what to do to fix it.

Thanks,

nick.


texts:
Short version: This is a lighting control project.  Some of the clases are Pin and  Channel. Channel contains a Pin.  Pin is a base class for DigitalOutPin and will be the base class for AnalogOutPin, and I want Channel to be able to use any child of Pin.

Pin has an abstract method setPinValue(), but when I create a DigitalOutPin object and call setPinValue(), Pin.setPinValue() gets called, not DigitalOutPin.setPinValue() and my program doesn't work because Pin.setPinValue() is empty as it's supposed to be overwritten.

Long version:
If I leave out the definition of Pin.setPinValue(), I get that most idiotic of error gcc messages, "undefined reference to `vtable for Pin'".  If I make it pure virtual I get several errors in the form of

In file included from /devel/arduino/lightbright/LightBrightMain/LightBrightMain.ino:9:0:
/devel/arduino/libraries/LightBrightLib/Channel.h:21:20: error: cannot declare parameter 'pin' to be of abstract type 'Pin'
     void begin(Pin pin, int channelNumber);
                ^
In file included from /devel/arduino/libraries/LightBrightLib/DigitalOutPin.h:10:0,
             from /devel/arduino/lightbright/LightBrightMain/LightBrightMain.ino:8:
/devel/arduino/libraries/LightBrightLib/Pin.h:16:7: note:   because the following virtual functions are pure within 'Pin':
 class Pin
   ^
/devel/arduino/libraries/LightBrightLib/Pin.h:33:18: note:  virtual void Pin::setPinValue(int)
     virtual void setPinValue(int value)=0;
              ^
In file included from /devel/arduino/lightbright/LightBrightMain/LightBrightMain.ino:9:0:
/devel/arduino/libraries/LightBrightLib/Channel.h:23:9: error: invalid abstract return type for member function 'Pin Channel::getPin()'
 Pin getPin();
     ^
In file included from /devel/arduino/libraries/LightBrightLib/DigitalOutPin.h:10:0,
             from /devel/arduino/lightbright/LightBrightMain/LightBrightMain.ino:8:
/devel/arduino/libraries/LightBrightLib/Pin.h:16:7: note:   since type 'Pin' has pure virtual functions
 class Pin
   ^

Full code is at GitHub but here are the relevant parts:
Pin is declared like this right now as pure virtual, but I've tried with and without =0

class Pin
{
  public:
   ...
  protected:
   ...
  // This method is child-specific. It's empty in this base class
  virtual void setPinValue(int value)=0;
};

DigitalOutPin is declared as

class DigitalOutPin : public Pin
{
  public:
    void on();
    void off();
  protected:
    void setPinValue(int value);
};

and defined as

void DigitalOutPin::setPinValue(int value) {
....
}

Disclaimer: I'm primarily a Java developer so C++ OO is very different for me, but as far as I can tell this should work as designed.

Thanks for any advice you can offer.


texts: I was able to connect my HC-05, pair it with my phone, and I can see data in the Serial Bluetooth Terminal Android App.  But when I try to connect it to a certain application it says it cannot find it.  Can the application force a certain version of Bluetooth?  Am I missing something?  Thanks.


texts:
I am doing a project that requires me to program an arduino to sense changes of a steady stream of light due to the scattering of that light. If the phootodiode does change its resistance to the current, then a flap will turn a certain number of degrees. I'm not sure how to operate a photodiode, but know the basics of how it works.

The apparatus is designed to increase the operating life of a solar panel on Mars. When dust from a dust storm collects on its surface, a photodiode will detect the change in light and change its resistance to a current running through it. Then a flap connected to the solar panel will close to cover the solar panel. I'm using Hitec HS-311 Standard servo to rotate  the flap, but I've had some problems operating it.


texts: OSCOKIRQ failed to assert with USB HOST and SD card

texts:
I am having an issue using a MAX 3421 EE based Arduino USB Host shield and an SD card shield. From my understanding, they should both function as long as they are using different CS/SS pins and only one is active at a time. I have connected the SD card CS pin to pin 4. I am trying to write a program that reads an ACM terminal and writes that data to a file on the SD card (see code below). When the SD card is not powered the USB host shield reads the ACM and prints it to serial fine. However, immediately when I connect the SD card shield power, it starts printing "ACM not ready." On a reset, it prints "OSCOKIRQ failed to assert."

Troubleshooting steps I have already tried:

External power source.
Removing SD card from the reader.
Commenting out all SD Card code.
Disconnecting USB Device (to see if initialization still works)

None of these steps have helped solve the USB initialization issue.

My code:

//Lots of Code from https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/acm/acm_terminal/acm_terminal.ino
#include <cdcacm.h>
#include <usbhub.h>

#include "pgmstrings.h"

// Satisfy the IDE, which needs to see the include statment in the ino too.
#ifdef dobogusinclude
#include <spi4teensy3.h>
#endif

#include <SPI.h>
//#include <SD.h>

//https://github.com/felis/USB_Host_Shield_2.0.git
class ACMAsyncOper : public CDCAsyncOper{
public:
    uint8_t OnInit(ACM *pacm);
};

uint8_t ACMAsyncOper::OnInit(ACM *pacm){
    uint8_t rcode;
    // Set DTR = 1 RTS=1
    rcode = pacm->SetControlLineState(3);

    if (rcode)
    {
        ErrorMessage<uint8_t>(PSTR("SetControlLineState"), rcode);
        return rcode;
    }

    LINE_CODING lc;
    lc.dwDTERate    = 115200;
    lc.bCharFormat  = 0;
    lc.bParityType  = 0;
    lc.bDataBits    = 8;

    rcode = pacm->SetLineCoding(&lc);

    if (rcode)
        ErrorMessage<uint8_t>(PSTR("SetLineCoding"), rcode);

    return rcode;
}

const int USBChipSelect = 10;
USB     Usb;
//USBHub     Hub(&Usb);
ACMAsyncOper  AsyncOper;
ACM           Acm(&Usb, &AsyncOper);

const int SDChipSelect = 4;
/*
const int maxLog = 10000;
volatile int logged = 0;
volatile long name = 0;
*/
void setup()
{
    Serial.begin(115200);
    Serial.println("Start");

    pinMode(USBChipSelect, OUTPUT); // Sets USB CS pin output
    pinMode(SDChipSelect, OUTPUT); //Sets SD CS pin output
    digitalWrite(SDChipSelect,HIGH);
    digitalWrite(USBChipSelect,HIGH);

    USBActive();

    if (Usb.Init() == -1){
    Serial.println("OSCOKIRQ failed to assert");
  }

    delay(500);
}

void loop(){
    String toWrite = "Error";

    toWrite = readACM();
    Serial.println(toWrite);

    if(logged>=maxLog){
        logged = 0;
        name++;
    }
    /*
    SD.begin(SDChipSelect);
    File dataFile = SD.open(String(name), FILE_WRITE);
    if(dataFile){
        dataFile.println(toWrite);
        dataFile.close();
    }*/
    delay(100);
}

//Activates USB and Deactivates SD
void USBActive(){
    digitalWrite(SDChipSelect,HIGH);
    digitalWrite(USBChipSelect,LOW);
}

//Activates SD and Deactiavates USB
void SDActive(){
    digitalWrite(USBChipSelect,true);
    digitalWrite(SDChipSelect,false);
}

String readACM(){
  Usb.Task();

  if( Acm.isReady()) {
       uint8_t rcode;

        /* reading the phone */
        /* buffer size must be greater or equal to max.packet size */
        /* it it set to 64 (largest possible max.packet size) here, can be tuned down
        for particular endpoint */
        uint8_t  buf[64];
        uint16_t rcvd = 64;
        rcode = Acm.RcvData(&rcvd, buf);
         if (rcode && rcode != hrNAK)
            ErrorMessage<uint8_t>(PSTR("Ret"), rcode);

        if( rcvd ) { //more than zero bytes received
            char rcvdData[rcvd];
            for(uint16_t i=0; i < rcvd; i++ ) {
                rcvdData[i] = (char)buf[i]; //printing on the screen
            }
            return String(rcvdData);
        }
    }
    return String("ACM Not Ready");
}

Thanks in Advance.


texts: How to use a Pololu 5v AVR ISP Programmer to program an AVR at 3.3v

texts:
I have a Pololu 5v AVR ISP which I have successfully used to program several Arduinos (a Mega, an Uno and a Pro Mini 5v). I now have a new Arduino compatible clone which is basically a clone of the pro mini 3.3V.

I am wondering if anyone else has used this programmer to program a 3.3V board without issues. I've seen a forum post on pololu's forum which discusses modifications required - but I don't really understand what is necessary.

I've also found the software tool mentioned in the above forum post here and I have downloaded it and built it.

When I run the aforementioned tool I get these options:

PgmCmd: Configuration and status utility for the Pololu USB AVR Programmer.
Version: 1.0.1.0
Options:
 -l, --list             list available devices
 -d, --device SERIALNUM (optional) select device with given serial number
 -s, --status           display complete device status
     --freq NUM         sets the ISP frequency (in units of kHz)
     --linea ID
       or --lineb ID    set serial control signal associated with line A or B.
                        Valid IDs are: none, cd, dsr, ri, dtr, rts.
                        Warning: dtr and rts are outputs: -f option is required
     --swminor HEXNUM   AVR ISP software version minor (in hex, e.g. A)
     --swmajor HEXNUM   AVR ISP software version major (in hex)
     --hw HEXNUM        AVR ISP software hardware version (in hex)
     --vddmin NUM       set minimum allowed target vdd (units of mV)
     --vddmaxrange NUM  set maximum allowed target vdd range (units of mV)
     --restoredefaults  restore factory settings
     --bootloader       put device in to bootloader (firmware upgrade) mode

I then ran the --status option with the serial number of my programmer and got this:

Serial number:                  00048632
Firmware version:               1.07
Settings:
  ISP Frequency:                200 kHz
  Line A Identity:              None
  Line B Identity:              None
  AVR ISP hardware version:     F
  AVR ISP software version:     2.A
  Target VDD allowed minimum:   4384 mV
  Target VDD allowed max range: 512 mV
Last programming:
  Error: None
  Measured Target VDD Minimum:  N/A
  Measured Target VDD Range:    N/A
SLO-scope:
  State:                        Off
  Line A output:                Off
  Line B output:                Off

From this I deduced that my programmer is currently set at between about 4.38V and 4.89V which I presume corresponds to the 5V approximate voltage of the normal Arduino chips.

Given that the utility program allows me to set both the target minimum Vdd and the target Vdd max range should I therefore set it to something like a minimum of 2704 with a max range of 512 which should put the signal voltages at up to ~3.2V.

Is that all I have to do to get this to work?


texts:
I am trying to program a Pro Micro clone (black PCB, 5v), using this command

avrdude.exe -p atmega32u4 -c avr109 -U flash:w:pro_micro_ISP_B6_10.hex:i -P COM3

but this is the (obviously incorrect) output I get:

Connecting to programmer: .
Found programmer: Id = "╞ ("; type = b
    Software Version =  . ; Hardware Version =  .
avrdude.exe: error: buffered memory access not supported. Maybe it isn't
a butterfly/AVR109 but a AVR910 device?

It has never been flashed before. All three lights are illuminated when I plug it in. I am pretty sure COM3 is the right port.

What's going on here? Is my USB cable bad or something? I actually had this problem on two separate units, so I know the board itself is fine.


texts: 4 Pelteir Plate Water Bottle wired to Arduino Uno

texts:
Note - I plan to use the Arduino Starter kit to make this project.
Hey everyone,
I've had an idea for a project recently and I would like to get some insight on its plausibility. Is it possible to heat and cool a bottle of water using 4 pelteir plates? I'd like to heat up or cool a bottle of water using 2 pelteirs for heating and 2 for cooling. Could the amount of power for the peltiers to function be supplied from a laptop, computer, or battery pack? The role of the Arduino is to program in some safety features or some things to help the circuit function better if necessary. For example, a feature I want to add in is if the cold pelteirs are on, the hot peltiers are off if nessecary. I might add an LCD to display which setting is on/off if I can (example: Cold: ON, Hot: OFF)
Thanks guys.


texts:
Why my servo motor is always on?

#include <Servo.h>

Servo myservo;

int pos = 0;

void setup() {

pinMode(2, INPUT);
myservo.attach(9);

}

void loop() {

  if (digitalRead(2) == LOW) {

    for (pos = 0; pos <= 180; pos += 1) {
      myservo.write(pos);
      delay(15);
    }

    for (pos = 180; pos >= 0; pos -= 1) {
      myservo.write(pos);
      delay(15);
    }
  }
  else {
    myservo.write(0);
    delay(15);
  }
}


texts:
I have created a byte for 16x2 LCD. It is basically a custom character which I will have to change later.

byte char[8]{
 B10000,
 B01000,
 B00100,
 B00010,
 B00001,
 B11000,
 B11100
};

I want to edit the third number from fourth row. So, the fourth row will become B00110 from B00010. Is this possible? Are there any alternatives for this?


texts:
I'm working to make a simple pedometer with Arduino, and after managing to find an algorithm that correctly finds the steps, I added a bluetooth extension (the overly popular and cheap JY-MCU) to check the steps via bluetooth.
I am facing a strange issue, though: when the bluetooth device is powered and waiting for a connection (red led blinking) the analog read function that reads data from the accelerometer goes crazy (thus the pedometer finds a step each second or so). When the bluetooth is powered down or connected to a device such as a mobile phone this doesn't happen.
Did anyone have this problem before? What could be the issue? My setup is easy, you can see it on the image.

I had other sensors as well but since the problem stays even when there are only those two connected I posted the bare minimum setup.
At first I thought I could use some kind of pull-ups to stabilise the signal, but I really have no idea on where to tie them and if they can really be helpful at all...
Any help is appreciated.


texts:
I am attempting to calculate the time between pulses by comparing the micros() timestamp. I understand that you cannot just simply subtract unsigned longs, but I cannot understand what the alternative for it is.

Below is a simplified version of code. On pin 6 I receive 2ms long pulses every 2ms comparing the times returns "-19728". I'm planning to make the pulses much shorter once I figure out this math problem.

Site note: I'm using pulses to make two Arduinos send simple data via digital pins.

Thanks you.

int pinReceiver = 6;
int val = 0;
int isReceiving = 0;
int pauseLength = 0;
unsigned long timeStart = 0;

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

void loop() {
  noInterrupts();
  val = digitalRead(pinReceiver);

  if(val==HIGH){
    if(isReceiving==0){ //Pulse begins
      isReceiving = 1;
      pauseLength = micros() - timeStart;
      Serial.println(pauseLength);
    }

  } else {
    if(isReceiving==1){ //Pulse ends
      isReceiving = 0;
      timeStart = micros();
    }
  }
  interrupts();
}


texts: Arduino simultaneous push button for a counter

texts:
I am a newbie with arduino. I am trying to have a counter with 3 buttons. Each Button when pressed will increase the number of counts. The counter should still count if button 2 is pressed while button 1 has not been released, and button 3 should also be able to increase the counter even if button 2 and button 1 are still pressed.

My code below counts if only one button is pressed at a time.

#include <LiquidCrystal.h>
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
int pbutton1 = 2;
int pbutton2 = 3;
int pbutton3 = 4;
int count = 0;

void setup() {
  lcd.begin(16, 2);
  pinMode (pbutton1, INPUT);
  pinMode (pbutton2, INPUT);
  pinMode (pbutton3, INPUT);

  lcd.print("My Counter");
}

void loop() {

  lcd.setCursor(0, 1);
  lcd.print("Total ");
  if (digitalRead(pbutton1) == HIGH) {
    lcd.print(count++);
    while (digitalRead(pbutton1) == HIGH); //monitor button to avoid continous count
  }

  if (digitalRead(pbutton2) == HIGH) {
    lcd.print(count++);
    while (digitalRead(pbutton2) == HIGH); //monitor button to avoid continous count
  }

  if (digitalRead(pbutton3) == HIGH) {
    lcd.print(count++);
    while (digitalRead(pbutton3) == HIGH); //monitor button to avoid continous count
  }
}


texts: Using a toggle switch to run part of a sketch

texts:
First, I am a beginner for this.  I just ordered my first book on coding Arduino and I'm working through some simple applications using a DS3231 (that has a temperature reading), LCD, MicroSD card module, etc.  My board is a Uno R3.  Currently, I need a sketch to run part of a program which contains a loop to collect data and have this run when a toggle switch is turned on.  So, toggle goes on and part of program runs, toggle goes off and this part exits.
The reason I need a toggle with constant on/off is the problem with G forces and vibration.  I momentary push button input will not be reliable.  Ultimately, all the components will be in a amateur high-power rocket to run a roll control program.
If you can help, I greatly appreciate your assistance.


texts: Get more PCINT capable pins on Mega 2560

texts:
I'm building kinda "ball game" for a total of 6 players based on these per-player specs:

1 stepper motor with 4 pins
2 end stops (start & finish) per motor
1 finish LED
3 holes to score, resulting in slow, medium or fast motor movement

Additionally, there's a "master reset" to move all motors back to their starting end stops.
Because of my initial assumption, 54 pins would be enough, I didn't realize actually requiring 60 pins (24 for motors, 12 for end stops, 6 for LED, 18 for holes). I'm also neither an expert at microelectronics nor C programming language, but my understanding of the Mega's pins is that I need 12 + 18 PCINT capable pins (end stops + holes) while only 16 pins are available.
So far, the only information I could find suggests buying an Arduino Shield to resolve this by providing additional 16 PCINT pins. But being connected via I2C, I suspect delays resulting in unequal treatment of player scores.
How to get at least 30 PCINT capable pins, treated equally by Arduino? In case there's no need for the PCINT requirement, which pins can be used as an alternative?


texts: Does sharing code on Arduino Create automatically grant any license rights?

texts: I have code I am happy to share under a GNU GPL License and which is marked accordingly. Before I upload it to Arduino Create Web Editor I want to check whether in doing so I inadvertently grant additional license rights. I have searched for any terms and conditions which may inform me but not found any as yet.


texts: Arduino UNO(master read) + NANO(slave write) i2c buttons+stepper

texts:
First of all, I'm new to arduino. Check the EDIT line below the two codes.

I have connected motor shield to arduino uno. Connection between the two arduinos are A5 to A5, A4 to A4, 5V to 5V and GND to GND. I have a stepper connected to UNO, and a button connected to nano.

EDIT5: I deleted the messy previous codes, the question was answered.
However, I cant get the steppers to rotate(they only vibrate). Any advice is appreciated. The code right now is:

Master

#include <Wire.h>
#include <AFMotor.h>
//define steppers
AF_Stepper motor1(48, 1);
AF_Stepper motor2(48, 2);

//define variables
int x = 0;
int y = 0;

void setup()
{
  Wire.begin(5); //begin i2c communication
  Wire.onReceive(receiveEvent);
  motor1.setSpeed(10);  // 10 rpm
  motor2.setSpeed(10);  // 10 rpm

  motor1.release();
  motor2.release();
  delay(1000);
}

void loop()
{
  delay(500); // wait 0.5 second
}

void receiveEvent(int howMany)
{
    //read x,y from slave
    x = Wire.read();
    y = Wire.read();

    if (x == 1) //stepper1 rotate forward
    {
      motor1.step(100, FORWARD, SINGLE);
    }
    else if (x == 2) //stepper1 rotate backward
    {
      motor1.step(100, BACKWARD, SINGLE);
    }
     else if (y == 1) //stepper2 rotate forward
    {
      motor2.step(100, BACKWARD, SINGLE);
    }
     else if (y == 2) //stepper2 rotate backward
    {
      motor2.step(100, BACKWARD, SINGLE);
    }
}

Slave

#include <Wire.h>

//define buttons
const int button1 = 2;
const int button2 = 3;
const int button3 = 4;
const int button4 = 5;

//define state of buttons
int buttonState1 = 0;
int buttonState2 = 0;
int buttonState3 = 0;
int buttonState4 = 0;

//define variables
int x = 0;
int y = 0;

void setup()
{
   //start i2c communication
   Wire.begin();
}

void loop()
{
  //read state of buttons
  buttonState1 = digitalRead(button1);
  buttonState2 = digitalRead(button2);
  buttonState3 = digitalRead(button3);
  buttonState4 = digitalRead(button4);

    //if button1 is pressed,send x to master
    if(buttonState1 == HIGH){
      x = 1;
      Wire.beginTransmission(5);
      Wire.write(x);
      Wire.endTransmission();
    }
    //if button2 is pressed,send x to master
    else if(buttonState2 == HIGH)
    {
      x = 2;
      Wire.beginTransmission(5);
      Wire.write(x);
      Wire.endTransmission();
    }
    //if button3 is pressed,send y to master
    if(buttonState3 == HIGH){
      y = 1;
      Wire.beginTransmission(5);
      Wire.write(y);
      Wire.endTransmission();
    }
    //if button4 is pressed,send y to master
    else if(buttonState4 == HIGH)
    {
      y = 2;
      Wire.beginTransmission(5);
      Wire.write(y);
      Wire.endTransmission();
    }
}


texts: For Loop function to iterate through outputs after interrupt

texts:
I would like help to continuously loop over my output pins after each sleep cycle.  I am trying to increment through each output pin during each successive interrupt.  Introducing this myIteration function causes immediate incrementing to final output pin and eliminates sleeping.
EDIT
To clarify a bit and clean up the code, I am having trouble getting the loop to increment over the output pins each time the interrupt is triggered.  It stays on the initialized pin value after each interrupt.
The reason I separate the if (state=HIGH) into two consecutive statements is because when I do not the debug LED remains on.
#include <LowPower.h>

const byte interrupt_pin = 2;                             // declare interrupt pin for PIR trigger
int musicPins[] = {3, 4, 5, 6, 7, 8, 9, 10, 11};          // Initialize pins that play music in array, elements from 0 to 8
volatile byte state = LOW;                                // trigger threshold starts low
int pinCount = 9;
int previous = 0;

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);                           // use builtin LED for debug
  pinMode(interrupt_pin, INPUT);                          // set interrupt pin as input

    for (int thisPin = 0; thisPin < pinCount; thisPin++) {      // set all music pins as High to start with no music during sensor initialization
    digitalWrite(musicPins[thisPin], HIGH);
    }
    for (int thisPin = 0; thisPin < pinCount; thisPin++) {      // set all music pins as outputs
    pinMode(musicPins[thisPin], OUTPUT);
    }

  delay(5000);                                            // wait so sensor can initialize
}

void loop() {

  attachInterrupt(digitalPinToInterrupt(interrupt_pin),interrupt_routine,RISING); // must attach each loop
  LowPower.powerDown(SLEEP_FOREVER,ADC_OFF,BOD_OFF);      // MCU sleep until interrupt
  detachInterrupt(digitalPinToInterrupt(interrupt_pin));  // remove interrupt

  if (previous==10){                                      // when variable gets to 10 reset to zero
    previous=0;
  }

  if (state==HIGH){                                       // PIR senses motion, sends high signal
    digitalWrite(LED_BUILTIN,HIGH);                       // debug LED turns on
    myOnIteration();                                      // musicPin number x turns on
    delay(100);                                           // wait to stabilize
    digitalWrite(LED_BUILTIN,LOW);                        // debug LED turns off
  }
  if (state==HIGH){                                       // separate statements to guarantee next steps happen
    myOffIteration();                                     // musicPin number x turns off
    LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);       // sleep for 8s after musicPin plays

  }

  previous++;                                             // increment before attaching next interrupt

}

////////Functions//////////
void interrupt_routine(){
  state = HIGH;
}

void myOnIteration() {                                    // cycle through output pins turning on once per interrupt
for (int count = previous; count < pinCount; count++) {
        digitalWrite(musicPins[count], LOW);
      }
}

void myOffIteration() {                                   // cycle through output pins turning off once per interrupt
for (int count = previous; count < pinCount; count++) {
        digitalWrite(musicPins[count], HIGH);
      }
}


texts: Split string using a delimiter then saving to different variables

texts:
I have a string that looks something like this "43;27;42;27". It is the data from 4 DHT22 temperature sensors, i need to splice this string every ";" and save the number to a variable. In the end, I will have 4 variables, each one for every number. Thanks!
The data comes from another esp wirelessly and I need the data in different strings to a nextion display.
I could also change the delimiters to differ from each other, I am posting this question because I am not sure how i should go about writing all of these 4 values in a string then also "decoding" these strings and assigning each one to a variable.


texts: Reading analog value while generating PWM signal

texts:
I'm trying to generate dim two LED strips simultaneously by generating two PWM signals based on potentionmeter value. The pot sets how bright each of the LED strips will be. To drive this I'm using Arduino Pro Micro equipped with Atmel 32u4 chip.

I'm using following code:

int sensorValue = 0;
int outputValue = 0;

void setup() {
}

void loop() {
  sensorValue = analogRead(A0);

  outputValue = map(sensorValue, 0, 1023, 0, 255);
  analogWrite(5, outputValue);
  analogWrite(6, 255 - outputValue);

  delay(2);
}

The problem is, the analogRead never returns 1023 when the pot is fully open. The value is always around 980. This itself would not be a big deal.

The main issue is that the analogRead is incredibly noisy. The value returned for the maximum position is in range of [940-1020].

When I don't use the analogWrite to generate PWM, the problem goes away an the input is crystal clear in range [0-1023] as expected.

I have tried to turn off the PWM before reading the value in, but this generates flicker, as the LEDs are temporarily off.

Is there any HW or SW solution to this? I don't mind writing some assembly if required.


texts: Connection between Arduino Mega 2560 , ESP8266-12F , PCF8574

texts:
Another start for achieving something new ,

I want to connect ESP8266-12F , Arduino Mega 2560 Board And the PCF8574 I/O Expander (I can use MCP23017 also) together , Where ESP8266-12F will take commands using http (or probably other possible protocols) from user and will turn on the relayes connected to Arduino Output Pins or PCF8574 pins.
I have done basic practical tests on esp8266-12f (like Turning Lights On/Off ) but i want to expand it for more functionalities.
Also don't want to control the esp8266 using AT commands.

Power source i can manage to build.

Please Guide me so that i can complete this long run.

P.S. - I am not from electronics background, so need long runway than usual to take off.


texts: Multiple data packets with CIPSEND, associate each with pathway

texts:
When using a CIPSEND from an Arduino Uno to a ESP8266 connected to the Uno is there a way to associate the data packet sent with a pathway so it can be retrieved at said pathway from the browser?

For example ESP8266WebServer.h has a command like this:

server.on(“/specificArgs”, handleSpecificArg);   //Associate the handler function to the path

where the first argument is the path/filename - what's the equivalent of this using using CIPSEND?


texts: Yun - FileSystem.Open prevents client.println from outputting to web page

texts:
The below code is meant to display lines stored in a text file to an arduino based web page (it's a IR gate monitoring solution).

When I visit
I can execute client.println("hello") and I see the word "hello" on the page.

Then I loop round the SD card rows and I can Serial.print (by char) in the Serial Monitor all the lines in the text file. Great - so far so good.

But when I attempt to print to screen (instead of Serial Monitor) it does not work.  The offending line (but don't know why) is the FileSystem.Open - this prevents any further output to screen.

Why does FileSystem.Open prevent client.print from working?

  void loop() {

  YunClient client = server.accept();

  if (client) {
    String command = client.readString();
    command.trim();
    Serial.println(command);

    if (command == "today")
    {
        //client.println("hello");

        // Get a timestamp
        String strTS = getTimeStamp();
        String strFileName = strTS;

        // Build the file name containing the
        strFileName.replace("-", "_");
        strFileName.replace("/", "-");
        strFileName.replace(":", "-");
        strFileName = strFileName.substring(0, 8);
        strFileName = "/mnt/sd/BeerLogger/" + strFileName + ".txt";

        // Display the file name in the serial window
      //  Serial.println((strFileName).c_str());

        // Print the contents of the text file to screen
        File myFile = FileSystem.open(strFileName.c_str(), FILE_READ);

        if (myFile) {
           while (myFile.available()) {
              char c = myFile.read();
              if ( c == '\n') {
                //client.println("");
              }
              Serial.print(c);
              client.print(c);
          }
          myFile.close();
      }
    }

    // Terminate the client connection so we may resume
    client.stop();
    //Serial.println("client disconnected");

  } else {
      MonitorIRGate();
  }
}


texts: Adafruit RGB LCD w/ Shield kit connection to arduino uno?

texts:
I have a adafruit rbg 16x2 lcd with shield kit and am trying to connect it to an arduino uno. The only thing is the assembly instructions have the lcd basically using every pin on the arduino, even tho it says its not for connections. Since we are using many of the pins already on the board, can I wire it to the board without soldering it to every pin, essentially only wiring to the few necessary pins?

Sorry, I am very new at this. Thank you for the help.

EDIT: Was essentially looking for the follwing diagram. Thanks to all!


texts:
I was trying to connect with server but, I was unable to post the data. I have added the SSL key to connect with server that is happening but HTTPS POST is not. I tried the same method with http, I am able to connect with server in that case.

/* set SSL/TLS certificate */
    client.setCACert(ca_cert);
//////////////////////////////// try to connect to server again and POST the data on the cloud //////////////////////////
  if (!client.connect(host, httpsPort)) {
     Serial.println("Connection failed!");
  } else {
     Serial.println("Connected to server!");
     client.println("POST /devices/deviceData HTTP/1.1");
     client.println("Host: api.thi***i.io");
     client.println("cache-control: no-cache");
     client.println("Content-Type: application/json");
     client.println("Authorization: Bearer eyJ0e***");
     client.println("Postman-Token: b1f4e147-8d13-4a27-a1a9-b****");
     client.print("Content-Length: ");
     client.println(PostValue.length());
     client.println();
     client.println(PostValue);
  }
  Serial.print("Waiting for response ");
  while (client.available() == 0) {
     if (millis() - timeout > 50000) {
        Serial.println(">>> Client Timeout !");
        client.stop();
        return;
     }
  }

  Serial.println("Response From Server");
  while(client.available()) {
     char c = client.read();
     Serial.write(c);
  }

It should connect from my logic but I am getting server error 400.
Can I know, what can be issue here?


texts: What is preventing my code from checking the number of pushbutton values for a correct/wrong answer?

texts:
My code is supposed to generate a random number and then display it in binary using four LEDs. After you press it, it waits for two seconds before checking your number of pushbutton presses to see if they equal the random number, and it turns the green/red LED on accordingly and restarts the loop.

It doesn't do that, and also it counts multiple pushes if you keep the button pressed in, since it reads the pushbutton as being "on".

Code:

//VARIABLES:
const int ledPin1 = 2;
const int ledPin2 = 3;
const int ledPin3 = 4;
const int ledPin4 = 5;
const int buttonPin = 6;        //push button
const int ledPincorrect = 8;   //green LED that switches on for correct answer
const int ledPinfalse = 9;    //red LED that switches on for wrong answer

int randomNumber = 0;
int buttonState = HIGH;
int buttonPushCounter = 0;             //counter for button presses
int lastButtonState = HIGH;             //previous state of the button
int getal;
int i;                              //for the ConvertBinary function, i serves as a variable for the LED's
unsigned long Timer;               //Timer, switches on after buttonstate = LOW, and after 2 seconds the game restarts
long lastDebounceTime = 0;         // the last time the output pin was toggled
long debounceDelay = 50;    // the debounce time; increase if the output flickers
int ledState = HIGH;
int remember;

void setup()
{
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  pinMode(buttonPin, INPUT);
  pinMode(ledPincorrect, OUTPUT);
  pinMode(ledPinfalse, OUTPUT);
  Serial.begin(9600);
  randomSeed(analogRead(0));
  buttonState = digitalRead(buttonPin);
  Timer = millis(); // unsigned long Timer = millis();

}
void loop()
{
  if (randomNumber == 0) {
    Serial.print("lets start with random");
    getal = random(1, 16);
    Serial.print("random is: ");
    Serial.println(getal);
    randomNumber = 1;
  }

   int remember = getal;
   for (int i = 2; i < 6; i++) {
   remember = remember / 2;
      if (remember % 2 == 1){
       digitalWrite (i, HIGH);
      }
     else ((digitalWrite(i, LOW)));
    }

    // reading the button state

    // read the state of the switch into a local variable:
    int reading = digitalRead(buttonPin);

    if (reading != lastButtonState) {
      lastDebounceTime = millis();
      if (reading == LOW) {                    // if (reading == LOW) ????
        buttonPushCounter++;
        Serial.println("on");
        Serial.print("number of button pushes:  ");
        Serial.println(buttonPushCounter);
        Timer = millis();
        lastButtonState = buttonState;

      } else {
      // if the current state is LOW then the button wend from on to off:
      Serial.println("off");
    }

      if ((millis() - lastDebounceTime) > debounceDelay) {
    if (reading != buttonState) {
      buttonState = reading;
      lastButtonState = reading;
    }

    if (Timer >= 2000UL) {
      if (buttonPushCounter == getal) {
        digitalWrite(ledPincorrect, HIGH);
        digitalWrite(ledPinfalse, LOW);
        digitalWrite(ledPin1, LOW);
      digitalWrite(ledPin2, LOW);
      digitalWrite(ledPin3, LOW);
      digitalWrite(ledPin4, LOW);
      randomNumber = 0;
      buttonPushCounter = 0;
      }
      else {
        digitalWrite(ledPinfalse, HIGH);
        digitalWrite(ledPincorrect, LOW);
        digitalWrite(ledPin1, LOW);
      digitalWrite(ledPin2, LOW);
      digitalWrite(ledPin3, LOW);
      digitalWrite(ledPin4, LOW);
      randomNumber = 0;
      buttonPushCounter = 0;
      }
}

    }
}

}


texts: Arduino IDE crash when I connect Blend Micro

texts:
I recently bought Blend Micro and I am setting up Arduino IDE to start using it, but after installing the required libraries and the Blend Micro drivers, the IDE suddenly crashes without any visible error whenever I plug the blend micro to my PC. If it is already plugged in, the ide won't even start up. This was not happening before I installed the drivers. I don't know if it's relevant but blend micro was connected to my pc during the drivers installation. I have already looked for a way to solve this on Google without relevant results.

I am using Windows 10 with Arduino IDE 1.6.12

I would really appreciate any help with my problem, thank you in advance.


texts: Arduino Christmas light project with dimmer

texts:
I have an existing project using an Arduino Yun that controls Christmas lights with relays to turn them on/off. There are currently 13 separate rows of lights on the (60 foot) tree, each plugged into a wall wart that's controlled by its own relay.

I'm considering adding the ability to dim the lights, so I wanted to figure out the best way to do it. The lights can all be dimmed "in unison" - there's no need for 13 seperately controlled dimmers. But I have to be mindful not to cause any "buzzing" in the audio equipment on stage where the tree is.

I've read about PWN, zero cross, and other terms and saw the zero cross tail from powerswitchtail.com that seem useful in the typical project. I'd like to be able to pull this off with no more than 2 "dimmers" for the whole project, if possible.

Where do I start, and how do I do it?


texts: Arduino Due and Vin, 3.3V and 5V power inputs

texts:
I just want to confirm something before I wire up my first ever Arduino project and fry all the stuff I just spent money on.

It is my understanding that the Vin power input will tolerate a 9V battery and use voltage regulators to pare it down to either 3.3V or 5V (as different parts of the board require). So it is then my assumption that if I have a 9V battery running to Vin, that I could then connect a power wire to the 3.3V connector, and reliably get a 3.3V signal (and ditto for 5V), yes?

Or, is it that they are input jacks expecting either 3.3V or 5V signals? I guess I'm confused over this:

Will Vin then power the 3.3V and 5V inputs, giving me access to voltage at that level; or
Do I have to choose between 3.3V, 5V or Vin, and only use one of those to power my board (with the appropriate voltage level)


texts: Arduino and NodeMCU problem with wifi conecction

texts:
Hello guys I am beginner with micro controllers but I am trying to make a simple IoT with Arduino and NodeMCU as WiFi. I was using this tutorial and code https://www.electronicshub.org/wifi-controlled-led-using-esp8266-and-arduino/.

When I upload the code for the first time everything worked perfectly but every other time when I upload the same code my program is stuck in a loop.

Program is in infinite while loop while(!esp8266.find("OK")) because as far as i understand it didnt receive the OK status from ESP.

But in fact esp8266Serial("AT+CWJAP=\"SSID\",\"Password\"\r\n", 5000, DEBUG); prints OK in my console so it means that it should work but it doesnt...

Do you guys have any idea whats the reason?

Code looks as follows;

#include <SoftwareSerial.h>
SoftwareSerial esp8266(2,3); //Pin 2 & 3 of Arduino as RX and TX. Connect TX and RX of ESP8266 respectively.
#define DEBUG true
#define led_pin 11 //LED is connected to Pin 11 of Arduino

void setup()
  {
    pinMode(led_pin, OUTPUT);
    digitalWrite(led_pin, LOW);
    Serial.begin(9600);
    esp8266.begin(115200); //Baud rate for communicating with ESP8266. Your's might be different.
    esp8266Serial("AT+RST\r\n", 5000, DEBUG); // Reset the ESP8266
    esp8266Serial("AT+CWMODE=1\r\n", 5000, DEBUG); //Set station mode Operation
    esp8266Serial("AT+CWJAP=\"SSID\",\"Password\"\r\n", 5000, DEBUG);//Enter your WiFi network's SSID and Password.

    while(!esp8266.find("OK"))
    {
      }
    esp8266Serial("AT+CIFSR\r\n", 5000, DEBUG);//You will get the IP Address of the ESP8266 from this command.
    esp8266Serial("AT+CIPMUX=1\r\n", 5000, DEBUG);
    esp8266Serial("AT+CIPSERVER=1,80\r\n", 5000, DEBUG);
  }

void loop()
  {
    if (esp8266.available())
      {
        if (esp8266.find("+IPD,"))
          {
            String msg;
            esp8266.find("?");
            msg = esp8266.readStringUntil(' ');
            String command1 = msg.substring(0, 3);
            String command2 = msg.substring(4);

            if (DEBUG)
              {
                Serial.println(command1);//Must print "led"
                Serial.println(command2);//Must print "ON" or "OFF"
              }
            delay(100);

              if (command2 == "ON")
                    {
                      digitalWrite(led_pin, HIGH);
                    }
                   else
                     {
                       digitalWrite(led_pin, LOW);
                     }
          }
      }
  }

String esp8266Serial(String command, const int timeout, boolean debug)
  {
    String response = "";
    esp8266.print(command);
    long int time = millis();
    while ( (time + timeout) > millis())
      {
        while (esp8266.available())
          {
            char c = esp8266.read();
            response += c;
          }
      }
    if (debug)
      {
        Serial.print(response);
      }
    return response;
  }


texts: 16*2 LCD display doesn't display my result

texts:
I am working on a project to calculate line frequency meter by reciprocal counting with Arduino. I am trying to print the the result on a 16*2 LCD but it is not displaying anything. It just gets on and stuck there. I got the project details from this website Line Frequency Meter Based On Reciprocal Counting

I modified the stock program to interface the LCD but it's not working. Here is the code I am using:

//To read and display the Line frequency
//using Reciprocal counting method
//clk for 'Time Counter'  is generated with 'Tone' function
//'Time counter' is the physical counter T1
// 'EVENT Counter' is a software counter
#define Fin 6      // input pin for Line freq sig
#define clk 7      // input to ' Time ' counter
#include<LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
boolean FState;   // status of the 50 Hz Signal
int countS;       // Signal count
int countC=0;     //  Clock count
int LineFreq;     // Result

void setup() {
  tone(8, 5000); // generates ref freq of 5000 Hz at Pin 8
  pinMode(Fin, INPUT); // set the Fin pin as INPUT
  pinMode(clk, INPUT); // set the clk pin as INPUT
  lcd.begin(16, 2);
}

void loop() {
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Frequency of signal");
  // to avoid partial cycles, first detect the rising edge
  while(digitalRead(Fin)) {
    //wait for '0' state of the Signal
    delayMicroseconds(10);
  }
  //here '0' state
  while(!digitalRead(Fin)) {
    //wait for '1' state
    delayMicroseconds(10);
  }
  //this is the rising edge of the Fin
  //counting can start from here
  // clear the TIME Counter T1
  counterStart1();
  //count 50 of the Line freq signals
  while(countS<50) {
    while(digitalRead(Fin)) {
      //wait for '0' state
      delayMicroseconds(1);
    }
    //here '0' state
    while(!digitalRead(Fin)) {
      //wait for '1' state
      delayMicroseconds(1);
    }
    // here '1' state
    // here one cycle is just over
    //increment the event counter
    countS=countS+1;
  }
  //here 50 Signal cycles over
  // read the contents of T1 & compute frequency
  countC = getCount1();
  LineFreq = 25000000/countC;

  //send to display
  lcd.setCursor(0,1);
  lcd.print(LineFreq);
  lcd.print(" Hz");
  delay(500);
  delay(100);
  // clear counter
  countS=0;
  // repeat
}

//The following code is obtained from on-line articles in the public domain
void counterStart1() {
 // hardware counter setup,  for  the 16-bit Timer1 Timer/Counter
 TCCR1A=0; // reset timer/countern control register A
 TCCR1B=0; // reset timer/countern control register B
 TCNT1=0; // initialize the counter value to 0; this register holds the current count
  // set timer/counter1 hardware as a counter; it counts events on pin Tn (Arduino pin 5)
 TCCR1B = TCCR1B | 7; // Counter Clock source = pin Tn (Arduino pin 5) , start counting now
 // 7 in binary is 0111; OR-ing will set CS10,11,12 to 1's
return;
}

// the following code is obtained from on-line articles in the public domain
// Sub routine  to get the current count
unsigned int getCount1() {
 unsigned int count; // this variable returns the current count from the counting register
 TCCR1B = TCCR1B & ~7; // Gate Off  / Counter T1 stopped,
 // this operation clears the bits (CS10,11,12)
 count = TCNT1; // read the counting register
 TCCR1B = TCCR1B | 7; // re-start counting by resetting the bits (CS10,11,12)
 return count; // return the retrieved count to the calling function
}

I am getting a blank screen but the line at very first of the code "Frequency of signal" is printing accurately.

What is wrong with the code and what changes do I need?

Thanks in advance!


texts: Should I use LLC to power sensors on grid pcb at 4mtr wire length distance?

texts:
I have setup a grid pcb that further distributes power and receive signal from sensors, I know low voltage can detroit if not damage sensors , so I am thinking to put BD-LLC  to distribute power output to 6 sensors connected to PCB shown below.
[ignore 24 volt power that feeds solenoid it is separate and comes from power adapter not from mega though the wire has same red colour] the 5 volt wire connecting to main connector from other connector is not visible.

And I have Arduino Mega from which I am drawing power 5 volt (using digital multimeter I found it's 4.98 volt). And all sensors are connected to this 5volt parallely.
So the question is should I put this BD-LLC on above PCB to distribute correct power output to sensors ?


texts:
I am working on a wireless sensor network project, in which data is collected at a central node using nRF24 modules and the RFNetwork.h library.

I want to post that to the internet using the famous ESP8266 module, which works fine when used as standalone and programmed with Arduino IDE. But the problem is how to transfer my data from Arduino to the ESP8266 as it only has one serial that is already used to program it?

I have tried to use a nRF24 module that uses SPI with an ESP-12 as it has an SPI header, but it didn't work out and I can't figure out the problem. Is there a way to use ESP core libraries like esp8266wifi.h, wifiClient.h, webserver.h etc., just like we can use the esp8266.h library that uses AT commands to communicate to ESP from an Arduino like in a master-slave manner?


texts:
A newbie in Arduino- and I'm trying to concatenate string and chars ( well in python it is quite different ).

I'm trying to post a MQTT message- constructed following format to the client.publish(outTopic, "["+outTopic+"]"+ msg)

while outTopic is a char* variable, and msg is char- but I get an error for such concatenation.

please your help

#include <ESP8266WiFi.h>
#include <PubSubClient.h>

// GPIOs on SONOFF board
int LED_SONOFF = 13;
int REL_SONOFF = 12;
int PIN_SW = 14;

const char* ssid = "HomeNetwork_2.4G";
const char* password = "pswd";
const char* mqtt_server = "192.168.2.113";

WiFiClient espClient;
PubSubClient client(espClient);

char msg[50];
const char* outTopic = "HomePi/Dvir/Messages";
const char* inTopic = "HomePi/Dvir/Windows/SONOFF";
const char* inTopic2 = "HomePi/Dvir/Windows/All";
const char* clientID = "Sonoff#1";
String m1, m2;

void start_wifi() {
  WiFi.mode(WIFI_STA);
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.print("IP address: ");
  Serial.println(WiFi.localIP());
}

void setup() {
  start_wifi(); // start wifi service
  Serial.begin(115200); // start serial service
  delay(10);

  // define sonoff gpios
  pinMode(LED_SONOFF, OUTPUT);
  pinMode(REL_SONOFF, OUTPUT);
  pinMode(PIN_SW, INPUT_PULLUP); // GPIO14 has a pullup resistor
  digitalWrite(LED_SONOFF,HIGH); // LED high is OFF
  digitalWrite(REL_SONOFF,LOW);

  // start mqtt
  client.setServer(mqtt_server, 1883);
  client.setCallback(callback);
}

void switch_on() {
  digitalWrite(REL_SONOFF,HIGH);
  digitalWrite(LED_SONOFF, LOW); // LED ON
  pub_mqtt("Switch ON");
}

void switch_off() {
  digitalWrite(REL_SONOFF,LOW);
  digitalWrite(LED_SONOFF, HIGH); // LED OFF
  pub_mqtt("Switch OFF");
}

void callback(char* topic, byte* payload, unsigned int length) {
  Serial.print("Message arrived [");
  Serial.print(topic);
  Serial.print("] ");
  for (int i = 0; i < length; i++) {
    Serial.print((char)payload[i]);
  }
  Serial.println();

  if ((char)payload[0] == '1') {
    switch_on();
  }
  if ((char)payload[0] == '0') {
    switch_off();
    Serial.print("payload: ");
    Serial.println(payload[0]);
  }

}

void reconnect() {
  while (!client.connected()) {
    Serial.print("Attempting MQTT connection...");
    if (client.connect("ESP8266Client")) {
      Serial.println("connected");
      client.publish(outTopic, "Connected");

      client.subscribe(inTopic);
      m1="Subscribed to: "+inTopic;
      client.publish(outTopic, m1);
      if (inTopic2 !=""){
        client.subscribe(inTopic2);
        m2="Subscribed to: ";//+ String(inTopic2);
        client.publish(outTopic, m2);
      }

    } else {
      Serial.print("failed, rc=");
      Serial.print(client.state());
      Serial.println(" try again in 5 seconds");
      delay(5000);
    }
  }
}

void pub_mqtt(char* msg) {
  client.publish(outTopic, msg);
}

void loop() {
  if (!client.connected()) {
    reconnect();
  }
  client.loop();

  if (digitalRead(PIN_SW)==1) {
    if (digitalRead(REL_SONOFF)!=LOW) {
      switch_off();
    }
  }
  else if (digitalRead(PIN_SW)==0) {
    if (digitalRead(REL_SONOFF)!=HIGH){
      switch_on();
    }
  }
   delay(100);
}


texts: How to I make the Tx and Rx pins on an ESP-8266-01 into GPIO pins?

texts:
When programming an ESP-01 with Arduino IDE, how can I make the Tx and Rx into a generic I/O pins reliably? I think there's a command to swap the Tx and Tx with other pins. I  tried serial.swap() but it didn't work. So how to get done with Arduino IDE or is it even possible?. I am using an ESP-01, which means there will be four GPIO pins once this question in answered.

I want to achieve same as in the video, How to add more GPIOs to ESP8266 (ESP-01), but without soldering wire.


texts: How do I send tweets with flame sensor and ESP8266?

texts:
I want to send tweets with flame sensor and ESP8266. My flame sensor is digital. I think everything is good but it doesn't send.

This is my code:

#define ag_ismi "SSID"
#define ag_sifresi "PASSWORD"
#define IP "184.106.153.149" //thingspeak.com IP address

int sensorPin = 8;
int smoke_level = HIGH;

void setup() {
  pinMode(sensorPin, INPUT);
  Serial.begin(115200);
  Serial.println("AT");
  delay(3000);
  if (Serial.find("OK")) {
    Serial.println("AT+CWMODE=1");
    delay(2000);
    String baglantiKomutu = String("AT+CWJAP=\"") + ag_ismi + "\",\"" + ag_sifresi + "\"";
    Serial.println(baglantiKomutu);
    delay(5000);
  }
}

void loop() {
  smoke_level = digitalRead(sensorPin); // Arduino reads the value from the smoke sensor
  Serial.println(smoke_level);// prints just for debugging purposes, to see what values the sensor is picking up
  if (smoke_level == HIGH) {
    // if smoke level is greater than 500, the buzzer will go off
    sicaklik_yolla();
  }
  delay(20000);
}
void sicaklik_yolla() {
  Serial.println(String("AT+CIPSTART=\"TCP\",\"") + IP + "\",80");
  delay(1500);
  String tweet = "POST /apps/thingtweet/1/statuses/update HTTP/1.1\n";
  tweet += "Host: api.thingspeak.com\n";
  tweet += "Connection: close\n";
  tweet += "Content-Type: application/x-www-form-urlencoded\n";
  tweet += "Content-Length:67\r\n\r\napi_key=";
  tweet += String("MY API KEY");
  tweet += String("&status=");
  tweet += String("MY TWEET TEXT");
  Serial.print("AT+CIPSEND=");
  delay(100);
  Serial.println(tweet.length());
  if (Serial.find(">")) {
    Serial.println(tweet);
    Serial.println("AT+CIPCLOSE=0");
    delay(100);
  } else {
    Serial.println("AT+CIPCLOSE=0");
  }
}

This schema is old. Sensor connected to pin 8.


texts: Using NodeJS, socket.io and Adafruit HUZZAH CC3000 breakout board to control Arduino wirelessly?

texts:
I'm looking to build my a wirelessly controlled lamp and have a few questions. Would I be able to use the Adafruit HUZZAH CC3000 breakout board to receive commands from a website and control a connected lamp?

I just set up a NodeJS server with webpage on my PC and using socket.io and Firmata I was able to communicate with the Arduino using the webpage over a serial connection. Could I set up similar implementation except instead of communicating over serial I'd communicate using Wifi? Would I need to host a web server on the Wifi board itself to communicate with the Arduino or is there some way to just use the wifi board as a communication between external site and Firmata?


texts: Is there a color LCD display for an arduino?

texts: I currently have a Mega2560 with the LCD4884 Shield. The Shield is good for putting out text and simple pixel images. But I am wondering if there is something that has a full range of colours that would work with the Arduino? The screen size would only have to be a few inches in size.


texts: Get deceleration (negative acceleration when apply brake force)

texts:
I want to build a device to measure deceleration force when a car brakes. I am using a MPU6050 for get data and I read from it acceleration on X,Y,Z axes in m/s2 and also it gives me gyro in degrees/second.
My question is how can I use these gyro values to correct acceleration? Basically when apply brake the position of the axes are changing .
Also I guess I need to calculate the deviation as well if the car goes to the left or right during brake process.
Any ideas, hints will be very appreciated
Thank you very much


texts: Can i use a sparkfun rfid qwiic without an id-xxla?

texts:
Sparkfun rfid qwiic

id-20la

I am using an Arduino UNO R3.

You should assume that i don't know anything. If yes can you give some information about how to do it? Thanks for any help.


texts:
I've been searching a little for self-updating the ARDuino, and most i've come about is updating it using a wifi / lan shield.

Now I have a GPRS shield that can connect it to the internet. Say that I want to remotely update the shield - how would I go about doing that?

I'm guessing I need some kind of bootloader - but is that extra hardware?

Actually the question boils down to:

How can I flash the ARDuino Uno with new software, that I'll receive over a GPRS connection using a GPRS shield?


texts: I've been working on a project and I get an error compiling for board arduino uno. kindly help

texts:
##include <jm_LiquidCrystal_I2C.h>

#include <LiquidCrystal.h>

#include <Wire.h> // For I2C
//Set the pins on the I2C chip used for LCD connections
//ADDR,EN,R/W,RS,D4,D5,D6,D7
LiquidCrystal_I2C lcd(0x3f, 2, 1, 0, 4, 5, 6, 7); // 0x27 is the default I2C bus address of the backpack-see article

#define echoPin 3 // Echo Pin (OUTPUT pin in RB URF02)
#define trigPin 2 // Trigger Pin (INPUT pin in RB URF02)

int led = 5;
int maximumRange = 350; // Maximum range needed
int minimumRange = 0; // Minimum range needed
long duration, distance; // Duration used to calculate distance
int brightness;

void setup() {
  lcd.begin (16, 2); // 16 x 2 LCD module
  lcd.setBacklightPin(3, POSITIVE); // BL, BL_POL
  lcd.setBacklight(HIGH);
  Serial.begin (9600);
  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
  pinMode(led, OUTPUT);
}

void loop() {
  // The following trigPin/echoPin cycle is used to determine the distance of the nearest object by bouncing soundwaves off of it.
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  duration = pulseIn(echoPin, HIGH);
  distance = duration / 58, 2; //Calculate the distance (in cm) based on the speed of sound.
  lcd.home (); // Set cursor to 0,0
  lcd.print("The Water Level is");
  lcd.setCursor (0, 1);
  lcd.print(distance); // Custom text
  lcd.print("cm");
  Serial.println(distance); // distance in cm
  brightness = map(distance, 1, 100, 0, 255);
  analogWrite(led, brightness);
  delay(1000); //Delay 50 ms


texts:
I know this is Arduino Forum but I think this question is related to programming, I am using ESP8266 for the project. I need to convert the  string incoming on the serial through UART lines and receiving those using the below code. Also I am converting the received string to char array as i need to insert some more characters in between hence I need the conversion.
I have used 3 different commands to convert the above string into char array as you can see below

#include <SoftwareSerial.h>
#include <Arduino.h>

#include <stdio.h>

#include <string.h>

SoftwareSerial s; //RX TX
using namespace std;
String str= "";
String str_tx;

const char* c;
double buff[24];
unsigned long int str_len = 0;
double val;
char* token;
//char* rest = char_array;
int i=0;
void setup() {
  // put your setup code here, to run once:
  Serial.begin(115200);
  s.begin(115200, SWSERIAL_8N1, 13, 15, false, 256); //115200, SWSERIAL_8N1, 13, 15, false, 512
  pinMode(13, INPUT);
  pinMode(15, OUTPUT);

  Serial.println("in setup 1");
  Serial.println("in setup 2");
  Serial.println("in setup 3");

}

void loop() {
  // put your main code here, to run repeatedly:2
 while(s.available() >0)
 {

  char ch=s.read();
  str.concat(ch);
  if( ch =='\n' )
  { str.trim();
    Serial.println(str);
    str_tx = str;
    Serial.println(str_tx);

    str_len = str_tx.length()+1;
    Serial.println(str_len);
    //char char_array[sizeof(str_tx)];
    char char_array[str_len];
    //strcpy(char_array, str_tx.c_str());
    //str_tx.toCharArray(char_array, str_len);
    std:copy(str_tx.begin(),str_tx.end(),char_array);
    Serial.println(char_array);
    char_array[sizeof(str_tx)] = '\0';
    //char_array[65] = 0;
    str="";
    str_tx = "";
    Serial.println("------------------------------------");
  }
  /*
  str = "";
  str = s.readStringUntil('\n');
  str.trim();
  Serial.println(str);
  str_tx = str;
  Serial.println(str_tx);

  str_tx = str;
  str_tx.replace("\n","");

  str_len = str_tx.length();
  Serial.println(str_len);
  Serial.println(str_tx.c_str());*/

}

}

The output of the above code comes as below, you can see the first time conversion occurs but the next time only empty string shows up, in all the 3 cases its showing the same hence I need to find out what exactly this issue is caused by, would appreciate if anyone could thro some light on it.
Thankyou


texts: How many LED Strips can we connect to an Arduino Uno? Is there a way to connect 1-3 meters worth without needing extra parts (relays)?

texts:
I am looking at Adafruit to purchase some LED strips for a mod for my computer case, and want to power it with an Arduino.

I am looking at the Uno, but the Mega looks good too.  I hear the Uno is good because if the chip fries, you can just replace it easier than the Mega's chip.  I did hear that the Uno chip had issues, but that was a 2013 post.

Anyways, I am essentially looking to connect about a foot of 144 leds/m to the front of my case, and connect that to the Arduino.  I will then be lining the inside of my case with about 12-15" per side (x4 sides) of 60 leds/m so I wanted to connect that to another part of the Arduino.

I read that each led takes something like 6mA or 60mA each, so that is what we should watch for.  I was trying to search for this question that others asked, but people were looking to connect a lot of strips, and needed relays and whatnot, so I wanted to make sure the Arduino itself could power about 1.5 to 2 meters of Led strips in at least 2 different strip configs (or whatever you want to call them).

I also am curious if there will be an issue programming each strip setup or, if it just is a little more work to get it setup?

Since this is a computer cause led setup, I'm not sure if I should go USB power, or a wall charger?  What is the recommended approach for something like this?

I will definitely be reading up more tutorials and all that important stuff, but I want to buy the stuff now since I realized there's a cyber Monday deal going on, so I don't want to miss out...

Any help is appreciated, thank you!


texts: Arduino Uno + MSD-11-EM stepdriver + NEMA 17

texts:
I am working on Arduino code for stepper motor rotations control. I want to rotate a stepper for only 4 rotations.

The code is working fine but that will run only once as I have put that in setup().

I want to know if there will be any reverse current flowing in the circuit that would damage the Arduino or stepper. What if I want to run the stepper in the loop()? I tried but that will force the stepper to run continuously.

How can I run stepper for only 4 rotations and then stop?

I want to run it in loop().

Below is the code I am using:

#include <Stepper.h>

const int stepsPerRevolution = 2100;
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);

void setup() {
  // set the speed at 60 rpm:
  myStepper.setSpeed(110);
  // initialize the serial port:
  Serial.begin(9600);
  for(int i=0;i<25;i++) {
    Serial.println("Anti-clockwise");
    myStepper.step(stepsPerRevolution);
    delay(50);
  }
}


texts: So I'm taking a class where the project is to create a new embedded language. We are using OCaml for the compiler, so I was looking for a way to interface with AVR or its C library in such a way as I can write programs in my language, then compile and somehow get it on the arduino I have. I was curious if there's a library for OCaml or some sort of white paper for interfacing with the board at a high level or even at a low level where I can get this to work.


texts: CH340G and CP2102 devices not recognized with Thinkpad L380

texts:
I have three different devices, none of them gets recognized on my new Thinkpad L380 running Windows 10:

Arduino Nano Clone with CH340G chip (USB2Serial)
NodeMCU (Lolin V3) with CH 340G chip (USB2Serial)
NodeMCU (ESP-WROOM-32) with CP2102 chip (USB2UART)

All three of them are recognized properly both on my desktop computer running Windows 10 (on USB 2.0 ports) as well as on my other laptop (Acer Switch Alpha 12, Win10, USB 3.0 port).

But even after hours of trying I was not able to connect those devices to my Thinkpad.
Things I've tried so far:

Of course, simply installing the Arduino IDE and try plug'n'play
Downloading and installing the CH340G driver from the official website
Disabling Secure Boot, enabling testsigning mode and reinstalling the CH340G driver
For the CP2102 device I only tried installing the driver under "normal" Windows (e.g. no testsigning enabled) since it also worked that way on my desktop computer

I have to admit that it's been a while since I set up the drivers on my other laptop and desktop computer, but I cannot remember that there was anything unusual I had to do back then.

Does anybody else know about problems regarding Thinkpad laptops? At first I thought USB 3.0 might be the problem, but the Acer laptop works just fine with the USB 3.0 port.

Update

Somehow the laptop now at least recognizes the Arduino Nano clone in the device manager and I can choose the COM port in the Arduino IDE. I can't tell what made the difference. All I did was to plug in a dongle for a wireless mouse in the USB ports to verify that they are working with "normal" devices and afterwards the Nano was recognized at least with a yellow "!" in the device manager. I then was able to uninstall the CH340 drivers and reinstall them. The device manager now displays the Nano as correctly installed.

But uploading a sketch fails. It outputs the errors:

avrdude: stk500_recv(): programmer is not responding
avrdude: stk500_getsync() attempt 9 of 10: not in sync: resp=0x0a
avrdude: ser_send(): write error: sorry no info avail
avrdude: ser_recv(): read error: Access denied

The RX LED is faintly blinking in red at the beginning of the process, then the upload seems to get stuck until the error messages are displayed.

The NodeMCU Lolin V3 with the same CH340 chip is still not recognized, though.

Serial communication (with the Serial monitor of the Arduino IDE) is now possible. I uploaded the "ASCIITable" example using my Desktop PC, connected the Arduino to the ThinkPad and could successfully read the output over the serial interface.


texts: MQTT not working on ESP8266 (Nodemcu 0.9)

texts:
I'm trying to use NodeMCU on my ESP8266 (NodeMCU 0.9) but the board keep crashing and I don't understand why.

I tested the mqtt broker using command line and it works perfectly, so I can suppose that the problem is not the server.

I was following this guide but it doesn't seem to work with me.

Here's the code I wrote:

Previously:

#include <PubSubClient.h>
#define MQTT_SERVER    "1.2.3.4"
#define MQTT_PORT      1883
#define MQTT_USER     "user"
#define MQTT_PSW      "psw"
...
WiFiClient client;

Then:

PubSubClient clientMqtt(MQTT_SERVER, MQTT_PORT, this->client);
//Try mqtt connection
while (!clientMqtt.connected()) {
    Serial.print("Attempting MQTT connection...");
    // Attempt to connect
    if (clientMqtt.connect("ESP8266Client", MQTT_USER, MQTT_PSW)) {
      Serial.println("connected");
    } else {
      Serial.print("failed, rc=");
      Serial.print(clientMqtt.state());
      Serial.println(" try again in 5 seconds");
      // Wait 5 seconds before retrying
      delay(5000);
    }
}

//Try send message
clientMqtt.publish("bin", "test", true);

The code works correcty until clientMqtt.connect("ESP8266Client", MQTT_USER, MQTT_PSW) where at the first/second attempt crashes.

This is the output:

Attempting MQTT connection...
failed, rc=-2 try again in 5 seconds
Attempting MQTT connection...
failed, rc=-2 try again in 5 seconds
Attempting MQTT connection...

Soft WDT reset

ctx: cont
sp: 3ffefa90 end: 3ffefe30 offset: 01b0

>>>stack>>>
3ffefc40:  3ffe897d 40202c5d 3ffefcc4 40202dab
3ffefc50:  3ffe89b7 3ffefcc0 3ffefcc4 40203cdc
3ffefc60:  514d0400 00045454 3ffe89a7 40204cdc
3ffefc70:  3ffe89c0 3ffe89a9 00000000 3ffe88fa
3ffefc80:  3ffeeb70 3ffefdb0 3ffeedd8 3ffe88fa


texts: Is Sparkfun's MicroView OLED Arduino module a shield?

texts:
I'm getting confused by the Arduino terminologies:  shield, breakout, module.

Is this MicroView an Arduino compatible shield that will plug into Arduino's or Adafruit's Uno?


texts: Arduino Uno R3 keeps on resetting within void setup() itself

texts:
This problem is very recent as I have run the program (standard SHT10 sensor code) successfully many times. But now, all of a sudden, my program keeps repeating void setup() statements and does not execute void loop().

I checked for memory leakage using freeMemory() given here https://github.com/McNeight/MemoryFree.
Its showing freeMemory = 1807 on Serial Monitor.
SRAM memory is 2K for Arduino Uno.

I have executed this particular program continuously for many days and have used the board simultaneously switching between different programs.

I tried executing other programs too, but the same problem persists. The only program out of all that I tried that works fine is the blink program!

I have even implemented the F() macro but no change.

What is the problem?

The code is:

#include <SHT1x.h>

#define dataPin 6
#define clockPin 7
SHT1x sht1x(dataPin, clockPin);
float temp, humidity;

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

void loop() {
 temp = sht1x.readTemperatureC();
 humidity = sht1x.readHumidity();

 Serial.print(F("Temperature: "));
 Serial.print(temp); Serial.print(F("C"));
 Serial.print(F("Humidity: "));
 Serial.print(humidity);Serial.println(F("%"));
 delay(4000); }


texts: Can the Arduino Uno become an AVR programmer and use the ICSP header to program the target board

texts:
The Arduino Uno has an ICSP header that I imagine is for programming the board using a separate ICSP programmer. That is, its ICSP header turn the board into a target.

Can one use that same ICSP to program other boards, turning the Arduino Uno effectively into a ICSP AVR programmer? How?

I'm assuming that the target boards would also be Arduinos and wanted the Uno to program them using the Arduino IDE. Is that possible?

Reading the AVR In-System Programming Application Note it looks to me that the only issue would be to make the programmer (the Arduino Uno) control the target board reset line. I've seen something like that in ArduinoISP sketch, but in that sketch, the target reset is controlled by port D10. But one could program the reset line to be an output, right? So could we change the ArduinoISP sketch to use its own reset line as output to control the target board reset line? If not, why not?


texts: DC Motor Pinning the Ada Fruit Moto Shield with the Mega2560 R3

texts:
I picked up an AdaFruit Motor Shield V2.3 .  The example on the site shows how to code the DC Motor connection

// Create the motor shield object with the default I2C address
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
// Or, create it with a different I2C address (say for stacking)
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61);

// Select which 'port' M1, M2, M3 or M4. In this case, M1
Adafruit_DCMotor *myMotor = AFMS.getMotor(1);
// You can also make another motor on port M2
//Adafruit_DCMotor *myOtherMotor = AFMS.getMotor(2)

What I'm unclear about is how to connect the shield to the mega board.  Which pin on the shield should connect to which pin on the board in order for Motor 1 to run at that speed?


texts:
This may be an easy question, and if so im sorry, but i couldn't find out how to do this. I've programmed in python before and hoped that this would work, but it don't.

int myArray1[] = {0, 2, 4, 5, 7, 9, 11};
int myArray2[] = {0, 2, 3, 5, 7, 8, 10};
int myArray3[] = {0, 3, 5, 6, 7, 10};

int newArray[] = myArray2;

I wanted to only have to change one place in my code, which of the first three arrays i want my new array to take values from. Do anyone have any suggestions on how to do this?


texts: Arduino controlled remote for an rc car. What am I doing wrong?

texts:
I have an Osepp Mega 2560 (Arduino Compatible) which I'm trying to use to run a RC Car from the remote control.

Can someone please explain how do I need to connect the pins from Osepp to the remote board.

The setup (please look at image for bolded details):
 - Osepp 5v Power pin going to the Positive (see red wire)
 - Osepp GND pin going to the Negative (Black wire)
 - Osepp Pin 13 (pwm) going to the signal to drive forward (bottom of the board).

The Code

int led = 13;

void setup() {
  pinMode(led, OUTPUT);
  digitalWrite(led, LOW);
}

void loop() {

  digitalWrite(led, LOW);
  delay(10000);
  digitalWrite(led, HIGH);
  delay(10000);
}

The Problem
I expect that after 10 seconds the remote will start sending a signal to move forward.
In actuality the signal gets sent right away, even though the pin is set to LOW.
The "signal to drive forward" spot where I soldered a wire from pin 13 is where power gets sent once you press down the joystick (also highlighted in the pic) and complete the circuit.

FYI
I am not trying to do any modulation, pin 13 may have been a poor choice.
I do not have any kits nor manuals, just winging it
The joystick for the forward action is actually suppose to be top left(missing in this case but you can see the circuit) and not the one highlighted in the picture


texts: Error while sending message using gsm sim900a module interfaced with arduino uno

texts:
The code used for interfacing the gsm module with arduino for sending a message is as follows :-

#include <GSM.h>

#define PINNUMBER ""

// initialize the library instance
GSM gsmAccess; // include a 'true' parameter for debug enabled
GSM_SMS sms;

// char array of the telephone number to send SMS
// change the number 1-212-555-1212 to a number
// you have access to
char remoteNumber[20]= "12125551212";

// char array of the message
char txtMsg[200]="Test";

void setup()
{
  // initialize serial communications
  Serial.begin(9600);

  Serial.println("SMS Messages Sender");

  // connection state
  boolean notConnected = true;

  // Start GSM shield
  // If your SIM has PIN, pass it as a parameter of begin() in quotes
  while(notConnected)
  {
    if(gsmAccess.begin(PINNUMBER)==GSM_READY)
      notConnected = false;
    else
    {
      Serial.println("Not connected");
      delay(1000);
    }
  }
  Serial.println("GSM initialized");
  sendSMS();
}

void loop()
{
// nothing to see here
}

void sendSMS(){

  Serial.print("Message to mobile number: ");
  Serial.println(remoteNumber);

  // sms text
  Serial.println("SENDING");
  Serial.println();
  Serial.println("Message:");
  Serial.println(txtMsg);

  // send the message
  sms.beginSMS(remoteNumber);
  sms.print(txtMsg);
  sms.endSMS();
  Serial.println("\nCOMPLETE!\n");
}

the error is found on the 3rd line
    GSM_SMS sms;
as GSM_SMS is not a name type.
what point am i missing here...??

thank you in advance.


texts: SPI Problem with K-Thermocouple and Potentiometer?

texts:
I have a setup where the Arduino reads input from the k-thermocouple and uses that info to regultate the an output voltage through a potentiometer. I know the potentiometer is not faulty because able to read the output from the wiper when I run the program but for some reason, k-thermocouple is stuck at 0 Celsius. I know that the k-thermocouple is not faulty either because it works accordingly when I run a program specifically by itself.

Does anybody know why there is a problem with how the k-thermocouple is operating in junction with the potentiometer? Here is a declarations of my program.

#include <SPI.h>

// K-couple dependent DigiPot Regulator

#include "SPI.h"
#include "max6675.h"

byte address = 0x10;
int CLK = 13;
int CS = 10;
int SDI = 11;
const int ktcSO = 12;
int ktcCS = 9;
int ktcCLK = 13;

MAX6675 ktc(ktcCLK, ktcCS, ktcSO);

int digitalPotWrite(int value) //Everything that happens when the DigiPot is
called
{
  digitalWrite(CS, LOW); // Chip Select is ACTIVE LOW (so now it's selected)
  SPI.transfer(address);
  SPI.transfer(value);
  digitalWrite(CS, HIGH);
}

void setup()
{
  SPI.begin();
  pinMode (CLK, OUTPUT);
  pinMode (CS, OUTPUT);
  pinMode (SDI, OUTPUT);
  Serial.begin(9600);
  // give the MAX a little time to settle
  delay(500);
}

void loop()
{
  if (ktc.readFahrenheit() < 60)  // While it's still in Safe Zone
  {
    digitalPotWrite(255);
    // Show the current temp in C and F
    Serial.print("Deg C = ");
    Serial.print(ktc.readCelsius());
    Serial.print("\t Deg F = ");
    Serial.print(ktc.readFahrenheit());
    int sensorValue = analogRead(A0);
    float voltage = sensorValue * (5.0 / 1023.0);
    Serial.print("\t V = ");
    Serial.println(voltage);
    int clockValue = analogRead(A1);
    Serial.print("\t Clock = ");
    Serial.println(clockValue);
  }
        if (ktc.readFahrenheit() < 65) // While in Caution Zone
        digitalPotWrite(51);
        else if (ktc.readFahrenheit() < 70)
        digitalPotWrite(102);
        else if (ktc.readFahrenheit() < 75)
        digitalPotWrite(153);
        else if (ktc.readFahrenheit() < 78)
        digitalPotWrite(184);
        else if (ktc.readFahrenheit() < 80) //Getting into Danger Zone
        digitalPotWrite(204);
        else if (ktc.readFahrenheit() < 81)
        digitalPotWrite(214);
        else if (ktc.readFahrenheit() < 82)
        digitalPotWrite(224);
        else if (ktc.readFahrenheit() < 83)
        digitalPotWrite(235);
        else if (ktc.readFahrenheit() < 84)
        digitalPotWrite(245);
        else (ktc.readFahrenheit() < 85); //Complete Shutoff
        digitalPotWrite(255);
    {
     Serial.print("Deg C = ");
     Serial.print(ktc.readCelsius());
     Serial.print("\t Deg F = ");
     Serial.print(ktc.readFahrenheit());
     int sensorValue = analogRead(A0);
     float voltage = sensorValue * (5.0 / 1023.0);
     Serial.print("\t V = ");
     Serial.println(voltage);
     int clockValue = analogRead(A1);
     Serial.print("\t Clock = ");
     Serial.println(clockValue);
    }
}

Also, the code I used to test the K-Thermocouple is one that can be found on the internet (with just a little bit of adjustments)...

// Sample Arduino MAX6675 Arduino Sketch

#include "max6675.h"

int ktcSO = 12;
int ktcCS = 9;
int ktcCLK = 13;

MAX6675 ktc(ktcCLK, ktcCS, ktcSO);

void setup() {
  Serial.begin(9600);
  // give the MAX a little time to settle
  delay(500);
}

void loop() {
  // basic readout test

   Serial.print("Deg C = ");
   Serial.print(ktc.readCelsius());
   Serial.print("\t Deg F = ");
   Serial.println(ktc.readFahrenheit());
   int clockValue = analogRead(A1);
    Serial.print("\t Clock = ");
    Serial.println(clockValue);

   delay(500);
}


texts:
I am moving a project from breadboard and jumper cables.
It light a bunch of LEDs with different sets running of many almost every pin.
I need a few meters of cables.
I will a resistor on each led.
I have no idea what kinda cable/wire to use and googling cable gets me nowhere.
What kinda wire do people use?


texts: Data from PROGMEM array mismatches initialisation

texts:
The amount of memory needed for my user interface is outrageous. Hence I decided to use flash memory. But after some successful readouts from program space, problems emerge.

Updated:
I have some sort of initialisation files to collect all global arrays which go into flash like this: (intitialisation.cpp)

#ifndef INITIALISATIONDEF
#define INITIALISATIONDEF

#include "initialisation.h" //which includes Arduino libraries and "globals.h"

const uint8_t gl_PsNMenuType[MAXMENUS] PROGMEM = { 0, 0, 0, 0, 0};  // this is, what I intend to read out later.
const uint8_t gl_PsNMenuParent[MAXMENUS] PROGMEM = { MAXMENUS, 0, 0, 0, 0};
const uint8_t gl_PsNMenuFixTexts[MAXMENUS][MAXFIXTEXTSPM] PROGMEM = {
  { 20, 2, MFTS, MFTS, MFTS}, // 0
  {2, 9, 1, MFTS, MFTS}, // 1
  {2, 10, MFTS, MFTS}, //2
  {2, 11, MFTS}, //3
  {2, 12, MFTS} //4

};
#endif

Updated:
while I propagate all global vars via another header (globals.h):

#ifndef GLOBALS
#define GLOBALS
#define SDTXT

#define MAXMENUS 80
#define MAXFIXTEXTSPM 5

#include "initialisation.h"
extern const uint8_t gl_PsNMenuType[MAXMENUS];
extern const uint8_t gl_PsNMenuParent[MAXMENUS];  // referenz auf den übergeordneten MP
extern const uint8_t gl_PsNMenuFixTexts[MAXMENUS][MAXFIXTEXTSPM];  // Liste der festen Menütexte zu jedem MP
#endif

as one can see, I do not initialise my arrays fully, as I'm in a development phase, but the first bytes should be zeroed out correctly AFAIK.

But, when accessing my stored values later in a third file: (uimenu.cpp)

#include "uimenu.h" // which includes globals.h and initialisation.h

// somewhere in the code inside a function, with uint8_t mp=0:
Serial.print(pgm_read_byte(gl_PsNMenuType[mp]));

The last line should print 0, as stated in initialisation, but it prints 12.

So, I think, I'm doing sth. substantially wrong here, but have no clue at the moment. I have several guesses:

I should not use const with PROGMEM. I did this to be informed by the compiler, if I accidentally write to an array stored in flash.
I made some mess with #includes, perhaps with order of occurrence. At the moment I try to sort the order out.
There's something with having global variables or arrays defined and declared in a header and accessed in another source files function. But I cannot imagene, what.
Updated: something wrong with my indices for my arrays? is uint8_t insufficient?

If you need more information or code, I'll edit my question accordingly. Thanks in advance! I appreciate any help.
(all files were edited for brevity before posting them)

Update:
I moved the definitions of the progmem arrays to the source file and all macro constants (#define) to globals.h. The outcome is: different numbers are printed, but they are wrong whatsoever. I poked elsewhere into the progmem array and got other wrong numbers.


texts:
I am using arduino two ic 4511 and two 7 segemnt I am trying to convert binary into Gray code and on one 7 segemnt I successfully showed binary of number as I use arduino pin 12,13,14 for input and concent with logic state ic 7 segemnt but now I connect arduino pin 3,4,5 with ic and 7 segemnt
I code for it by using xor but it's not working
Example
As first  7 segemnt show binary input  011 decimal which is 3 decimal should show on first 7 segemnt and second 7 segment should show gray code decimal which is 2


texts:
Firstly, I must apologise as I'm a complete noob but the Arduino kits / lego pieces are fantastic and I can't stop tinkering.  Unfortunatley my knowledge does not match my passion.

I picked up a laser from Amazon: FamilyMall(TM) KY-008 Laser Transmitter Module 650nm 5V Diode For Arduino AVR PIC.

I'm wondering what the middle pin is good for and if I can somehow manage to detect and respond to the beam being broken?

Thanks for looking. :)


texts: How to convert this sketch to keep only one if-else statement?

texts:
int ldrPin = A0;
int rainPin = A1;
int smokePin = A2;
int greenLED = 6;
int redLED = 7;

// you can adjust the threshold value
int thresholdValue = 500;
int LightSensorThreshold = 500;
int RainSensorThreshold = 500;

void setup() {
  pinMode(ldrPin, INPUT);
  pinMode(greenLED, OUTPUT);
  pinMode(redLED, OUTPUT);
  digitalWrite(greenLED, LOW);
  digitalWrite(redLED, LOW);
  Serial.begin(9600);

  pinMode(rainPin, INPUT);
  pinMode(greenLED, OUTPUT);
  pinMode(redLED, OUTPUT);
  digitalWrite(greenLED, LOW);
  digitalWrite(redLED, LOW);
  Serial.begin(9600);

  pinMode(smokePin, INPUT);
  pinMode(greenLED, OUTPUT);
  pinMode(redLED, OUTPUT);
  digitalWrite(greenLED, LOW);
  digitalWrite(redLED, LOW);
  Serial.begin(9600);
}

void loop() {
  int lightSensorValue = analogRead(ldrPin);
  Serial.print(lightSensorValue);

  if(lightSensorValue < LightSensorThreshold){
    Serial.println(" - light");
    digitalWrite(greenLED, LOW);
    digitalWrite(redLED, HIGH);
  }
  else {
    Serial.println(" - dark");
    digitalWrite(greenLED, HIGH);
    digitalWrite(redLED, LOW);
  }
  delay(500);

  int rainSensorValue = analogRead(rainPin);
  Serial.print(rainSensorValue);

  if(rainSensorValue < RainSensorThreshold){
    Serial.println(" - It's wet");
    digitalWrite(greenLED, LOW);
    digitalWrite(redLED, HIGH);
  }
  else {
    Serial.println(" - It's dry");
    digitalWrite(greenLED, HIGH);
    digitalWrite(redLED, LOW);
  }
  delay(500);

  int smokeSensorValue = analogRead(smokePin);
  Serial.print(smokeSensorValue);

  if (smokeSensorValue < thresholdValue) {
    Serial.println(" - Smoke");
    digitalWrite(redLED, LOW);
    digitalWrite(greenLED, HIGH);
  }
  else
  {
    Serial.println(" - No Smoke");
    digitalWrite(redLED, HIGH);
    digitalWrite(greenLED, LOW);
  }
  delay(100);

}


texts: Ring topology by using arduino and Bluetooth

texts: I want to connect Bluetooth in a circular ring is it possible to contect 8 arduino with each other via Bluetooth hc05 or hc06  and share data into tha ring..


texts:
I am using an Arduino Uno in my project. I recently found that if I disconnect the power from my Arduino (I am powering it by USB port, from a 5V regulator - 7805), then it remains under power from the input pins. I also found that if I disconnect the 3 digit 7 segment common anode display (which is also powered from same 7805) and if I remove the LM358 (which is again powered from the same 7805) from the socket, then my Arduino is not powered anymore.
My questions are:

Is my setup correct - if I am powering it from the 5V regulator (7805) through the USB port ?
My Arduino and the other components from the schematic - the display, the LM358, the mosfet - will be powered on at the same time, when the 230V switch that is placed on the mains input of the 24V SMPS is closed. Could this be a problem in terms of "phantom powering" ? Is there any better way to power the Arduino when I have 5V regulated supply on the schematic ? I will always keep connected the Arduino to the 5V output of the 7805 to the USB port.

Please find attached 2 schematics, one is the main PCB (the one with Arduino) and the other schematic is the one with the display, which is placed on the front panel. The J2 connector from first schematic is connected pin to pin to the J2 from second schematic.

https://ibb.co/QnLHsM0

https://ibb.co/KxLFKsQ


texts: Sending PUBX commands to GPS Board (Ublox NEO-6M) through SoftwareSerial

texts:
I am having trouble parsing NMEA sentences coming from a GY-NEO6MV2 board (https://www.cytron.io/p-gps-neo6mv2), using the TinyGPS (https://github.com/mikalhart/TinyGPS) library. The GPS board itself is connected to an Arduino Pro Mini 3v3 8MHz (ATmega328)

First of all, to start debugging I want to disable all NMEA sentences other than GGA and RMC (which are the only ones I need for this project)

According to the manual, this can be done by sending PUBX commands through the SoftwareSerial (no need for binary UBX)

I am doing this in the following way

#include <SoftwareSerial.h>
#include <TinyGPS.h>

// GPS SoftwareSerial
// Shares pins with (MISO 12/ MOSI 11) used for SPI

#define GPS_RX_PIN 12
#define GPS_TX_PIN 11

TinyGPS gps;
SoftwareSerial GPSSerial(GPS_RX_PIN, GPS_TX_PIN);

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

      GPSSerial.print("$PUBX,40,GLL,0,0,0,0*5C\r\n");
      GPSSerial.print("$PUBX,40,ZDA,0,0,0,0*44\r\n");
      GPSSerial.print("$PUBX,40,VTG,0,0,0,0*5E\r\n");
      GPSSerial.print("$PUBX,40,GSV,0,0,0,0*59\r\n");
      GPSSerial.print("$PUBX,40,GSA,0,0,0,0*4E\r\n");
}

void loop()
{
// ...
}

However, the GPS board will not respond to these commands and keep sending all the NMEA sentences.

FWIW, this is the original code I'm building my project on - https://github.com/billygr/arduino-aprs-tracker/blob/master/arduino-aprs-tracker.ino

Any thoughts would be appreciated...


texts:
First of all sorry that i dont know much about programming, most of my codes are just copy paste. And of course, i know this question has been asked before, but while using this code:
#include <AccelStepper.h>

AccelStepper stepper (1,7,6);

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

 stepper.setMaxSpeed(100);

 stepper.setAcceleration(20);

  stepper.runToNewPosition(100);

 delay (1000);

stepper.runToNewPosition(0);

delay(1000);

}

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

}

The code worked perfectly once but after resetting the power the code doesnt work in a way that my stepper motor just idles.  Obviously what I want is for the stepper motor to execute the code once per power on. Is there something that i miss? many thanks!