Recent Posts

Pages: [1] 2 3 ... 10
1
Hey PaulS,

thanks for the tips, I looked up operator precedence and I believe my bitshift line should be working the way I am intending. I did fix one thing that seems to help with stabilizing my outputs. I didn't realize that the U/D pin on the HCTL-2022 was an output and not an INPUT. I've been sending from the microcontroller a LOW value to the Quad-Decoder. It seems to be working now.

I believe the issues with consistent output are due to signal stability now. Is there a simple way to stabilize the outputs from the QuadDec with hardware components or perhaps someway in code?
2
A more precise version of the algorithm posted by Jremington would be:
class EMA {
  public:
    EMA(uint8_t shiftFac)
        : shiftFac(shiftFac), fixedPointAHalf(1 << ((shiftFac * 2) - 1)) {}
    int32_t filter(int32_t value) {
        value = value << (shiftFac * 2);
        filtered = filtered + ((value - filtered) >> shiftFac);
        return (filtered + fixedPointAHalf) >> (shiftFac * 2);
    }

  private:
    const uint8_t shiftFac;
    const int32_t fixedPointAHalf;
    int32_t filtered = 0;
};

It performs rounding, and has greater precision. Otherwise, the value could get stuck at a value lower or higher than the actual value.

Pieter
3
Programming Questions / Re: Problem with toCharArray
Last post by davorg - Today at 01:51 am
Thank you very much.
4
Thank you for the fast replay!

I have study this and i think it should work but i don't know if it can work with the switch i have?
5
 Still streams random midi data as if all of the buttons are being pressed. Can someone please proofread?
Code was originally built for a Nano, so some of the comments may not accurately represent the actual pin assignments. A wiring schematic is attached in an earlier post.
6
I know you're probably set with using the barometric altimeter, but an even better choice would be a LiDAR solution like the LiDAR Lite V3. I use it myself on my RC planes and it's much more accurate and reliable than a BMP-180 as long as you have line of sight to the ground and fly under 40 meters.

Just a thought.
7
Hey,
I have big problems with a NeoPixel on my PCB. The µC is an Atmega32U4 and the NeoPixel is an WS2812B. The pixel seems to work fine and the circuit should be good, but when I use the function to select a color in an if-function the color of the pixel is more green. This itself is not the problem, but when I want to turn it off, all colors are gone but green stays. If I do the same in e.g. the setup or the loop it is working.
The Values for R G B are sent from a mobilephone via usb in serial connection and this is working. I´m also getting R == 0, G == 0, B==0 but like I said the pixel stays green...

I hope you can help me..
I need this for a schoolproject and I only have time till thursday...

Greetings from bavaria !!

Code: [Select]
#include <Adafruit_NeoPixel.h>

#include <IRremote.h>

//IR
IRsend irsend;
int number = 0;
const int sendingPin = 3;

//LEDs
int LEDs[8]{ 15,14,13,12,11,10,9,8 };

//Neopixel
#define PIN 17
Adafruit_NeoPixel strip = Adafruit_NeoPixel(1, PIN, NEO_GRB + NEO_KHZ800);


//Serial
byte buffer[4] = {0,0,0,0};
int starttime = 0;

//Temperature
const long interval = 1000;           //interval of the temperaturechecks
const int checkingNumber = 5;         //number of checks
const int ntc = A5;                   //analogRead-pin
const int ntcNominal = 15000;         //resistance at e.g 25°C
const int tempNominal = 25;           //nominaltemperature (e.g. 25°C)
const int bCoefficient = 3528;        //Beta Coefficient(B25 from the datasheet of the NTC)
const int serialResistor = 10000;     //value of the serial resistor
 
int checks[checkingNumber];           //array variable for averaging the temperatur
float averageValue = 0;               //variable for averaging the temperature
float temp;                           //variable for calculation (Steinhart)
float lastTemp;
unsigned long lastTempCheck = 0;      //saves time of last temperaturemeasurement
int lastTempUpdate = 0;

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

 //LEDs
