Working on an Arduino Program to control a Stepper Motor using a small IR Remote and Sensor. Sent signals don't seem to come through [closed] - arduino

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 days ago.
Improve this question
I am having trouble locking in on the "UP" and "DOWN" signal that the IR Remote makes. When testing, I found that I received the number 18 and 52 with UP and Down commands so I converted these values into HEX. This was so that I can create an if statement with both cases defined.
Here is my program thus far:
`#include <Stepper.h>
#include <IRremote.h>
#define STEPS_PER_MOTOR_REVOLUTION 32
#define STEPS_PER_OUTPUT_REVOLUTION 32 * 64 //2048
int Steps2Take;
const int RECV_PIN = 7;
// create an instance of the stepper class, specifying
// the number of steps of the motor and the pins it's
// attached to
//-------------------------------------------------------------
//The pin connections need to be pins 8,9,10,11 connected
// to Motor Driver In1, In2, In3, In4
//-------------------------------------------------------------
Stepper small_stepper(STEPS_PER_MOTOR_REVOLUTION, 8, 10, 9, 11);
void setup() /*----( SETUP: RUNS ONCE )----*/
{
IrReceiver.begin(RECV_PIN, ENABLE_LED_FEEDBACK);
}
void loop() /*----( LOOP: RUNS CONSTANTLY )----*/
{
if (IrReceiver.decode())
{
switch(IrReceiver.decodedIRData.command, HEX)
{
case 0x12:
Steps2Take = STEPS_PER_OUTPUT_REVOLUTION ; // Rotate CW 1 turn
small_stepper.setSpeed(700);
small_stepper.step(Steps2Take);
delay(500);
}
IrReceiver.resume();
}
}`
When this runs, only the IR Sensor and the Arduino blink while the Stepper Motor does nothing.
Wiring Diagram of Components
So far, I've tried rewriting the program with the new IrSensor library to see if it was just deprecated packages causing this. As it turned out, this was not the case.

Related

ARDUINO UNO- Need explains about program

I am begginer on Arduino. I am student and this is my first homework.
Please, could someone explain to me how to understand the following codes. Which code is better? How do operators affect the executive speed? Below is the content.
"The task was to measure the speed of code execution depending on the programming technique used. The program code was designed to expose the high and low states to the D10 (PB2) port respectively without entering delays – as a result, we obtained a rectangular waveform with the maximum frequency for a given program recording method. Programs were written by putting all statements in void setup() omitting the void loop().
Preparation for the exercise consisted in connecting the Arduino Uno board to the USB port, starting the Arduino IDE environment and turning on the oscilloscope. The oscilloscope was used to observe the rectangular waveform generated from the D10 pin (PB2) and to measure its frequency."
Code of the first program:
const byte outPin = 10;
void setup() {
pinMode(outPin,OUTPUT);
while (1)
{
digitalWrite(outPin, HIGH);
digitalWrite(outPin, LOW);
}
Code of the second program:
const byte outPin = B00000100;
void setup() {
DDRB | = outPin;
while (1)
{
PORTB = B00000100;
PORTB = B11111011;
}
Third program code:
const byte outPin =10;
byte state =0;
void setup() {
pinMode(outPin,OUTPUT);
while (1)
{
digitalWrite(outPin, state);
state = !state;
}
Code of the fourth program:
#define _BV(n) (1<<n)
const byte outPin= B00000100;
byte state = _BV(2);
void setup()
{
DDRB|=outPin;
}
while (1){
PORTB |=state;
PORTB &=~state;
}
Code of the fifth program:
const byte outPin= B00000100;
void setup()
{
DDRB|=outPin;
while (1){
PORTB |=B00000100;
PORTB &=B11111011;}
}
As I said I am begginer on ARDUINO UNO. I cannot find any solution to explain exactly my homework.
Which code is better?
The first one, of course. Reasons:
Usually, it's fast enough.
The other ones are hardware specific and do not run on any Arduino, but just on atmega328P microcontrollers.
How do operators affect the executive speed?
It's the call to digitalWrite, which makes the difference, not some operators like ~ . You should look for an similarly hardware independent replacement to digitalWrite, which does the translation between Arduino pin number and hardware register only once at compile time.
BTW: your question is off topic here :)

ESP32 Interrupt jitter at 20kHz

I would like your help to solve the following problem.
I'm using an ESP32 Dev Kit V1 connected as follows:
Pin 4 (input) is connected to a 20kHz and 3.3V signal and to channel 1 of the oscilloscope; and
Pin 2 (output) is connected to channel 2 of the oscilloscope.
My goal is to use interrupts and generate a signal on pin 2 (output) that follows the variations of the signal on pin 4 (input).
The image below illustrates two behaviors. The most frequent and the other one that happens occasionally.
In the first behavior, the latency is around 3 us, but sometimes there is a variation (jitter) and the rise of the output signal takes 15 us or even more to keep up with the input.
I would like to know how to remove this occasional behavior and keep the system stable.
The code that I'm using is below. To compile and upload I am using the latest Arduino IDE version 1.8.13.
I'm using GPIO.out_w1ts and GPIO.out_w1tc because I believe it will be faster than using digitalWrite(pin, state).
Also notice that I'm not reading the state of pin 4 (input) to be faster, because of this, sometimes the output signal gets inverted, but that's not a problem at this point.
#define OUTPUT_PIN 2
#define INPUT_PIN 4
volatile bool state = false;
void IRAM_ATTR interruptFunction() {
if (state)
GPIO.out_w1ts = 0b100;
else
GPIO.out_w1tc = 0b100;
state = !state;
}
void setup() {
pinMode(INPUT_PIN, INPUT);
attachInterrupt(digitalPinToInterrupt(INPUT_PIN), interruptFunction, CHANGE);
gpio_config_t io_conf;
io_conf.mode = GPIO_MODE_OUTPUT;
io_conf.pin_bit_mask = 0b100;
gpio_config(&io_conf);
}
void loop() {
}
The settings used in the Arduino IDE are illustrated in the next image.
Thanks in advance for all the help!

How to make a duty cycle using 2 LEDs using arduino? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
I want to make a duty cycle of 2 LEDs using Arduino in tinkercad. I have 2 LEDs 1 is red and another is green. I want both the LEDs on at the same time but a glowing delay of red led is 1second and green led is 1.3second just like the graph below and having both duty cycle 50%.
but I cant be able to do that I had tried with 2 blocks of if-else but it doesn't work due to its take if-else synchronously then I tried to calculate the graph and want to put it as a delay but it is not an easy solution
I've learned about millis() is the solution but how would I use it?
Please help me to solve this problem
Try this code:
#define LED11_PIN 11
#define LED12_PIN 12
#define LED12_BLINK_RATE 1000
#define LED11_BLINK_RATE 1300
class Led
{
private:
bool _ledState;
const int _ledBlinkRate;
double _lastStateChange;
const int _ledPin;
public:
Led(int blinkRate, int ledPin) : _ledState(false),_ledBlinkRate(blinkRate), _lastStateChange(millis()), _ledPin(ledPin)
{}
~Led()
{}
void update()
{
double currTime = millis();
if((_lastStateChange + _ledBlinkRate/2) <= currTime)
{
_ledState = !_ledState;
digitalWrite(_ledPin, _ledState);
_lastStateChange = currTime;
}
}
};
Led led11(LED11_BLINK_RATE,LED11_PIN);
Led led12(LED12_BLINK_RATE,LED12_PIN);
void setup()
{
pinMode(LED12_PIN, OUTPUT);
pinMode(LED11_PIN, OUTPUT);
}
void loop()
{
led11.update();
led12.update();
}

MeetAndroid with SoftwareSerial issue

I use Amarino with SoftwareSerial (from here: http://www.double-oops.org/mini-blog/amarinowithsoftwareserial ) but I have a strange issue.
It seems that there are some strange behaviour in the MeetAndroid Library. In order to receive events I had to make this changes:
in init() I had to change
ack = 19;
with
ack = 226;
because this is the char I received from the phone at the end of a message
and in receive() I had to change
uint8_t lastByte;
with
char lastByte;
otherwise the
if(lastByte == ack)
won't be true ever
Does anyone have any idea why I had this problems? Why do i get another ack char and why is the if not working for char (ack) and uint8_t (lastByte)
This is my sketch:
/*
Receives Test Events from your phone.
After it gets a test message the led 13 will blink
for one second.
*/
#include <MeetAndroid.h>
#include <SoftwareSerial.h>
MeetAndroid meetAndroid(4, 2, 115200);
int onboardLed = 13;
void setup()
{
meetAndroid.registerFunction(testEvent, 'A');
pinMode(onboardLed, OUTPUT);
digitalWrite(onboardLed, HIGH);
}
void loop()
{
meetAndroid.receive(); // you need to keep this in your loop() to receive events
}
void testEvent(byte flag, byte numOfValues)
{
flushLed(300);
flushLed(300);
}
void flushLed(int time)
{
digitalWrite(onboardLed, LOW);
delay(time);
digitalWrite(onboardLed, HIGH);
delay(time);
}
I found the problem, it is baudrate related. When using software serial I have to use a lower baudrate (9600 for example), otherwise when receiving multiple characters at once it won't work. And since amarino library sends multiple library at once (signaling the start and the end of the message for example) it caused problems when using software serial on slower hardware (like the Arduino Uno used by me). Probably with better hardware (Arduino Mega) changing the baudrate is not necessary.
Example for changing the baudrate is available here:
Receiving multiple chars at once with Software Serial
Long answered short:
When using SoftwareSerial on slower hardware use a low baudrate (like 9600). Also make sure to set the bluetooth board work on the lower baudrate.

I²C with energia and EK-TM4C1294XL

I want to communicate with a SHT21 Sensor from a EK-TM4C1294XL Board.
But it seems that I2C communication is quite difficult with energia.
I used different setups with external Pullup, used the internal pullup and also no pullup. then i tried both I2C interfaces by setting Wire.setModule(0) or Wire.setModule(1) but in all cases the result is that either everything freezes in the Wire.endTransmission() function or i receive only bytes filled with 0.
I basically used this library: https://github.com/elechouse/SHT21_Arduino and modified the example script like this:
#include <Wire.h>
#include <SHT2x.h>
void setup()
{
Wire.setModule(1); // SCL = PN_5 (pin 49), SDA = PN_4 (Pin 50)
Wire.begin();
// optional use this:
// pinMode(PN_5, INPUT_PULLUP);
// pinMode(PN_4, INPUT_PULLUP);
Serial.begin(115200);
}
void loop()
{
Serial.print("Humidity(%RH): ");
Serial.print(SHT2x.GetHumidity());
Serial.print(" Temperature(C): ");
Serial.println(SHT2x.GetTemperature());
delay(1000);
}
There is a boosterpack containing the SHT21 as well, but i did not found any sample code for that... I did not managed yet to get the C stuff running on my linux machine, probably I2C is broken in the energia lib?
Edit: it seems that there is a bug in the library too. The timing must be precise and also 3 bytes are requested and only 2 read. when reading the last byte i do not get good values but at least the loop does not freeze.

Resources