for (int i = 0; i < 8; i++) {
pinMode(LEDs[i], OUTPUT);
}

 //NTC
pinMode(ntc, INPUT);
           
 //Neopixel
strip.begin();
strip.show();
}

void loop()
{
temperature();
serialInterface();
}

void serialInterface() {
if (Serial.available() > 0) {
while (Serial.available() < 4 && ((millis() - starttime) < 1000)) {}

for (int n = 0; n < 4; n++) { buffer[n] = Serial.read(); }

//send temperature to FP
int timeNow = millis();
if (timeNow - lastTempUpdate > 2000) {
Serial.println((int)temp);
lastTempUpdate = millis();
}

switch (buffer[0]) {
case 1:
IRremote();
break;
//LED-Light
case 2:
lightLED();
break;
//RGB
case 3:
neoPixel();
break;
}
}
}

//lights up the 8 LEDs attached to the GPIOs
void lightLED() {
for (int i = 0; i <= 7; i++) {
digitalWrite(LEDs[i], bitRead(buffer[1], i));
}
}

//lights up the Neopixel
void neoPixel() {
strip.setPixelColor(0, buffer[1], buffer[2], buffer[3]);
strip.show();
delay(10);
}

//sends signal via IR-LED
void IRremote() {
//sending selected hex-code
switch (buffer[1]) {
// ON
case 1:
irsend.sendNEC(0xFFB04F, 32);
break;
// OFF
case 2:
irsend.sendNEC(0xFFF807, 32);
break;
// RED
case 3:
irsend.sendNEC(0xFF9867, 32);
break;
// GREEN
case 4:
irsend.sendNEC(0xFFD827, 32);
break;
// BLUE
case 5:
irsend.sendNEC(0xFF8877, 32);
break;
}
}

//checking the NTC and sending temperature to the FP
void temperature() {
int timeNow = millis();
if (timeNow - lastTempCheck > 100) {
//N readouts with a short delay
for (int i = 0; i < checkingNumber; i++)
{
checks[i] = analogRead(ntc);
delay(10);
}

//averaging of the measured values
averageValue = 0;
for (int i = 0; i < checkingNumber; i++)
{
averageValue += checks[i];
}
averageValue /= checkingNumber;

//transform measured value (voltage) into resistance
averageValue = 1023 / averageValue - 1;
averageValue = serialResistor / averageValue;

//convert measured results
temp = averageValue / ntcNominal;     // (R/Ro)
temp = log(temp);                     // ln(R/Ro)
temp /= bCoefficient;                 // 1/B * ln(R/Ro)
temp += 1.0 / (tempNominal + 273.15); // + (1/To)
temp = 1.0 / temp;                    // invert
temp -= 273.15;
lastTempCheck = timeNow;
lastTemp = temp;
}
}
8
Project Guidance / Re: Emergency Brake Reaction T...
Last post by TonyWilk - Today at 01:46 am
I will also be using two Load Cells (one for the accelerator pedal and the other for the brake pedal)
I reckon a Load Cell for the brake makes sense - measure the force applied to the brake, but I think you'd need a position sensor for the accelerator.

Quote
To measure time I will be using the arduino board for that, will this be accurate enough?
Yes, an Arduino could take two measurements at 1000Hz

Question remains: what will you do with the 1000 * 2 measurements per second ?

Do you need to store the values or transmit them somewhere, or simply time between pre-defined 'trip points' of the measurement values ?

Also, I would have thought that the speed of the vehicle would be an important variable.

Yours,
 TonyWilk


 

9
Programming Questions / Re: Using end-stops on CNC shi...
Last post by pert - Today at 01:45 am
From:
https://blog.protoneer.co.nz/grbl-arduino-g-code-processor-pin-layout/
Quote
Limit Switches prevent the machine for over extending each axis and are connected to Pins 9-11.

Note that the jumper on the shield determines whether the switches are active HIGH or active LOW.
10
Just that.
What is the default font for Arduino Serial Output?
Pages: [1] 2 3 ... 10