#help-with-arduino

1 messages · Page 67 of 1

twin ginkgo
#

so for my main script for the actual project i have it to turn on pins and stay on so once a pin turns on it stays on till it hits the end then all the pins turn off but pin 0

#

will that loop still work

#

its long but at the end of the script it tells what pins to turn off

reef ravine
#

as an example, the very last bit can be shortened to
if (now.day() == 1) { for (int i = 1; i < 16; i++) { // Set pins 1 - 15 LOW on mcp4 mcp4.digitalWrite(i, LOW); } for (int i = 1; 1 < 16; i++) { // Set pins 1 - 15 LOW on mcp5 mcp5.digitalWrite(i, LOW); } }

#

it'll be a cool project when you get it working

candid topaz
#

is it binary clock?

reef ravine
#

looks like an LED old school clock with hands

candid topaz
#

so many code

#

i think 2 dimensional array would fit here

#

with 1 and 0 to which led to turn on on minute from 0 to 59

reef ravine
#

yes, there is room for improvement, looking at my example above it can be shortened further as well. Just starting out @twin ginkgo ?

twin ginkgo
#

Yeah i was just thinking and i can do the same for each hour and min but instead of low high and the i<i "i = number of time and days for each hour and days so

candid topaz
#

array would be more flexible and can be put on PROGMEM (idk how much memory you have)

reef ravine
#

often you write code just to make it work, then go back and "refactor it" to make it do the same thing with fewer lines of code

twin ginkgo
#

Yeah this code works long wise

reef ravine
#

then as @candid topaz is suggesting even more optimization can be had by using different techniques such as arrays

twin ginkgo
#

Ill learn more later

reef ravine
#

good luck with it, share a pic when you're done!

pine bramble
#

does anyone have use a makeblock orion cuz it seems im having issues with my buzzer and sensors

twilit hare
#

Anyone tried implementing BLE (in arduino) with a M4 (with a ESP32 as a co-processor)? I see that there's an adruinoBLE library available... I though about looking into getting it to work with my PyPortal

stuck coral
#

My understanding is the firmware on the ESP32 is for wifi only on the pyportal but I may be mistaken, to do that wou'd need a new ESP32 co-processor firmware and Im not aware of a pre-made example for you.

twilit hare
#

@stuck coral Thanks. I'm not ready to get into that level of depth (updating ESP32 firmware)... I'll just park my idea until a later point in time. Thanks!

knotty rover
#

@twilit hare I use bluetooth spp on an ESP32, works great, windows 10 support for ble is yucky, so I never touch it

#

ESP32 will support it though

stuck coral
#

Hes asking in context of the pyportal co-processor

#

Normally, you are quite correct

knotty rover
#

my bad, not familiar with that

#

anyone here use ArduinoJson before, the end of my string is getting truncated when i send it over a SPP bluetooth link

stuck coral
#

Yes, if you print it to serial do you see the whole string?

knotty rover
#

I've looked at the output over bt in docklight and unity, and its truncated in both, i'll double check over a wired link

stuck coral
#

Yeah, you need to check over serial to see if its a issue in creating the json document, or if its the bluetooth MTU

knotty rover
#

I've tried a much longer, and a shorter sting, both had the closing } truncated

stuck coral
#

Ah, when you send the document, do you have a size value you provide?

knotty rover
#

only truncated over bt spp

#

yep

twilit hare
#

@knotty rover I had some problems with sending JSON over MQTT because the message buffer wasn't large enough (defaults to 256)... so once I changed that, I was good. That might not be your issue

knotty rover
#

output.getBytes(dat, sizeof(dat));

#

output is the json string, dat is: uint8_t dat[output.length()];

#

guessing a need a +1 to that

#

for a terminator

stuck coral
#

Possibly but to me that wouldnt make a ton of sense

knotty rover
#

doesn't explain it working locally though

stuck coral
#

Well lets just figure out if its printing to serial first, otherwise we're just taking stabs in the dark

knotty rover
#

yes, it prints properly over serial

#

eats the last character over spp

stuck coral
#

Okay, can I see the code? Pastbin if you could

knotty rover
safe shell
#

@twilit hare The NINA firmware (WiFi only, no Bluetooth) on the ESP32 co-processor is developed with the Espressif IDF https://github.com/adafruit/nina-fw, and there is a method for transferring over a new firmware .bin https://learn.adafruit.com/upgrading-esp32-firmware/upgrade-an-airlift-all-in-one-board. But WiFiNINA expects to use the SPI protocol to talk to the co-processor, while ArduinoBLE expects to find the BLE on the main processor. Probably much more straightforward with a standalone ESP32.

knotty rover
#

actually i think the last change may of fixed it

stuck coral
#

Thats good, looking at it you made the correct fix

twilit hare
#

@safe shell Thanks!

safe shell
#

....or an nRF52840 + Airlift FeatherWing / BitsyWing

knotty rover
#

@stuck coral thanks for taking the time to help 🙂

twilit hare
#

@safe shell I'm working on a pyportal project... and I'm thinking about possible "add ons" (to take it to "11"). Alexa has something called an Alexa Gadget SDK that allows you to connect a smart device to an Alexa via BLE... which I why I was asking about using the ESP32 - as co-processor - for BLE.... anyway... I might switch to an nRF + Wing later for the next iteration of the project. Sticking with Wifi is probably good enough for now. Thanks for all your help

twin ginkgo
#

@reef ravine i will tanks

pine bramble
#

I'm learning how to connect a BME280 to a Feather M0 board and I'm apprehensive to make the connections and power it up.

I'm just afraid I'm going to short out the boards and have to buy new ones because I cant afford to buy them right now. It's like $60 for these two and shipping.

For an I2C connection I think the connection would look like this:
Feather - BME
USB - Vin
GND - GND
SCL - SCK
SDA - SDI

As for SPI I'm even more unsure if I'm understanding it. In the example they're using a Metro board and connecting the BME to digital pins (10-13). But when I look at the M0 pinout there isn't anything that specifically says that 10-13 are digital. But I did see that they're PWM pins so I'm assuming that translates to "digital".

https://learn.adafruit.com/adafruit-bme280-humidity-barometric-pressure-temperature-sensor-breakout/arduino-test

Adafruit Learning System

Buld your next weather and enviromental sensing system

reef ravine
#

@pine bramble I2C and SPI are two common types of "communication bus", you only need one, that sensor is designed to allow you to use either. The pins on the Feather are different from the Metro, you'd have to look up which pins are MOSI, MISO, CLK, CS on the Feather you have. If you know you are connected to SCL and SDA on the Feather you can power it up without damaging anything if it's wired as you show above.

lime ridge
#

I have a question ... I've bought one esp32 wroom version and it seems to be working so far. Haven't tried out the bluetooth etc yet. I have a single load cell I'm looking to run stats via bluetooth / wifi. Price and stability wise; are their better options with smaller form factors etc ?

cedar mountain
#

As far as I know, the ESP32 is basically the best option for combined WiFi / Bluetooth, in terms of price and size. I talked to an engineer from another chip-maker, wondering why they hadn't tried to compete in that niche, and he said that Espressif actually did an amazing job with it... his company would have taken 3x the silicon for the same functionality, which would have been way more expensive, so they decided not to even try.

safe shell
north stream
#

I've used chip antennæ like that (in particular, a Taiyo Yuden AH316M245001-T)

safe shell
#

2.5mm, nice

lime ridge
#

Speaking of bodge's library lmao ... Thanks for the updated one for the hx711. My projects finally coming together since I last tried an old library.

#

Esp32 seems to be the perfect board for what I need too so it's nice to hear I picked the right one without even knowing which one to start off with lol

north stream
#

That's not my library, but I like the name

twin ginkgo
#

so i tried if (now.hour() == 10) { for (int i=0; i<10; i++) mcp3.digitalWrite(i, HIGH); } but it did not work i feel like it should have been different

north stream
#

Seems like it ought to work, every time that code gets called, if hour is 10, it should set the first 10 lines of mcp3 high.

twin ginkgo
#

yeah but it doent idk

#
#include <Adafruit_MCP23017.h>
#define NUM_ONES_LEDS 4

RTC_DS3231 rtc;
Adafruit_MCP23017 mcp3;
void setup() {
  // put your setup code here, to run once:
 //mcp
  mcp3.begin(B001);
  mcp3.pinMode(0, OUTPUT);//JAN
  mcp3.pinMode(1, OUTPUT);//FEB
  mcp3.pinMode(2, OUTPUT);//MAR
  mcp3.pinMode(3, OUTPUT);//APR
  mcp3.pinMode(4, OUTPUT);//MAY
  mcp3.pinMode(5, OUTPUT);//JUN
  mcp3.pinMode(6, OUTPUT);//JUL
  mcp3.pinMode(7, OUTPUT);//AUG
  mcp3.pinMode(8, OUTPUT);//SEP
  mcp3.pinMode(9, OUTPUT);//OCT
  mcp3.pinMode(10, OUTPUT);//NOV
  mcp3.pinMode(11, OUTPUT);//DEC
  mcp3.pinMode(12, OUTPUT);//
  mcp3.pinMode(13, OUTPUT);//
  mcp3.pinMode(14, OUTPUT);//
  mcp3.pinMode(15, OUTPUT);//

for (int i=0; i<16; i++) {
  mcp3.digitalWrite(i, LOW);
}

#ifndef ESP8266
  while (!Serial); // for Leonardo/Micro/Zero
#endif

  Serial.begin(9600);

  delay(500); // wait for console opening
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }
  if (rtc.lostPower()) {
    Serial.println("RTC lost power, lets set the time!");
    //rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  }
}

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

void loop () {
  //rtc
  DateTime now = rtc.now();

  Serial.print(now.year(), DEC);
  Serial.print('/');
  Serial.print(now.month(), DEC);
  Serial.print('/');
  Serial.print(now.day(), DEC);
  Serial.print(" (");
  Serial.print(daysOfTheWeek[now.dayOfTheWeek()]);
  Serial.print(") ");
  Serial.print(now.hour(), DEC);
  Serial.print(':');
  Serial.print(now.minute(), DEC);
  Serial.print(':');
  Serial.print(now.second(), DEC);
  Serial.println();

  Serial.print("Temperature: ");
  Serial.print(rtc.getTemperature());
  Serial.println(" C");

  Serial.println();
  delay(1000);
  
  if (now.hour() == 10) {
   for (int i=0; i<10; i++)
    mcp3.digitalWrite(i, HIGH);
  
}```
#

full test code

#

before i emploment it into the main script

spiral copper
#

Guys, I coded a software in C#, I want to implement this with an arduino, can someone tell me how can I implement this source code of the software into the Arduino?

#

Do I add some sort of code into the software's source code to have the Arduino connect with the software?

stuck coral
#

No, Arduino uses wiring which is derived from C

#

C# is kinda just for microsoft related stuff

#

For an bit of hardware labelled arduino, unless there is a framework and complier Im not aware of which is possible than you're outta luck

reef ravine
#

@twin ginkgo is it actually executing if (now.hour() == 10)? Also, it looks to be missing the closing } for the if (and both {} in the for)

twin ginkgo
#

no its checking if hour is 10

reef ravine
#

is the if statement true? maybe it never runs the code inside the if. If you put a print statement inside the if you can tell.

#

it doesn't throw errors about the missing brackets?

obtuse spruce
reef ravine
#

@obtuse spruce are the curly braces around the for statement optional?

stuck coral
#

@obtuse spruce good suggestion, I was going to give a versions with constants but thats way cleaner

obtuse spruce
#

In C/C++ compound statements (if, while, do, for, etc...) are all followed by exactly one statement... if you want multiple lines, you can make that one statement be a block with { and }.... but if you have just one statement, there is no requirement to make it a block.

twin ginkgo
#

thanks @obtuse spruce but that is actualy just a test script my other script is a lot more then that

reef ravine
#

thanks @obtuse spruce

obtuse spruce
#

Also - note the way Serial is initialized... you call begin() first, then do the while (!Serial); to wait for it to be ready, not the other way 'round.

#

er - reload that code, the original works, but I cleaned it up some

#

also, made use of Serial.printf which works with Adafruit cores - if you can use it, makes your much easier to read (and usually smaller footprint as well!)

#

@twin ginkgo - sure - I just thought a little code clean up would make the code a bit more clear, and easier to debug

twin ginkgo
#

oh ok thanks im not a strong scripter but im getting there its my first time working with i

cunning reef
#

Hello, please excuse my cluelessness, Because I'm completely new to programming of any kind. I have an Arduino Mega2560 and I'm wondering what the digital I/O pins do. Can somebody tell me?

north stream
#

Pretty much what their name implies, you can set them as inputs (to get data from switches or sensors or whatever) or outputs (to send information to displays, LEDs, turn on transistors, etc.)

cunning reef
#

So they're the same as pin 3-13 in the analog in section? I assumed they were until my LED burnt out, and that completely threw me off.

#

Maybe my LED burnt out for a different reason

north stream
#

A current limiting resistor is a really good idea when using LEDs. The analog pins can do the same input and output as digital pins, but also have the additional ability to digitize an analog value (so instead of just "on" or "off", they can measure the magnitude of a voltage)

cunning reef
#

Yes, I had a 330 ohm resistor in series with the LED.

north stream
#

Ah, that should be fine. Maybe you just had a duff LED (it happens)

cunning reef
#

that would make sense. It was very new, I got it in an Arduino kit for my birthday. Oh well. Thanks for your help!

twilit hare
#

hey, rando question. I'm about to order a capacitive touch sensor - Adafruit has both the MRP121 and the CAP1188 available. Anyone use both, and have an option on one versus the other?

lime ridge
#

So what's the best route when it comes to sending data via bluetooth to a phone ? mqtt or are their any good BLE options ? Trying to avoid costs if anything lol

stuck coral
#

Bluetooth GATT is the usual way of sending data

pine bramble
#

@reef ravine thank you for the clarification. I'll look up MOSI, MISO, CLK, CS and try to figure out what's what on each board.

atomic wadi
#

I'm trying to turn on a Vizio TV with an IR LED connected to an Arduino Nano.

So far, I have the sketch set up to turn the IR LED on / off, but I don't know the duration for each pulse. Without using a receiver, is there any way to know how long these should be?

cedar mountain
#

Typically IR remote signals are modulated at 38 kHz, and there's a simple command protocol on top of that.

#

But the exact code will vary from device to device... you may be able to look it up in a universal-remote guide for your TV.

twin ginkgo
#

ok so everything in my script but the days work if someone can see what might be wrong leds don't want to turn on and i checked on a separate script to test the leds and chips and they light up when i call them to

#

months hours min's work but not the days

cedar mountain
#

By "not work", what does it do instead? I'll note that your I2C addresses are a little weird, in that you're counting mcp1,2,3,4,5 as 0, 1, 2, 4, 3. So you may want to double-check the address pins.

twin ginkgo
#

just does not want to light up but if i go to another script and turn one led on at a time they work

#

i would change the mcp5 to mcp4 and change pins to test and it does work

#

but not in the main script

cedar mountain
#

Does "day" print out correctly?

#

(By the way, your code could be simplified a lot by using some variables instead of if statements.)

obtuse spruce
#

That code needs some for loops and helper functions -- I'd be happy to prepare an example

#

most because, as you've found, it is very hard to debug long sequences of replicated code.

obtuse spruce
#

I can't see where the error is in the 600+ line version, as it is probably some typo in the days code.

#

The big change I suggest is stop trying to be clever about turning on and off lights - it is too hard to reason about, and is prone to errors if, say, the RTC skips a second somewhere.... Instead, the code I gave sets ALL lines HIGH or LOW for each component of the time everytime through the loop

#

this is safe, in that setting the outputs isn't dependent on the prior state of the output

twin ginkgo
#

i was thinking that error in type but i looked it over i cant find it i tried to make it easyier to see by saying whats on and whats days

fallen canyon
#

is there a stop command in the arduino code that will prevent the program from running further? trying not to use a bunch more if statements than i really need to.

vivid rock
#

@fallen canyon

while(true) {}
obtuse spruce
#

@fallen canyon - do you mean you want to halt all further processing - or "I'm just done with this time through loop()"?

tidal peak
#

so I'm trying to look into inline assembly (something I just want to mess with) and I've been looking into some example codes. I was wondering if someone can tell me the reasoning behind this label? like why with the
.L%=

".L%=_byte_loop:\n"
fallen canyon
#

well more like if condition in part a of the loop is true then no longer run the rest of the code after point x

#

i can make that happen with if statements but was curious if it had a command directly for it

obtuse spruce
#

well, if you are done running all code - @vivid rock 's while loop will halt things until you reset. --- if you are just done with loop for now, but maybe run later, perhaps something like this is what you want:

void loop() {
  int noodleTemperature = ... some code here to read a sensor ...;
  if (noodleTemperature < 85) {
    // meh, cold noodles
    delay(1000); // check again in a second...
    return;
  }
  // do lots more stuff here
}
fallen canyon
#

so return is the command to make it restart the loop

obtuse spruce
#

well - return exits the current function (loop in this case)....

#

Now it turns out that the code that called loop, basically calls it again and again:

void main() {
  setup();
  while (true) {
    loop();
    yield();
  }
}
#

so, your return will exit loop, returning to the caller (main), and since that is in a while loop, it'll come around again - and call loop again, which start start again from the top of the loop code

fallen canyon
#

actually thinking about it more is the ioref pin on the arduino uno used for an on off function? what i am trying to do is make an on off switch to the board or at least stop the loop from running

obtuse spruce
#

no, it isn't - that is just a power pin.

fallen canyon
#

ok

#

then code side it is

#

thanks for the examples up there i will see if i can butcher it on my end lol

fallen canyon
#

is there a way to force a pin through code into a normally low state so i dont have it flipping back n forth between high and low till i put power to it?

#

outside of being a pullup

safe shell
#

Is it an output? Just set it low until you need it high.

fallen canyon
#

@safe shell is that done with the pinmode on setup?

#

and itd be an input

#

also the pullup resistor ones are the ones with the tilde on them right?

thorn relic
#

inputs are high-z or pull up

fallen canyon
#

or can that be any pin

thorn relic
#

unless you want open collector mode?

fallen canyon
#

whats open collector?

#

im new to arduino so not all these terms are known to me yet

safe shell
#

what processor board are you using?

fallen canyon
#

last time i had to go pulup on the pin so it would throw between low and high constantly

#

i have an uno

thorn relic
#

what is on the input

fallen canyon
#

im gonna be using it for an on off switch for my stepper drivers

#

planning to make it output to the enable on the drivers when the pin is given the 5 volts

safe shell
#

if you don't have INPUT_PULLDOWN and don't want an external pull-down resistor, you could reverse the logic and use INPUT_PULLUP so it's normally high, then ground that pin when you want to activate

fallen canyon
#

i dont know if i have the pulldown option on the uno

#

i know i have the pullup option and can use that as well

#

got a bunch of reed switches for limit switches. but i am gonna have to figure thiose out

#

so thats part of the reason i wanted to find out if there was a way to do that

#

so doing some research i can just throw a 10k resistor as a pulldown from what i am understanding right?

safe shell
#

@fallen canyon you could use an external pulldown resistor with INPUT, and the reed switch would then connect a high value to the input pin and the code would be looking for a high value to trigger action. Or with INPUT_PULLUP, the reed switch would ground the input pin and the code would be looking for a low value to trigger action, no external resistor needed

fallen canyon
#

yeah @safe shell i was thinking about that too but i need to have 8 reed switches and i havent counted them but the ones that can be marked as pullup are the pins that are marked with a ~ right?

safe shell
#

@fallen canyon I think the tildes are for PWM, almost any pin should be able to do digital input

vivid rock
#

indeed, ~ denotes PWM pins
All pins can be used as digital i/o, and any pin has internal pullups available.

#

just be careful with D0 and D1 as they are also used by the USB (to be precise, serial-to-usb)

fallen canyon
#

alright cool that makeds things that much easier then

#

yeah im avoiding d0/1

#

using 2 through 13 and the analog

vivid rock
#

BTW, uno has internal pull-ups but no internal pull-downs - for that you would other boards, such as those based on m0 chip

fallen canyon
#

alright no biggie i can just reverse the logic and wire to ground

#

thanks for all the info guys

#

ohh and also

#

what does PWM mean?

vivid rock
#

pulse-width modulation

#

this is when a pin is swithcing between on and off at given frequency, with certain part of the cycle being on

#

this is what you really get when you use "analogWrite()"

#

and this is also what you need, e.g., for controlling servos or dimming led's

fallen canyon
#

so thats proabably what i need to have running my pulse on the drivers for my steppers

vivid rock
#

stepper drivers work differently, so you do not control them using analogWrite(), but there is no harm in using PWM enabled pins for them

fallen canyon
#

alright so it dont matter either way

#

good to know

#

thanks shurik.. and your tank project there is pretty slick. now all ya need is a second camera on a turret

vivid rock
#

thanks!

twin ginkgo
#

can someone link me something how to use a 7 segment 4 digit display without backpack

reef ravine
twin ginkgo
#

thanks

reef ravine
#

that's why they make backpacks, only need 2 wires 🙂

tidal peak
#

so I'm trying to look into inline assembly (something I just want to mess with) and I've been looking into some example codes. I was wondering if someone can tell me the reasoning behind this label? like why with the
.L%=

".L%=_byte_loop:\n"
cedar mountain
#

I'm not familiar with that exact syntax, but the %= is sometimes used to create a unique numerical label, so that if you have an inline function, the assembly will be different in each instance.

spiral copper
#

Is it ok to ask a question about C# here?

#

It's kinda related to Arduino but not really at the same time.

distant plinth
#

#include<UltraDistSensor.h>

                        ^

compilation terminated.

exit status 1
Erreur de compilation pour la carte Arduino/Genuino Uno

#

why im getting this error guys , the same code was working 1 month ago <@&617066238840930324>

north stream
#

The error message itself is missing, so we can only guess. Possibly a library issue?

lilac zodiac
#

hey all, can someone help me with a basic arduino code to set up a melody with LEDs? i dont have a clue where to begin

north stream
distant plinth
#

The error message itself is missing, so we can only guess. Possibly a library issue?
@north stream

#

yes it was, i just redownloaded it 🙂

#

thanks a lot my friend 🙂

obtuse wedge
#

hello! regarding PID's. I've a heating system with 30s of inertia between actuator and sensor. I've set Kp = 1, Ki = 0.2 and Kd = 0.8. I know this is a very system dependant question, but could you share some insight?

#

does the values look noice? 🙂

safe halo
#

If I want to check every character of a char[] would this do the trick?
This is the string Format
1999138596,#1496,27/07/20,14:52,6.060,-28

        switch (recievedData[i])
        {
        case "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ",", "/", ":", "-","#","." :
          /* My code is Here*/
          break;
        default:          
          break;
        }

cedar mountain
#

I think you need single quotes for a char constant... the double quotes produce a length-1 string instead. But other than that, it should work.

obtuse spruce
#

@safe halo - was your intention to run /* My code is Here */ once, if all the characters of the string are in that set... or was it to run that code once for each character?

#

also, you can't write multiple case values like that... each needs case.

#

So - assuming you want to check all the characters for conformance to that set before running your code... to do it like you're doing with a switch statement, you'd do something like this:

bool good = true;
for (int i = 0; i < strlen(receivedData); ++i) {
  switch (receivedData[i]) {
    case '0':
    case '1':
    case '2':
    case '3':
    case '4':
    case '5':
    case '6':
    case '7':
    case '8':
    case '9':
    case ',':
    case '/':
    case ':':
    case '-':
    case '#':
    case '.':
      break;
    default:
      good = false;
      break;
  }
}
if (good) {
  /* my code is here */
}
#

But that code is awkward and long... and use of a library function strchr makes it cleaner:

bool good = true;
for (auto c = receivedData; *c != '\0'; ++c) {
    good &= strchr("0123456789,/:-#.", *c) != nullptr;
}
if (good) {
  /* my code is here */
}
#

Also, notice how the loop was re-written - calling strlen inside the for is unnecessary expense. Not a big deal, but poor form.

#

Once you get use to the common string functions:

if (strspn(receivedData, "0123456789,/:-#.") == strlen(receivedData)) {
  /* my code is here */
}
safe halo
#

I am checking than there are no bad chars in the array such as anything that is not in the switch
Im setting a boolean and then if the Boolean is true at the end of the loop Ill run another method

obtuse spruce
#

Good... in the examples here, I've included the loop - because, as you can see in the last example, you don't really need to code a loop -

#

That last function strspn asks "how many characters from the start of this string are all from this set?" - if that number is the length of the string, then all the characters are in the set.

#

(also - i fixed my code from the first one - d'oh!

safe halo
#

I just want to check if anything thats not in those charachters are present. Like this string would be bad

1999138�96,#25�,27/07�20%17:28,6.0␆0,-38```
obtuse spruce
#

yup - do you need to run code once for each bad character? or only once if there are any bad characters?

safe halo
#

no once it finds a bad char it can stop

obtuse spruce
#

You can use any of the forms above to do so.... just test for !good or in the last one use !=

#

you are on the right track - and your switch idea will work - as long as you fix the case statements (you need one per character... which is verbose, but oh well... C/C++!)

safe halo
#

I had split them up but I do like less code for the same answer

obtuse spruce
#

right, but in C/C++ you can't write case 'x', 'y':

#

you have to write it case 'x': case 'y':

safe halo
#

you have to write it case 'x': case 'y':
@obtuse spruce So that would have them all inline then

obtuse spruce
#

yup - though they can be on separate lines, like in my example

safe halo
#

so under each case would I have to put thegood=true

obtuse spruce
#

you can write:

#
case '0':
case '1':
case '2':
...more here...
case '.':
  good = true;
  break;
#

Each case labels a point where the switch statement jumps to to execute - you can have several labels all before a statement.

#

mind you - in this situation - you don't need to set good = true at all - look at my code example... good is presumed true (by setting it before the switch) --- and only set false if a non-good character is found. Once set false, it'll remain so even if subsequent characters are good.

#

Of course you could break out of your loop once good is false, but there isn't really a need, since most of the time (on good data) you need to test every character... so testing them all when one is bad, is a bit wasteful... but doesn't happen all time time (one assumes)

safe halo
#

Once it happens I just do a device reboot to fix the issue.

obtuse spruce
#

right, but it'll be about the same if the loop runs to the end, and then the code says "if they weren't all good, reboot"

#

so make the code easier, don't worry about the optimization of stopping as soon as one bad character is found.... do what every makes the code simple and clear.

safe halo
#

Here is the final Code

void ReadLoRa()
{
  // try to parse packet
  int packetSize = LoRa.parsePacket();
  if (packetSize)
  {
    char receivedData[50];
    char startChar = (char)LoRa.read();
    if (startChar == (char)126)
    {
      String incoming = LoRa.readString();
      incoming += ",";
      incoming += LoRa.packetRssi();
      incoming.toCharArray(receivedData, sizeof(receivedData));

      bool good = true;
      for (auto c = receivedData; *c != '\0'; ++c)
      {
        good &= strchr("0123456789,/:-#.", *c) != nullptr;
      }
      if (good)
      {
        Serial_Debug.println(receivedData);
        for (size_t i = 0; i < 5; i++)
        {
          if (client[i] == true)
          {
            ws.sendTXT(i, receivedData);
          }
        }
        display.clearDisplay();
        display.setCursor(0, 0);
        display.print(incoming);
        display.display();
        LoRa.flush();
      }
      else
      {
         LoRa.flush(); 
      }

      /* code */
    }
  }
  else
  {
    LoRa.flush();
  }
}
obtuse spruce
#

Looks good

#

though, once you are using String, there is little reason to convert it to a char array. Check out WString.h for all the things you can do with it.... you'll find what you need... and you just print them directly, too.

safe halo
#

I did that because the LoRa library requires a Char[] to transmit.

obtuse spruce
#

You can use .c_str() to get a point to the the char[] inside a String. So long as you know the String is still alive, you can use that pointer.

#

In your code, you're fine, as String incoming lives longer than than the call to ws.sendTXT -- so just use ws.sendTXT(i, incoming.c_str());

tidal peak
#

so I'm looking at this inline assembly code and I come across this "rjmp .L%=_bit_loop\n", why would you want to use rjmp over jmp?

rotund nebula
#

can someone help me please

lone ferry
#

@rotund nebula You need to ask the actual question.

rotund nebula
#

yes

#

this is my code but i am getting errors

lone ferry
#

That's very vague. 😉 Which errors and where?

nova comet
#

anyone have experience with arduino bluetooth?

#

Im running a bluetooth module on mine right now

#

and when i send info via the DSD app on the ios app store

#

like this

#

i get weird output on the arduino side

#

like this

cedar mountain
#

248 would be 0xF8. Is that what you sent during that test?

nova comet
#

I sent just ‘3’

#

And both the 248 and 0 popped out

#

When i printed the data

#

@cedar mountain

obtuse spruce
#

@nova comet - can you drop your code in a gist (https://gist.github.com/) -- so we can see the whole code - and indicate which line is printing 248....

One think I immediately noticed is that in the double nested for loops where you print out the board matrix... there is no space printed between values.... so if a file has values 12 and 3 -- it'll print the same as a file with 1 and 23.

nova comet
#

The board matrix isnt what is printing ill show ya

obtuse spruce
#

I didn't think so - but I thought I'd point that out anyway

nova comet
obtuse spruce
#

er - so which print is that output coming from?

#

oh - line 62 I bet

#

hrm.... nothing obvious - but the "HEX TX (*) ON" control in the App is suspicious. Perhaps turn that off?

nova comet
#

I can try that

nova comet
#

@obtuse spruce when i use no hex tx and i send '1'

#

i get

#

120 followed by 128

stable hamlet
#

hey guys. would someone like to help me write a code that im not able to write.

im new to arduino and wanted to make a simple parking sensor.
and i think im missing an "if" and "else" function in my code to make it how i want it.

if anyone can help me with that if and else function i would be glad

#

i want a parking sensor with an ultrasonic sensor.

i got the code to the point where it measures the distance.

but now i want the code to make a LED light up and get faster the closer you get

and as the LED lights up a buzzer makes noise at the same time as the LED blinks

nova comet
#

@cedar mountain any ideas?

stable hamlet
#

should i paste my code here?

stuck coral
#

Sure, go ahead and give me a pastebin

nova comet
stable hamlet
stuck coral
#

@nova comet is there anything in the documentation from the module about what it returns?

stable hamlet
#

im getting cm values if i use the seriell monitor

#

3cm is the closest it can measure.

and i think it has range till 400cm

stuck coral
#

@stable hamlet You just need help with an if statement? An if statement evaluates if something is true, so if figure out what disstance it is that you want something to happen, you can create a new variable say const long threshhold = your_number; then you create a statement using operators https://www.tutorialspoint.com/cprogramming/c_operators.htm. so for example if(threshhold>=cm){ // Code you want to execute when that happens here }

nova comet
#

i think i got it one min

#

might have been the serial baud

stable hamlet
#

const long threshold = 100 (for example) comes in the beginning to all other const variables?

stuck coral
#

Well const just makes it constant, meaning its not meant to change

#

Another way would be #define THRESHHLD your_number

stable hamlet
#

if(threshhold>="50" "cm"){ //not sure what to put next to >=
digitalWrite(ledPin, HIGH);
digitalWrite(buzzPin, HIGH);
}
else {
digitalWrite (ledPin, LOW);
}
}

stuck coral
#

What I put was the variable you already defined on line 16, cm

#

"50" would be a string, and you cannot compare a number and a string object

#

If you define threashhold then if(threshhold>=cm){} will work if you put it after line 25.

stable hamlet
#

so
#define treshhold 50
and
if(threshhold>=cm)

stuck coral
#

Yeah

stable hamlet
#

getting an error now

#

entfernung_messen:40:1: error: expected declaration before '}' token
}
^
exit status 1
'microsecondsToCentimeters' was not declared in this scope

stuck coral
#

Put microsecondsToCentimeters() above your setup

stable hamlet
#

as an "int"?

stuck coral
#

No, copy your function named microsecondsToCentimeters() and put it above your set() function

stable hamlet
#

const int trigPin = 7;
const int echoPin = 6;
const int buzzPin = 5;
const int ledPin = 4;

#define threshhold = 50;
long duration;

microsecondsToCentimeters(duration);

void setup()

#

like this?

stuck coral
#

Well, that isnt what I meant but technically that should declare it if you put long before microsecondsToCentimeters and duration. I mean to copy the entire function you defined that is microsecondsToCentimeters() with the {} and the code inside it

stable hamlet
#

im so sorry .. im confused

#

could we screenshare or somehting?

stuck coral
#

I would rather not, you need to declare the function microsecondsToCentimeters() before you call it and you have it defined under main()

#

All the code under the main(){} function you shared with me, cut, and paste on line 7 before setup()

ripe flint
#

this is the airlift coprocessor, if that helps:

stable hamlet
#

i hate that english is not my main language...

#

i undid everything. starting with the paste i sent you again

ripe flint
#

yes

stuck coral
#

Hm, my code formatting stopped working, first comment out lines 20-45 if you're going to command out the top bit of the constants

stable hamlet
#

FML................... i thought you ment i need to copy line 25 and put it there

#

jeeesus... that wouldve been long to figure out

ripe flint
#
19:34:06.996 -> WiFi Scanning Test
19:34:07.098 -> enter loop
19:34:07.098 -> Statuses: 
#

I commented out those lines and this is all I get

#

something seems to break in or right before the while loop. I think it has something to do with the WiFi.status(), but im not sure

stuck coral
#

It would mean it's getting stuck in WiFi.status() if you don't see it printing Communication with WiFi module failed!

#

You have the right baud rate at the bottom of the console 9600?

ripe flint
#

yes

stuck coral
#

Okay, I dug through the source code for the lib, are you sure you have the module connected correctly? If the INT line is not connected or is connected to the wrong signal it looks like it can hang from the master branch

#

If the ACK pin connected to SPIWIFI_ACK? Pin 1

ripe flint
#

yes that is connected to digital 1

stuck coral
#

Could i see your setup with the board and co-processor?

ripe flint
#

sure. One sec

#

let me know if you need to see it at a different angle or something, it not the best organization, but this was just going to be a quick test

stuck coral
#

I would disconnect that from power ASAP

ripe flint
#

uhoh. why?

stuck coral
#

Send me a link of the board you have?

ripe flint
stuck coral
#

Alright, go ahead and connect it back up, normally you cannt connect 3.3V logic like a ESP32 to a 5V device like the one you have, but the ESP32 airleft has a level shifter so it's all okay

#

Although from what I can see the ESP_BUSY line doesnt go through the level shifter....

#

So you might not be able to reliably sense it, since you're using it as a input on your 328 board it wont damage anything

#

Weird that doesnt also go through the level shifter, aswell as the MISO

#

Where did you get that library? Library manager? I cant get that to compile

ripe flint
#

I downloaded it from the walkthrough page and then pulled up the example, I set the board as an uno as the metro mini page says as well

buoyant drum
#

Can I upload a sketch from an Arduino Pro Mini using a USPtinyISP and a windows laptop? Not sure if this message is going out and in the proper format or area/location. Please advise if so.

stuck coral
#

@ripe flint Im going to make you a quick library branch

ripe flint
#

okay

stuck coral
#

First, could you try adding WiFi.init(); right after WiFi.setPins()?

ripe flint
#

`'static void WiFiClass::init()' is private within this context

#

thats the error that appears

stuck coral
#

Hm, alright... yeah I see you're not supposed to be able to use that, I see the metro has "some" 3.3V inputs so let me take a peek at which ones that is

safe shell
#

I think the assumption is that 3.3v out to a 5v device will be above the threshold for high

#

all the inputs on the airlift have level-shifting

stuck coral
#

Not the BUSY or MISO

#

But I would agree 3.3V would be above the threshhold

safe shell
#

BUSY and MISO are outputs from the airlift

stuck coral
#

You are right

5V logic with 3.3V compatible inputs

ripe flint
#

BUSY - this pin is an input from the AirLift, it will let us know when its ready for more commands to be sent. This is 3.3V logic out, can be read by 3-5V logic. This pin must be connected.

stuck coral
#

Connections look good to me, not sure why it would be hanging unless it cant read the BUSY signal looking at the library

ripe flint
#

okay, question though, are there supposed to be any LEDs active on the airlift when power is given ?

stuck coral
#

One is not connected to 3.3V, its unclear to me if one is if the ESP32 boots it just mentions you can use them from the library

fallen canyon
#

void loop() { while (digitalRead(onoff) == LOW) { digitalWrite(slide_enable_1, HIGH); digitalWrite(slide_enable_2, HIGH); digitalWrite(slide_enable_3, HIGH); digitalWrite(slide_enable_4, HIGH); }

with this code block here as soon as i activate my switch it keeps the slide enabled as high. do i need to enable them as normally low or would i have to do something like an else

#

if there is a better way than using an if statment that would be cool if someone knows just ping me please. thanks guys n gals

stuck coral
#

loop() acts like a big while loop, you can change the while to a if and prodide an else to turn them off

fallen canyon
#

yeah i got a bunch of if else now thats working the way i intended

#

but i was hoping for a more efficient method...

stuck coral
#

What do you mean you have a bunch of if else?

fallen canyon
#

one moment let me haste it\

#

gotta have a bunch of areas so i can enable or disable the drivers when they hit my limit switch\

stuck coral
#

Im not understanding your complaint

#

Looks normal to me, maybe add toggles but that I would consider all of that to be correct.

fallen canyon
#

not really a complaint just trying to be efficient

#

i know in other languages if else if else is slower especially nested if statements

#

thast why i was wondering about the efficiency

stuck coral
#

Not in c, Im not sure what languages your refer to, and thats not many if statements

fallen canyon
#

gonna have alot more lol

#

thats just the start i have 3 more drivers ill be making use of that will be using the if else setup for other pins for my limit switches

#

anyways thats good to know... thanks for the info IoT

stuck coral
#

You can get to too many if statements, and a lot of times when you get into that situation you need to write functions or switch statements

safe shell
#

@ripe flint There won't ordinarily be any LEDs lit on the Airlift breakout, unless you either activate R, G, or B, or if the library does for network activity.

obtuse spruce
#

@fallen canyon - In compiled code, like this, you shouldn't be too concerned about the execution time of if / else or switch - it's all very quick compared to other things.

#

What you should be concerned about is expressing the logic of what you want done - so code clarity should be the top priority.

fallen canyon
#

ill add in comments later

#

to explain it

#

most of it at this point is to get it working on all 8 limit switches

obtuse spruce
#

better to just make the code say it directly, than add comments (! - and yes, I'm a Sr. Software Architect - and I tell my teams this all the time!!)

#

give me a second, and I'll show you.

fallen canyon
#

sounds good

obtuse spruce
#

if you try to expand this code, in the form it is in, to 8 limit switches - you'll go nuts!

fallen canyon
#

haha

#

im already nuts

#

i have all my slide in and out limits names in the pins

#

so when i read it i understand whats going on based on my application. but i will gladly take any advice especially from someone who does this kinda thing daily

obtuse spruce
#

your current code can be re-written as:

  uint32_t enableSlide = (digitalRead(onoff) == LOW) ? HIGH : LOW;
  digitalWrite(slide_enable_1, enableSlide);
  digitalWrite(slide_enable_2, enableSlide);
  digitalWrite(slide_enable_3, enableSlide);
  digitalWrite(slide_enable_4, enableSlide);

  bool checkIn = (digitalRead(switch_pin) == LOW);

  uint32_t pinToCheck = checkIn ? limit_slide_in_left_1 : limit_slide_out_left_1;
  uint32_t limitHit = digitalRead(pinToCheck) == LOW;
  digitalWrite(slide_enable_1, limitHit ? HIGH : LOW);
  digitalWrite(dirPin, checkIn ? LOW : HIGH);
#

notice the use of ? : operators: Learn them as they can reduce piles of nested ifs into clear code;

fallen canyon
#

now that was more of what i was lookin for... much cleaner more efficient

#

but

#

i dont understand alot of the calls you have there

obtuse spruce
#

again - don't worry about the efficiency in execution - it is efficient in expression!

fallen canyon
#

as this is my first basic c code ive ever written

obtuse spruce
#

That's fine - let me help you understand it - all the calls are the same ones you had.

#

ask away!

fallen canyon
#

uint32_t

#

i have no idea what that means there

obtuse spruce
#

that is just the type of the variable.... so the compiler knows how big, and what kind of value enableSlide is.

#

Now - how did I know it should be uint32_t (unsigned integer, of 32 bits) --- because I looked up what the functiondigitalWrite takes as the first and second arguments - and we find this:

extern void digitalWrite( uint32_t dwPin, uint32_t dwVal ) ;
#

So we know that the first and second arguments are both of type uint32_t -- so if I'm going to make a variable, enableSlide or pinToCheck - and use that variable in calls to digitalWrite, the varibale should be the same type.

#

So the first line of my code says "make a variable of type uint32_t, named enableSlide, and set it to either HIGH or LOW, based on the result of reading the pin onoff"

fallen canyon
#

ok so its actually taking the portion of the code that its reading in the boolean and reversing it when the switch is high or low

#

instead of having to reverse by reading the if else

obtuse spruce
#

yes - and more importantly - without having to duplicate code in both the if and else blocks - because that is a source of errors: One day you'll add a line to one side, and forget to add it to the other. The way I wrote it you can't forget, 'cause there is only one path!

fallen canyon
#

ok ill study it a bit more and hope my brain dont do a short circut on me while trying to decypher it

#

( uint32_t dwPin, uint32_t dwVal ) ;

#

that there is Digital Write pin and the Digital Write value right?

obtuse spruce
#

yes - the line I showed you is the "function signature" from the header file that defines the function for the compiler. It says "the first argument is of type uint32_t, and is named dwPin. The second is of type uint32_t and named dwVal" -- Turns out the names - like this in the header file - are for you, not for the compiler, since they aren't used here at all..... "dw" is someones odd way of repeating the name of the function - there really isn't any need here.

#

If I were writing that header file, I'd write:

extern void digitalWrite(uint32_t pin, uint32_t value);
#

which would be - IMHO - be more clear

fallen canyon
#

i mean i follow that better than the shorthand bits there

#

so i can agree for sure there

obtuse spruce
#

heh - I left out your commented debugging line... it becomes:

  Serial.println(checkIn ? "LOW" : "HIGH");
#

notice how useful the ? : form is - it keeps you from having to repeat code

fallen canyon
#

checkin ? "low" : "High" what is the ? doing there... i dont quite follow how this works... takes me a bit as my brain is mor mechanical and geometry style than algebra which is kinda what im gettin here

obtuse spruce
#

No problem - let me help you see it - it isn't hard.

magic field
#

test ? result_if_test_is_true : result_if_test_is_false;

obtuse spruce
#

the test is just like what you would have in if (test) ...

#

the two possible results must be the same type of things: both numbers of the same type, both characters, both strings, both serial ports, etc....

#

So in the debugging line, checkIn ? "LOW" : "HIGH" is passing either the string "LOW" or the string "HIGH" to Serial.println(....) --- and choosing based on the value of checkIn

#

? : is call "the tertiary operator" - as it is the only operator in the language that takes three operands - the test, and the two results.

ripe flint
#

@safe shell do you know which pins do i need to use to turn on the onboard LEDs

safe shell
#

It's not pins, it's part of the protocol. You're using the WiFiNINA library?

fallen canyon
#

@obtuse spruce im trying to side by side this at the same time to understand it from my already known coding concepts. i think im starting to get it and what it does. this is super clean i can tell already and once i wrap my head around it then life codewise is gonna be a ton cleaner

obtuse spruce
#

"yesssssss.... now we've hooked them...... reel in slowly..... slowly...."

fallen canyon
#

haha braincells just had a colission

obtuse spruce
#

I try to make the code read - in code - what I'd say about what I want to have happen. Consider:

  • Read the switch_in to see if we are going to check the "in" side or the "out" side.
  • This tells us that the pin to check will be either limit_slide_in_left_1 or limit_slide_out_left_1, based on if we are checking "in" or "out".
  • Finally, we see if the limit is hit by reading that pin._

which became:

  bool checkIn = (digitalRead(switch_pin) == LOW);
  uint32_t pinToCheck = checkIn ? limit_slide_in_left_1 : limit_slide_out_left_1;
  uint32_t limitHit = digitalRead(pinToCheck) == LOW;
#

The three steps of my description became exactly three statements in code. This is better than having it exploded all out in nested if statements.

fallen canyon
#

ok so when the motor is going on the low side and say drawing it in and then its reading my pin at the same time to check the value to see if its low. i gather that much from my other code that i had already written and understand this is an exact match and is a way more efficient manner... gonna have to start writing it like this to probably understand it fully

obtuse spruce
#

I would suggest literally retyping it - not cut-n-paste! You'd be surprised how much it'll help. While you do, try changing the names to something you think makes more sense... again just as an exercise to make you think about each part as you type it.

fallen canyon
#

enableSlide = (digitalRead(onoff) == LOW) ? HIGH : LOW; is defining enableslide as the digital read of the pins being on or off

#

yup thats what i am gonna do

#

i know that works really well in understanding due to having been taught that way before

obtuse spruce
#

I'm not sure what you code is meant to do... I had to reverse engineer the meaning from the original code.... so here enableSlide is just what we're going to set all four slide_enable_x pins to either HIGH or LOW, based on result of reading the pin onoff. Note that enableSlide itself is just a value - based on the digitalRead at the time it that statement is run... It isn't like each time enableSlide is used the digitalRead happens again -

#

... but that is exactly how your if/else version operated, so I'm assuming that is what you want.

fallen canyon
#

per my application its very large RV type slideouts on my house im making a limit stop so they wont blow my steppers or gearboxes or push my slide out too far and break things

#

got an 80/1 gearbox turning acme thread

obtuse spruce
#

okay - and you probably have several of these things - each with an in and an out side, right?

fallen canyon
#

yeah i have 2 motors per slide and 2 slides per operation... im gonna make this setup drive all 4 slideouts but im just gonna manually unplug and replug in which motors and reed switches its running since stepper drivers and such aint the cheapest

#

and i wont be moving the house but a couple times

#

so the way i have it in my mind is have a reed switch on the outer tube of the slide and the magnet on the inside of the inner tube

#

so i dont have to worry about moving parts and wires

#

and ill have a switch at the front of the tube for when it goes out and the back of the tube fro when it goes in and the limit is based on the direction so i dont have to worry about having some kind of override

#

uint32_t disableSlide = (digitalRead(onoff) == low) ? High : LOW; so as the most basic of my understanding this is saying if this pin isnt low then declare it as a high pin

#

would that br correct @obtuse spruce ?

obtuse spruce
#

Close - let's say it says: "declare a local variable, disableSlide (of type uint32_t) - and set it's initial value by reading the pin onoff, and if it is LOW, then choose HIGH, otherwise LOW

fallen canyon
#

so its more of a choose command than an if statement

obtuse spruce
#

disableSlide itself is just a value, HIGH or LOW - -- we haven't said what to do with this value yet, and it isn't, itself, a pin or a pin's value (yet).

fallen canyon
#

the ? is choose and it could be if low choose low otherwise high if we reversed the HIGH : LOW to LOW : HIGH

#

digitalWrite(slide_enable_1, disableSlide); and then this is where we are telling it apply this logic to this particular pin

#

onoff is a pin connected to a switch tho

#

but its reading a value from it

ripe flint
#

@safe shell I had a chance to try to use the LEDs and they did not turn on which is making me wonder if the board is busted

obtuse spruce
#

not quite - digitalWrite(slide_enable_1, disableSlide); is not "applying the logic" at that point - the logic to choose a value was already run at the time digitalSlide was initialized - when the digitalWirte is run, it is simply using that chosen value to write to the pin.

#

This is a subtle thing - but keep it clear in your mind - values are just values, they don't "hold on to" the code used to create them.

fallen canyon
#

ok so its taking the value from the onoff pin and applying that value as high when the pin value is low. otherwise the value is low when the onoff pin value is high then its applying that to the other pin

safe shell
#

@ripe flint There are probably more things to try. Is the code you posted above still accurate? I think by adding in some more prints and logic tweaks, maybe something will fall out. And double-check the pin assignments match the connections, which you've probably done 3 times already.

fallen canyon
#

i think i get whats happening there now

ripe flint
#

Most recent code:
https://www.codepile.net/pile/ZgN91ZXq
the issue is that once I call a method from the WiFi class, it seems to stop execution because it is stuck somewhere, so the print statements in the setup function dont work.

safe shell
#

so what's the last thing you see on serial?

#

or paste the sequence from serial please

ripe flint
#

Just to confirm, the SPI pin is referring to the SPI clock input on the board?
and the last thing on Serial is :
22:58:19.127 -> WiFi Scanning test

safe shell
#

Therev are three SPI pins: MOSI, MISO, SCK. I don't know the Metro Mini 328, not sure how its pins are called out, but MOSI-MOSI, MISO-MISO, SCK-SCK between the two boards, plus the other connections, power, and ground.

#

Do you have a UART-to-USB?

#

you can hook up to the Airlift and see it's serial debug output

ripe flint
#

in the code it just refers to "The SPI port", and I was wondering which one is that.
And unfortunately I did not get the UART-to-USB, so I only have the output of the metro mini to use

safe shell
#

from your pictures, looks like you have connections to everything on the Airlift except 3vo and GPIO0, so that seems fine.

#

oh, the #define ...that's a class not a pin, so that looks OK

ripe flint
#

SPI is a class?

safe shell
#

it's the SPI port, from <SPI.h>. I'm assuming that's as it should be

ripe flint
#

That makes sense.

safe shell
#

the pins... you have Metro pin 2 going to Airlift CS

#

Metro pin 1 going to Airlift BUSY/RDY

#

There's a Metro pin 0? that goes to Airlift RESET?

ripe flint
#

Thats what I have them set to

safe shell
#

It's clear on the Metro which are the 3 SPI pins?

ripe flint
#

yes, 11-13 are the SPI pins (MOSI, MISO, CLK)

safe shell
#

No LEDs, or Serial.println("enter loop");

ripe flint
#

thats correct

safe shell
#

OK, so it seems to be failing in WiFi.setPins. Could be hardware like you said, but I'd still lean toward some assumption about pins, or wiring first. I don't know that board and couldn't find a good reference... do you have a link to the pinouts and how its SPI works?

#

it's supposed to be like the UNOrev3 and I'm looking at that

safe shell
#

thanks

#

give me a minute, I'm going back and forth between all teh things

ripe flint
#

absolutely. no problem.

#

...wait

#

The two pins labeled 0 and 1 are the two Serial pins that are used to send data to and from the Arduino to the USB-Serial translator chip.

Don't connect anything to Digital 0 or 1 unless you are super sure because it will affect your Metro's ability to communicate!

safe shell
#

I double-checked the wiring as well as I could from the pix and it looks right, as you already know 😉

#

ah, yeah, if that's the serial that's used for USB, then should try two other fere digital pins

ripe flint
#

smh

#

it worked

safe shell
#

wonderful!

ripe flint
#

I cant believe it was that simple. Thank you so much for going through all of that with me.

safe shell
#

np, sorry it took so long of double-checking what you already knew, I know the Airlift side, but not the Metro. Great that you figured it out. Good luck!

ripe flint
#

thank you.

sterile niche
#

hey guy, I am working on my 1st project from the Student kit about the basic of LED light:
like this
but when I duplicate the system to light 2 LED light, nothing happen, only 1 light up

#

please help me

lone ferry
#

@sterile niche How did you connect the second LED?

sterile niche
#

the same way @lone ferry

lone ferry
#

I don't know what you mean by that. 😉

deft sleet
#

The Voltage theems to low for the second LED, try it to wire it parralel circuit

copper stump
#

did you put the 2nd one in place of the 1st to see if it works? else you need to use another LED

lone ferry
#

It's best if you show us a picture of exactly what you did, @sterile niche

sterile niche
#

ok

lone ferry
#

Typical "mistakes" here are putting in the LED the wrong way around, or giving the second LED not enough voltage or current (what @deft sleet said), or using a broken LED (what @copper stump said).

copper stump
#

yup

#

aren't the 2 LEDs going to be half as bright as the 1st LED was because they're sharing the..voltage?

lone ferry
#

I guess that depends on how they are connected.

copper stump
#

(green on the left is resistor)

lone ferry
#

The same voltage is applied over both parallel branches. The current is split up.

copper stump
#

ah

#

but they would still be a bit more dim than the one LED?

lone ferry
#

I think that depends on how much current you're drawing from the battery. The lights in your house are wired exactly like this and they don't dim when you put more lights on. 😄

void gust
#

Hello all, I have a problem regarding String() in arduino,

I have two strings, the first one is concatenated like this:

 ``` dataString = String(dates + "," + times + "," + temp[0] + "," + hum[0] + "," +
                      temp[1] + "," + hum[1] + "," + temp[2] + "," + hum[2] +
                      "," + temp[3] + "," + hum[3]);
And the other one:
dataLog = String("," + airTemp[1] + "," + hum[1] + "," + floorTemp[1]);
dates, times are strings; hum, temp, airTemp, and floorTemp are floats.

I've got no problem with the first one, but with the second one, I always get this error message:

    error: invalid operands of types 'const char [2]' and 'float' to binary 'operator+'

However, if I use `String()` to convert the floats, it works just fine. But then again, I don't have to convert the floats in the first one into strings.

My problem is solved by using String(), but why does this happen?
#

it seems like it's okay to do String(string + char + float) but not okay to do String(char + float,

But I tried String("," +f) (where int f = 1), and it worked. However, String("," + f + ",") didn't work. I am really confused....what's the difference between these last two?

lone ferry
#

Does String(("," + f) + ",") work?

void gust
#

Does String(("," + f) + ",") work?
@lone ferry no it doesn't. this is the error message:

#

and I used c instead of f I forgot to change it back to f

lone ferry
#

Well, it probably has something to do with C++ not being able to figure out that it's supposed to make a String in this context.

#

It's not smart to turn a float into a string in this matter anyway because you don't have any control over the formatting. I prefer to use C strings and sprintf for this stuff.

void gust
#

Ahh I see, okay, thanks!

stable hamlet
#

anyone here to help me with my project?

lone ferry
#

Just ask the question, @stable hamlet

stable hamlet
#

https://pastebin.com/Gj3zgQ4g
code above.

i want to make a parking sensor and need help with if and else function. i added something to my code from yesterday but now it does not give me a distance number. all it gives me is distance: 0

#

i want it so the led and buzzer turns on if i get closer to an object.

#

and gets faster the closer i get

#

i dont know how i add that if and else function to my code

lone ferry
#

Change int distance; to float distance;

stable hamlet
#

that just changed that the distance is 0,00 instead of 0

lone ferry
#

Also, note with with duration = 20, the distance variable is 0.34. Because it's an int, that gets rounded down to 0.

stable hamlet
#

thats why i get 0 distance in the seriel monitor?

lone ferry
#

Yes, but with float distance; it should print 0.34, not 0.00.

#

Oh no, I see that your duration is also 0.

#

Put long duration (20); outside of setup().

#

Same thing for the flashtime.

stable hamlet
#

ok i got it to flash becuase distance is shown at 0,34

#

but its a constant 0,34
not changing

lone ferry
#

Well, your code doesn't contain any logic for changing it. Not that I can see anyway...

stable hamlet
#

i thought the ultrasonic sensor just shows the value. 😦

#

@lone ferry do you have time to help me in a call or something?

nova comet
#

@stable hamlet whats the problem exactly?

#

ur the guy who made a parking sensor right

stable hamlet
#

yes i am. sorry for not answering

pine bramble
stable hamlet
nova comet
#

what exactly is the issue right now

stable hamlet
#

what exactly is the issue right now
@Snap#5293

The issue right now is that the Led lights up on every value it gets

#

@nova comet

nova comet
#

and you want the LED to light up progressively faster as the sensor value decreases?

stable hamlet
#

Yes

nova comet
#

and echopin is ur ultrasonic??

#

@stable hamlet it doesn't look like flashtime changes anywhere

stable hamlet
#

Echo and trig Pins are ultrasonic sensor

nova comet
#

regardless

#

u have a function that when the cm < 50

obtuse spruce
#

the problem is that you never set distance

nova comet
#

you turn on the LED

#

you wait flashtime seconds

#

and turn it off

obtuse spruce
#

other issues are that there is no need to call pinMode in the loop - you called it for all those pins in setup -- though you forgot to call it for buzzPin

nova comet
#

but flashtime never changes

obtuse spruce
#

anyhow, you can just drop distance alltogether, and use cm in the if test.

#

as long as you don't mind the integer calculations - you're good to go here.

stable hamlet
#

Will test in like a half hour

obtuse spruce
#

if you want flashtime to be proportional to the distance - say 1000ms when the distance is 50cm, and 200 ms when it is 10cm --- then add a line like:

  flashtime = (max(cm - 10, 0) * 20 + 200;
#

do that just before the if

stable hamlet
#

Appreciated

stable hamlet
#

@obtuse spruce you there?

#

https://pastebin.com/sWP5sYZ1

tried to do as you said. but now im getting a constant beep+blinking led.

serial monitor shows 0cm everytime the led lights up

obtuse spruce
#

Sorry, I'm out... But quickly, print out duration as well. If it is always zero the the issue is with the sensor. If not, then your duration to distance function

#

If the sensor is always giving back 0... Perhaps your trigger isn't long enough. 20us seems very short

stable hamlet
#

on a different code it worked to show me values

#

but now as i added flashtime and stuff

stable hamlet
#

is there a way to know which code i flashed on my arduino nano?

stuck coral
#

Not over USB

#

With a programmer you can

stable hamlet
#

i think i got it to work

#

@stuck coral

#

thanks for the help from yesterday

#

the parksensor

stuck coral
#

Glad to hear

tidal peak
#

I was wondering if there is some way to communicate with an xbox one controller to an arduino, or indirectly through like processing?

pine bramble
#

What's that controller communicate with?

tidal peak
#

xbox one

pine bramble
#

No I mean the protocol. And physically.

#

(A quick google check suggests wireless)

tidal peak
#

I'm not sure, that's part of what I'm wondering what my options are

#

I'd like to go serially through the computer I guess

pine bramble
#

That should give some idea what is going on with that.

tidal peak
#

thx

pine bramble
#

;)

sterile niche
#

the best thing I can make is a light for sleeping

#

:I

void gust
#

Hey all, when we use sprintf, can we reuse the same buffer char for different instances of sprintf?

#

or do we have to make different buffer for different instance of sprintf?

lone ferry
#

You can use the same buffer, provided it is large enough.

#

(And you're not using it for something else at the same time.)

void gust
#

Thank you very much @lone ferry ! 😄 have a nice day!

sterile niche
#

anyone give me tips if you can

#

first project involve coding

obtuse spruce
#

@sterile niche - two quick things:

  1. make constants for your pins, either like:
const uint32_t pinGreenLED = 3;
  • or like: -
enum {
  pinGreenLED = 3,
  pinYellowLED = 4,
  ...
#
  1. What is your intention with the button? It looks like this code will cycle the lights - and pause while button is held, showing red - but only check the button and the end of the red cycle..... And because there is no "debounce" logic, the button might jump LOW for a short time while being depressed - and that will (with this code) cycle the lights again.
#

Note: When you give your pins names - you'll find your comments are no longer needed at all. I'd remove them.

gilded owl
#

I have the following code from a project I'm trying to make:

#

//define pin name
#define dir 1 // Direction
#define pwrA 2 // Power for Motor A
#define pwrB 4 // Power for Motor B
#define pwrC 7 // Power for Motor C

//constants won't change
const int buttonPin = 8; // the number of the pushbutton pin

// variables will change
int buttonState = 0; // variable for reading the pushbutton status
int pwrAState = LOW;
int pwrBState = LOW;
int pwrcState = LOW;
int delaymillsA = 400;
int delaymillsAr = 400; // Return delay
int delaymillsB = 400;
int delaymillsBr = 400; // Return delay
int delaymillsC = 500;
int delaymillsCr = 500; // Return delay
int delaymillsD = 100;

#

and I was if using #define was necessary

obtuse spruce
#

No - with modern compilers, const int foo = 4; is almost always better than #define foo 4.

#

You only need to use #define for things like this if you are doing strange things with symbol concatenation (using ##) - or if you are trying to be lax about types (which you shouldn't be)

gilded owl
#

Thank you

north stream
#

I'm curious why that would be: it seems like const int would take up storage, but #define wouldn't, but perhaps I'm missing something.

lone ferry
#

it seems like const int would take up storage
Not necessarily. And #define would take up the same amount of storage in the same situation.

obtuse spruce
#

When the compiler knows that a value is const, it can in-line it if it will take less space. So, for example, passing it as an argument - it doesn't need to load it from memory - it can just use an immediate form of an assembly instruction.

lone ferry
#

The reason const int is better is that the compiler knows you're trying to use this thing as a constant, and where you're trying to use it. With #define it first goes through the code and literally replaces every instance of this symbol with its value. In that case it no longer has that symbolic information (and type information), only the literal values, so it cannot reason about it in any way. The generated assembly code is never worse when you use const and potentially better.

obtuse spruce
#

consider:

#define fourDefined 4
const int fourConst = 4;
int fourVariable = 4;

void showInt(int x) {
  Serial.print("x is ");
  Serial.println(x);
}

void setup () {
  showInt(fourDefined);
  showInt(fourConst);
  showInt(fourVariable);
}

If you look at the generated code, the code for the first two lines of setup are identical. If that is the only use of fourConst, you'll see that the linker doesn't even allocate memory for it!

fallen canyon
#

Is there an arduino available that has solder connections rather than pins? Or would i need to pull the solder pins and solder in my wires in place of them

obtuse spruce
#

You want to solder wires directly to the board?

#

Most (all?) of the smaller Adafruit boards come with pin headers, but not yet soldered on. I use the Feather M0 Express for my projects - though the more powerful M4 (https://www.adafruit.com/product/3857) is just a bit more $.

#

Those are but two of the many options.

#

But - though I don't know what you're building - you might consider a stacking proto board - so you solder into something passive ( and cheap), and then mate it with the system board - that way the system board is ruined if you mess up the soldering or decide to change how you're doing things.

#

They make such things for full sized Arduino boards as well.

#

(see https://www.adafruit.com/product/2077 -- or https://www.adafruit.com/product/196 for one with screw terminals for your wires - you may not need to solder at all!)

fallen canyon
#

That might be a better option. Just thinkin of the disaster that could happen if one of my pom wires came loose for some reason and my limit switch never hit

#

Never thought about screw terminals... thats a pretty solid and easy way over soldering

#

That makes me wonder is there a screw terminal variant already set up for the arduino board itself

vivid rock
fallen canyon
#

Hmm looks like they are all adapter boards from what im seeing. Without having to go pin style i think the wing adapter setup would be best for my application then i can just cement the pins to the arduino to avoid separation and use the screw terminals. Vibration is the only thing i would worry about with the screws and coming loose.

#

Thanks for the info/suggestions guys

vivid rock
#

@fallen canyon with screw terminals, it is generally advised that instead of tinning the end of stranded wire to insert in the terminal, you use either wire sleeve/ferrule, or a male header pin. See e.g. https://electronics.stackexchange.com/questions/146527/most-ideal-wire-termination-for-round-screw-terminals

fallen canyon
#

Yeah i get the point of that. Its like phone wires. If youve ever had the joy of messing with them on a screw terminal you will understand what i mean by breaking with screws. I dont cram the wire down that hard but tinning the end is definitely a good way to go

thorn relic
#

And getting a phone call while holding the screwdriver

north stream
pine bramble
#

how do I figure out which pins are MISO, MOSI on the BME280?

north stream
#

It states: Connect the SDO pin to Digital #12 but any pin can be used later
Connect the SDI pin to Digital #11 but any pin can be used later

#

And in the code: #define BME_MISO 12
#define BME_MOSI 11

#

So SDO is MISO and SDI is MOSI.

pine bramble
#

smart, ty

fallen canyon
#

@north stream thanks for that link. Only thing is i dont see the usb port kn there and i aint no pro yet lol. Being as im gonna do this as more of a hobby after my current project i doubt ill ever be a pro as per the word

#

And getting a phone call while holding the screwdriver
Haha for real

pine bramble
#

Im clearly doing this wrong. I'm getting error messages:

    at processing.app.Serial.dispose(Serial.java:171)
    at processing.app.SerialMonitor.close(SerialMonitor.java:147)
    at processing.app.AbstractMonitor.suspend(AbstractMonitor.java:113)
    at processing.app.Editor$UploadHandler.run(Editor.java:2049)
    at java.lang.Thread.run(Thread.java:748)
Caused by: jssc.SerialPortException: Port name - COM3; Method name - setEventsMask(); Exception type - Can't set mask.
    at jssc.SerialPort.setEventsMask(SerialPort.java:279)
    at jssc.SerialPort.removeEventListener(SerialPort.java:1064)
    at jssc.SerialPort.closePort(SerialPort.java:1090)
    at processing.app.Serial.dispose(Serial.java:168)
    ... 4 more
#

This is what I tried for I2C on a Feather M0

#define BME_SCK 21
//#define BME_MISO 22
#define BME_MOSI 20
//#define BME_CS 10```
north stream
#

It's basically a low-cost Arduino compatible, so while it supports the standard shield pinout, it's smaller and less expensive, so you can build it into projects.

pine bramble
#

@north stream I got it working! I was using the USB power pin instead of the 3.3v regulated pin. Thanks for your help figuring out the other pins, I wouldn't have got this far.

fallen canyon
#

Cool stuff

vivid rock
#

@pine bramble MOSI, MISO, and SCK are not I2C pins, they are for SPI.
I2C is a two-wire bus, using signals commonly named SCL (clock) and SDA (data)

honest obsidian
#

What do you guys think about pull requesting someone else's fork vs. the original repo if the differences between the fork and the original repo aren't much different? I realize this is somewhat an opinion-based question.

pine bramble
#

@vivid rock Thank you 🙂 I first tried to use SPI but it didnt work (probably because of the power pin issue) so I did more digging and found out what you just told me so I wired it for I2C then figured out the power pin issue. I'm new to these microcontrollers so I'm trying to learn what all of these codes mean.

#

but its working so thats good lol

vivid rock
#

nice!

pine bramble
#

have you ever written sensor data to a sql database? Sqlite specifically.

vivid rock
#

unfortunately not
I have some experience with MySQL on websites, but never used local deployment

pine bramble
#

Im wanting to use the wifi on this Feather to upload to a DB on my PC. I'm sure there's a way. I'll keep digging lol

vivid rock
#

you might want to use one of existing IoT platforms

#

i used Blynk and liked it a lot

pine bramble
#

it works with the feather? I'll look it up

vivid rock
#

it works with anything that is wifi enabled

pine bramble
#

thats handy

#

yep it supports the Feather Im using

vivid rock
#

but it is a server-centric approach: all data is uploaded to a central server (owned by them), and you cna connect to the server to retrieve the values from a cell phone
I do not remember about log storage in Blynk

pine bramble
#

cost? I haven't got to that point

vivid rock
pine bramble
#

ok cool ty

vivid rock
#

haven't used it myself

pine bramble
#

how much is it to use Blynk for developers? I didnt see it anywhere.

#

free hosting seems too good lol

vivid rock
#

for personal use or to develop for clients?

pine bramble
#

personal

vivid rock
#

for personal use, it works like that: every "widget" you add in blynk app on your cell phone cost some "energy"

pine bramble
#

ok

vivid rock
#

you get some amount for free, then you pay

pine bramble
#

thats cool

vivid rock
#

but it is peanuts - maybe a couple of dollars for a project

pine bramble
#

ok

vivid rock
#

and it is one-time per project, not monthly

pine bramble
#

oh thats not bad

vivid rock
#

at least it used to be so

pine bramble
#

thanks for all of the info. Glad there are potential libraries for me to work from instead of going from scratch.

robust valve
#

Hey, I need help for a IC I bought a few days ago, I hope I can ask it in this channel.

#

So, I got a 74LS00 NAND Chip and I tried it out. So I placed it on my breadboard, I hooked up power and ground and also the inputs and outputs I needed for trying it out. But nothing happens. Idk why.... I have rebuild many different circuits from Youtube Vids with this logic gate, but nothing is happenning at all. Not even the LED I hooked up will turn on and thats really not a good sign I think cause its an Nand Gate and it should be on instantly..:

nova comet
#

anyone have any ideas of how i could send a 2d array over ble

#

like

#

how to convert it into hex or smth

north stream
#

Hex could work or you could use a higher level protocol like Firmata

nova comet
#

@north stream how would i go about that conversion

obtuse spruce
#

@nova comet - I would think that the first more important thing would be - what is consuming that 2D array at the other end? This will almost certainly determine the format.

nova comet
#

@obtuse spruce what do you mean? What type of device?

obtuse spruce
#

no, what software - you're sending a 2D array over BLE to what? What software will take and use that 2D array?

nova comet
#

im sending over to an ios app

obtuse spruce
#

one that you are writing? so it is a companion?

nova comet
#

yes

obtuse spruce
#

Ah - okay - then you have lots of options - it is a 2D array of what kind of data? and about how big is it?

nova comet
#

its the state of a chess board, its just 1's and 0's based on piece positions

#

8x8

obtuse spruce
#

oh - just boolean? not like the chess piece itself?

nova comet
#

no no im inferring all of that via software. It's a reed switch matrix

obtuse spruce
#

okay - since it is always fixed 8x8 boolean array... you've got several options - but I'd think the easiest would be: a 64 character string of 1s and 0s . It'll be easy to decode on the iOS side.

nova comet
#

so just something like left to right top to bottom

obtuse spruce
#

yup

nova comet
#

yeah aight

#

makes sense

obtuse spruce
#

you could try to compress it down to 8 numbers, one per row - but hardly seems worth it - once you're sending a packet, 64 bytes isn't all that much

#

especially since this isn't like once per millisecond, I assume

nova comet
#

this is only sent upon a move being confirmed so it should be fine

obtuse spruce
#

then sure - there ya go

nova comet
#

thank you

#

im writing the code rn

#

lmfao

obtuse spruce
#

😁

nova comet
#

:)

#

@obtuse spruce you think i should just append the numbers to a string and then convert to hex?

obtuse spruce
#

no

nova comet
#

what do u suggest

#

@obtuse spruce

obtuse spruce
#
char boardStr[8*8+1];

char* b = boardStr;
for (int i = 0; i < 8; ++i) {
  for (int j = 0; j < 8; ++j) {
    *b++ = board[i][j] == 0 ? '0' : '1';
  }
}
*b = '\0';
#

why convert to hex? that string is good enough -

nova comet
#

i guess just to shorten it since everything else i have is in hex too

#

all my other commands

obtuse spruce
#

shorten? that would make it longer

nova comet
#

the hex string would be longer than the binary??

#

i dont mean in terms of runtime

#

i mean in terms of the string length

obtuse spruce
#

well - this all depends on what you are doing - if you meant read the elements of the array as bits - and then pack 8 bits of each row into a byte, and then express that as a two character hexidecimal value - then sure it'll be smaller

#

But 16 vs. 64 characters - once every long while - is hardly a savings worth spending the time to code (and debug) ...

nova comet
#

i guess ill leave it in binary

obtuse spruce
#

I guess I wouldn't call what I wrote "binary" - I mean the two characters could have been * and `.``

nova comet
#

Alright

nova comet
#

@obtuse spruce could you look at my code and tell me if you see anything wrong? Im using lightblue to test rn and the results are odd. Im using digital 0 and 1 for the ble module

#

earlier i managed to send the string "hello" over with no issues

#

and in the serial on my compute I see 64 consecutive 1's

#

but on my phone i see weird stuff

obtuse spruce
#

@nova comet - was at dinner - will look now.

#

er - that code doesn't send anything over BLE ...

nova comet
#

Cant i just send via serial.write

#

Thats how i did it earlier

obtuse spruce
#

I guess I don't know how your module gets to Bluetooth - but sure - if Serial normally writes to a virtual serial console via BT - and you have an app to read it

#

Then the only issue I see is that you probably wanted Serial.println(boardStr); to get the newline

#

(I don't know what board your compiling for - nor do I know how the core for that board sets up Serial - does it normally show up in some app on the phone?)

nova comet
#

Yup the app is lightblue

#

And im using HM-18

#

As the bluetooth module

obtuse spruce
#

No idea - I don't know that board --- but you do see the correct output when connected to your computer via USB and the serial console? If so - er - then the only thing I can think of is try changing the Serial.println like I suggested. BTW - if that works, then the core implementation for that board is wonky (IMHO)!

#

I'm a little unclear - is the HM-18 your whole system? Or is just being a serial-over-BT module connected to some other developer board?

nova comet
#

Ive got an arduino hooked up to the hm18

obtuse spruce
#

So - er - how does writing to Serial go out both the USB port and some serial UART?

nova comet
#

Not sure if im being honest. Ive got the module hooked up to the built in rx and tx ports on the arduino, could be that

obtuse spruce
#

Alas - no idea what's going on - but if you see the right stuff over USB Serial - then the issue has to do with the device.... not the code we just wrote

nova comet
#

and when you say device you mean the ble module

#

also, i managed to successfully send data before this

#

it was just different format

#

could be the app

#

At this time the app no longer shows me data that i send over, just a stream of endless 0s

#

@obtuse spruce

#

hm

#

wait

#

this is odd

#

i restarted the arduino

#

and now i receive the values

#

when i send over 0x01

#

now it does send info over its just not correct

ripe flint
#

Hey, I just got a 3.5" touch screen breakout (https://www.adafruit.com/product/2050) and I'm trying to hook it up to my Arduino Mega. I ran the example sketch and got:

Using Adafruit 2.8" TFT Breakout Board Pinout
TFT size is 320x480
Unknown LCD driver chip: 0
If using the Adafruit 2.8" TFT Arduino shield, the line:
  #define USE_ADAFRUIT_SHIELD_PINOUT
should appear in the library header (Adafruit_TFT.h).
If using the breakout board, it should NOT be #defined!
Also if using the breakout, double-check that all wiring
matches the tutorial.```
#

I also tried the same screen, same code, same wire layout on an Arduino Duemilanove and it worked perfectly

ripe flint
#

never mind, the Arduino Mega pins are different than the other boards

calm hatch
#

I just started today and I'm about to code some servos, but I'm going to reuse the same functions over and over so I want to create a function or something that I can put different values in to input different servo names and button names. I haven't codded in a while but I know I can do it in different languages I just don't know how to in Arduino.

north stream
#

Similar techniques will work with Arduino, you can write a subroutine that accepts arguments for which servo and what parameters.

vivid rock
#

@calm hatch arduino is using a version of c++, so you can define funcctions in the same way as in c++

slate pendant
#

good day I need a little help with programming ^^'
So I'm currently building this door opener circuit with an ESP8266 wifi module (that can also be used on its own to open a relay) and IFTTT.
My Main problem is poor documentation about webhooks and outdated libraries for the ESP8266 wich throws errors.
If somebody could look over my code I would appreciate that.
Also a minor issue I was trying to iron out is giving the Module a name when connecting to wifi, that gets displayed in the router.
Code as follows:

#

and obviously I will change the webhook adress once implemented :P

obtuse spruce
#

two quick thoughts:

  1. status is never updated - so all those tests for != WL_CONNECTED are pointless
  2. If it is a secure client, then why is it using port 80? Shouldn't it be 443?
slate pendant
#

to answer first thought - thanks I somehow thought status would update itself but it is only updated if its Wifi.status
(https://www.arduino.cc/en/Reference/WiFiStatus)
Second one - thanks for pointing me to that! there's still library issues thoe:

#
C:\Users\mknoa\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\libraries\ESP8266WiFi\src/WiFiClientSecureBearSSL.h:262:36: error: expected ')' before '*' token

     WiFiClientSecure(ClientContext *client, const X509List *chain, unsigned cert_issuer_key_type,

                                    ^

C:\Users\mknoa\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\libraries\ESP8266WiFi\src/WiFiClientSecureBearSSL.h:264:35: error: expected ')' before '*' token

     WiFiClientSecure(ClientContext* client, const X509List *chain, const PrivateKey *sk,

                                   ^

C:\Users\mknoa\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\libraries\ESP8266WiFi\src/WiFiClientSecureBearSSL.h:38:5: error: 'BearSSL::WiFiClientSecure::~WiFiClientSecure()' marked override, but does not override

     ~WiFiClientSecure() override;

     ^

C:\Users\mknoa\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\libraries\ESP8266WiFi\src/WiFiClientSecureBearSSL.h:43:9: error: 'int BearSSL::WiFiClientSecure::connect(const String&, uint16_t)' marked override, but does not override

     int connect(const String& host, uint16_t port) override;

         ^

C:\Users\mknoa\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\libraries\ESP8266WiFi\src/WiFiClientSecureBearSSL.h:48:12: error: 'size_t BearSSL::WiFiClientSecure::write_P(const char*, size_t)' marked override, but does not override

     size_t write_P(PGM_P buf, size_t size) override;

            ^

C:\Users\mknoa\AppData\Local\Arduino15\packages\esp8266\hardware\esp8266\2.6.3\libraries\ESP8266WiFi\src/WiFiClientSecureBearSSL.h:60:12: error: 'size_t BearSSL::WiFiClientSecure::peekBytes(uint8_t*, size_t)' marked override, but does not override

     size_t peekBytes(uint8_t *buffer, size_t length) override;

            ^
#

having multiple libraries with same name being found shouldnt be a problem, should it?

obtuse spruce
#

Yes - it can be quite a problem.

#

The detailed log output of Arduino IDE will tell you which libraries it chose based on the .h files you included (and they included...)

#

Those errors look like there are two conflicting libraries being used. The expected ')' before '*' token error indicates that one of them is doing something like #defineing the symbols the other is using....

slate pendant
#

ohhh ok

#

I cant turn the outdated ESP libraries off because they come included with the boardmanager

#

what would be the solution?

obtuse spruce
#

As for status - the code on that page is written in a confusing style: WiFi.status() is checked at top - as it should - but then later, the int status variable is updated with the return value of WiFi.begin() - which presumably returns the same value as WiFi.status() would after it has been called. The status variable is only used as part of that while loop and should be declared just before the loop (or better yet, as part of a for statement), not as a global at the top.

#

If you have two sets of ESP libraries - then you really need to be sure to be using just one consistent set. If there are multiple libraries in each set, and the compiler is picking one from A and one from B - they are almost certain to not work together correctly - even if they compile, the result is unlikely work.

slate pendant
#

I would like to use the standart arduino/adafruit libraries instead of the ESP libraries

obtuse spruce
#

sounds like a good plan -

#

If you are using the Ardiuno IDE, and don't want to uninstall them (which deletes them) - then you can simply move them somewhere out of the library tree on your disk.

slate pendant
#

ahh ok thanks ^^

solid stag
#

hello i am using the sparkfun micro sd breakout board and i wanted to beable to save arduino scripts or text files with arduios scrpits saved in them and wanted to be able to run them with buttons anyone know how i would be able to read the sd and run the scripts inside of them?

stuck coral
#

@solid stag I think you misunderstand, if you have a sketch or text file as a script on the SD card, that is not a compiled binary the CPU can execute, and it resides in a seperate memory location. While there have been some efforts on bootloaders that can load compiled applications from an SD card and flash to PROGMEM before execution, it didnt work well and is a dead project. I recommend you look at Circuit Python, it is an application that operates as a python interpreter in PROGMEM, and can execute python programs from external memory which are basically just a text file. If I remember right there is a CP library that lets you write some basic arduino code above CP and you can use it to select a sketch to run, Im not sure about the details but I would write a program that will select the script you want from the SD card using the buttons, and than hand the script to CP

north stream
#

Theoretically, you could have a sketch that can retrieve lists of text commands from the SD card, parse them, and do various things based on what they are (for example, lists of notes to play and durations), but it would be somewhat complicated to build.

stuck coral
#

Which in a super cut down and basic sense, is CP

north stream
#

Right, just thinking of something that could fit on an Arduino.

stuck coral
#

Ah, I see.

north stream
#

Of course, you also run the risk of colliding with Greenspun's Tenth Rule of Programming: "Any sufficiently complicated C or Fortran program contains an ad-hoc, informally-specified, bug-ridden, slow implementation of half of CommonLisp." 🤪

#

That warning haunts me whenever I start writing a parser (and I write a lot of parsers)

stuck coral
#

Lol, you made me search for embedded lisp and of course thats a thing, love it, even supports an UNO 😆

north stream
#

I'm not particularly surprised, Lisp dates back to 1958, and a Uno is a fair match for the kind of computing power available then

solid stag
#

what i am trying to do is use the keyboard library and the arduino ot act as a fake keyboard and be able to run mulitple scripts

#

i will check out ciruit python tho do you have any microcontroller boards that you recomend that use ciruit python

north stream
#

There are a lot of possibilities there. At the low end, there's the Trinket M0. However, the ItsyBitsy M4 Express is much more powerful, has more I/O pins, and isn't very expensive.

stuck coral
#

Many of the SAM21 and SAM51 boards in Adafruit support it, there are a few other outliers but I always recommend the SAMD51 boards which you'll find with a M4 in their name as @north stream suggests

solid stag
#

hmmm ok i was thinking of buying a couple itsybisty so its nice to know they also runn currcit python

#

Could i use a nodemcu with curicut python?

north stream
#

Another advantage of those boards is you aren't stuck in either camp, you can run Arduino or CircuitPython on them, or switch back and forth all you like.

solid stag
#

nice

stuck coral
#

CP does not support the ESP32 or ESP8266 which is what nodemcu uses

solid stag
#

where do u recomend buying them as the shipping is really expensive from adadfruit

stuck coral
#

Digikey but thats not really cheaper in most cases

north stream
#

It depends on what part of the world you're in.

#

You can even get free shipping from Digikey (only in the US and Canada), but it's slow and more effort.

solid stag
#

k

#

does the ItsyBitsy 32u4 run micropython

odd fjord
#

I doubt Micropython supports any 32U4 devices...

solid stag
#

k

#

thanks

north stream
#

The 32U4 can emulate a USB keyboard device, but it can't run Python.

solid stag
#

rip

#

i found someone who kinda did somthing i am trying to do so im going to look into that

woven fox
#

Is anyone familiar with Nrf24l01 modules?

reef ravine
#

@woven fox can you post the transmit code using the "back tick" (to the left of 1 on a US kybd) ? it'll look like this

obtuse spruce
#

Your if test is backwards

#

if (radio.available()) { is what you want in the receiver.

reef ravine
#

your eyes are better than mine lol

woven fox
#

I have discord on my phone. I hesitated on asking here because of it

#

O! Yikes! Ok. I’ll give it a go. Thank you

#

My if (radio.available()) is on the receiver at the moment. Should it be in a different spot?

reef ravine
#

you have if radio not available

woven fox
#

!

#

Ok. Now I’m getting zeros and ones in the serial. These radios aren’t going to beat me.

#

I thank you for the progress you have helped me make this evening.

#

I’m going to go stare at code again for hours until I get it.

calm hatch
#

im having trouble still with my problem earlier

#

"I just started today and I'm about to code some servos, but I'm going to reuse the same functions over and over so I want to create a function or something that I can put different values in to input different servo names and button names. I haven't codded in a while but I know I can do it in different languages I just don't know how to in Arduino."

#

This is what i was guessing at and it wasnt working

#

int servoname;
int buttonname;
int angle180(servoname, buttonname);
{
switch (results.value)
{
case buttonname: //7
{
for (angle = 180; angle >= 175; angle--)
{
return (servoname).write(angle);
delay(15);
}
}
}

north stream
#

That return statement will bail out of your for loop so it won't complete

#

You'll probably also have to either a) pass in a servo object (instead of an integer), which is how I'd do it, or b) have an array of servos and pass in an index into that array to specify the servo to use.

calm hatch
#

im looking to make a command for each angle 90-180-0 but i need to be able to change the servo and button for each different input

north stream
#

I might have something like (this is not working code, this is just an illustration): ```c
void buttonservo(
Servo servo,
int angle,
int button)
{
if (results.value == button) {
servo.write(angle);
}
}

#

Then call it with something like ```c
buttonservo(servo4, 7, 180);

opal mirage
#

i have finally finsihed my project using lcd,arduino,jumper wires,ultrasonic sensor,buzzer and led.I need to make a case but not sure where to start...Any ideas?

magic field
#

the bottom is easiest, if you start with the top, it tends to fall onto the bench quickly.

lone ferry
#

If you don't have anything lying around that will fit, I'd buy a case and then modify it to suit your needs.

vivid rock
storm coral
#

Hey guys, I have a 4 channel relay board that I use to control our irrigation system. It's in a fairly humid environment - which might play a role in this behaviour, but I have not yet seen anything like it

#

The relay board has only 2 pins connected, vcc (5v) and gnd, but the relays are randomly switching on and off in really short intervals, without any controlling pins connected

north stream
#

It could be the unconnected control inputs are just picking up random electrical noise and interpreting it as commands to turn relays on and off.

#

Some boards have resistors to pull inputs to a default state when they're not connected, but yours may not.

storm coral
#

There are wires of 24vdc, 5vdc and 230vac in its close proximity, could those be it?

north stream
#

Those could well be it. Try connecting the inputs to something (just grounding them is likely to be fine) and see if the relays stop switching.

storm coral
#

Thanks I'll try doing that, however previously it was already connected to my NodeMCU and it still did the switching

north stream
#

That is odd, unless the NodeMCU didn't have its I/O pins configured as outputs, or they didn't share a common ground.

storm coral
#

I'm pretty sure all pins are configured as outputs

#

One more thing that was odd is that the leds that indicate whether a relay is on or off werent changing

#

They stayed the same even though the relays were switching at like 5-6 hertz

north stream
#

Curiouser and curiouser. Perhaps it's not floating input issues. Could be power supply spikes or something, or the relay board uses separate logic and coil supplies but one isn't connected, or weird leakage paths or I don't know what.

storm coral
#

Logic and coil supplies are grounded, both are going off a modular psu thats set to 5 volts (5.2 in reality)

#

I'm starting to suspect that power supply, its quite old I'll check it with another one I have lying around

quartz furnace
#

Adafruit has a nice library written for a MCP23008. It has two examples that make it easy to get started on a project. Question is there a way to poll all of the pins (input) and report the cumulative? It appears like it just does one at a time “mcp.digiitalRead(0)”

north stream
safe shell
#

It's conceptually a multiplexer, but easy enough to write a helper function to read and sum the inputs.

safe shell
#

the register read @north stream highlights has the advantage of simultaneous state on each pin

quartz furnace
#

So something just like int readAll = mcp.readGPIO(); ?

#

@safe shell If you could elaborate more. I’m not fully sure now

obtuse spruce
#

uint8_t allPins = mcp.readGPIO(); sets allPins to a value where each bit corresponds to a pin on the MCP unit. Bit 0 is pin 0, etc....

#

What I think we're not clear on is what you meant by "report the cumulative" -- did you mean you want to sum them? or rather count how many 1 bits there are?

quartz furnace
#

Well maybe I am confused .. with 8 pins. They will have values 1 , 2,4,8,16,32,64,128? Correct ? So by cumulative if the very 1st two pins have an input then the total would be 3 (1 +2) or am I confused it would be more like “11000000” reported back with each pin a 1 or 0

obtuse spruce
#

no - you've got it right - and that call will give you that value.

quartz furnace
#

Ahh awesome .. so just set them all high in the set up and the loop could have the uint8_t allPins = mcp.readGPIO();

obtuse spruce
#

it has the minor advantage that it will read all the bits in one transaction with the chip - so you're getting the state of the inputs all from the same moment in time. If you call mcp.digitalRead(pin) one at a time for each pin ... then you're getting the state of the pins from slightly successive moments in time.

#

Oh - heh - that is exactly what @safe shell just said above!

quartz furnace
#

And last question.. I see different advice on a google search for wiring to an Arduino board .. are resistors needed on the I2C pins ? Good practice Or not needed. I’ll be using a Feather 328P

obtuse spruce
#

From the board pinout page: "There's no pull up on this pin by default so when using with I2C, you may need a 2.2K-10K pullup."

#

for both pins - I'd trust Adafruit on this one, and add one. But if you're breadboarding the circuit first (you are, right?) - then you can just, well, try it with and without and see!

quartz furnace
#

Breadboarding.. yes

#

Cool Thank you!

obtuse spruce
#

welcome and good luck

quartz furnace
#

Very helpful ... I’m so glad this library is going to work after all.. it will greatly simply code ... I saw wire.h example that required many more lines to accomplish the same .. wire.beginTransmittion . Etc etc

#

Transmission**

teal prism
#

Does anyone know how to detect two electrical contacts? I want to make a buzzer play a song every time two wires touch, and I dont know how to do that, this is my concept that might not even work..

int GROUND = 7;
int POSITIVE = 5;

void setup() {
pinMode(GROUND, INPUT);
pinMode(POSITIVE, OUTPUT);
}

void loop() 
{
digitalWrite(POSITIVE, HIGH);
digitalWrite(GROUND, LOW);
//Buzzer goes into digitalPin 3

if(GROUND, HIGH) {
tone(3,294,125);//D4
delay(125);
tone(3,294,125);//D4
delay(125);
tone(3,587,250);//D5
delay(250);
}
#

I am very new to this so please have mercy when making fun of my code

#

it doesnt work

stuck coral
#

What arduino board are you using @teal prism? I recommend connecting one side of the switch to the actual ground pin of the arduino, and having a single pin you define. You can set the pin to be a INPUT_PULLUP instead of a INPUT. Then you would remove both your digitalWrite which sets a pin high or low and add a int state = digitalRead(BUTTON); which you can then pass into a if statement

teal prism
#

I am using a standard arduino uno board, what would be the conditions for the if statement, I am rather new to this

stuck coral
#

So an if statement will execute the code between the {} when the statement within the () becomes true. So if you have if(state==LOW){} and you press the button making it go to ground (aka LOW) after you read the pin with state = digitalRead(BUT_PIN); then any code you put between the {} will execute

teal prism
#

Can this work without a button?

stuck coral
#

Sure, a button is just two contacts

teal prism
#

Alright perfect, thank you

nova comet
#

@stuck coral u around?

stuck coral
#

Yep, just got home from work

nova comet
#

is this function correct in converting a binary string to binary int

#
uint32_t result = 0;
    for (unsigned int i = 0; i < strlen(boardStr); ++i)
    {
      result = result << 1;
      result = result | (boardStr[i] & 1);
    }
#

because when i input "1111111111111111111111111111111111111111111111111111111111111111" (65 1's) I get FFFFFFFF as the output, shouldnt it be FFFFFFFFFFFFFFFF (16 F's)

stuck coral
#

Well the result you defined is 32 bit, so no it shouldnt, it can only be 32 bits long

nova comet
#

oh my bad

#

i might need your help with this bluetooth

#

its a huge pain rn

#

i can successfully send messages

#

to it

#

but sending from the arduino aint working

stuck coral
#

Im not sure, Im not familiar with the Arduino bt stack but I can take a look ig

nova comet
#

i just changed the uint32 to int and it still prints ffffffff

stuck coral
#

What Arduino are you using? Its probably still 32 bits

nova comet
#

uno

stuck coral
#

You sure its the same value? Should be 16 bits so shorter not longer

nova comet
#

"FFFFFFFF"

stuck coral
#

Alright, what are you trying to do again?

nova comet
#

well as u know im trying to send the state of a chess board (binary) from the arduino to iOS

#

so

#

im trying to convert a string of 64 1/0s

#

into something i can send via bt

stuck coral
#

Why do you have strings of 1/0? That seems silly to me.

nova comet
#

someone here told me to do it :/

#

im very open to suggestions this isnt working for me at all

stuck coral
#

Could I see your code in a pastebin?

nova comet
#

sure thing

stuck coral
#

Looks to me those strings are just for the console, not for general storage + transport.

nova comet
#

i mean i am seeing them in the local console so that makes sense

#

what do u suggest?

#

to send a 8x8 matrix of 1s and 0s

stuck coral
#

Well you dont want it to send what piece is what? Just if there is a piece in a spot correct?

nova comet
#

yup

#

im using reed switches

#

im inferring the actual piece type on the ios end

stuck coral
#

Okay, makes sense, we can get this down to 8 bytes long which you can send through bluetooth. Define a uint8_t result[8] = 0x0;, then a for of for statement going over your 8x8 array, and if the value is a one, set the bit position in result at the index needed. Im sure this explaination will not be enough but that would be the most compact way of sending the data

nova comet
#

you are saying a nested for loop to go through each digit of the array correct

stuck coral
#

Correct, then we can imagine the data in result as 00000000 00000000 00000000 00000000 with each 0 being a location in your board. So go through each piece, and if the value is one, then set the bit in the position required. result |= 1UL << bit_position; will set a single bit, but make sure to transverse the bytes correctly

nova comet
#

two hex digits can represent 8 bytes right

stuck coral
#

8 bits

#

1 byte

nova comet
#

sorry yes

#

8 bits

#

so is result 8 bits or 8 hex characters

stuck coral
#

The result would be 8 bytes long

#

64 bits, one for each piece

nova comet
#

isnt uint8 only 8 bits?

stuck coral
#

Correct, thats why result is an array 8 values long

nova comet
#

omg im stupid sorry

stuck coral
#

No you're fine

nova comet
#

lmao

#

oh

#

oops

#

anyways

#

so

#

each position in the result array will hold a row

#

or column

stuck coral
#

Well, that is true. Wasnt the goal, but is true

nova comet
#

so can i send result all at once or do i need to send each entry of the array seperately

stuck coral
#

You can send it all at once

#

As an array

#

Would be weird if in bluetooth you could only send one byte at a time

nova comet
#

well

#

yes

#

okay

#

ill try that

#

thank you

#

can you give me an example of what you mean by the index needed?

#

@stuck coral

#

actually dw

#

@stuck coral supposedly there is no function call to send an 8 element uint8 array

#

Serial.write and Serial.print throw errors

stuck coral
#

Oh youre using serial over bt not GATT? And there are multiple solutions to this problem, one would be to turn uint8_t to char (And make it one byte longer for null terminator), or encode the value as a hex string.

nova comet
#

@stuck coral would gatt be better?

stuck coral
#

I would think so, then you can just make the board a GATT characteristic and notify the iOS device when the board state changes, and when the iOS just wants to read the state it can

nova comet
#

I should probably do that

#

Alright

slate pendant
#

ok so somebody helped me yesterday with some webhook code and the only error I still got is the WiFi library referencing to the SPI library wich for some reason cant be found
any ideas?

nova comet
#

@stuck coral something like this?

#
 uint8_t result[8] = {0x0};
    for (int i = 0; i < 8; i++) {
       for (int j = 0; j < 8; j++) {
          if (board[i][j] == 1)
            result[i] |= 1UL << j;
       }
    }
stuck coral
#

uint8_t result[8] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }; or use memset but yes, you got it

nova comet
#

@stuck coral oddly enough, when i print the array it shows up as all 0's

#
for (int i = 0; i < 8; i++)
    Serial.println(result[i], BIN);
#

prints:

stuck coral
#

Whenever you set a bit, print something to console to see if the if statement is working right

nova comet
#

i think i got it, if the row looks like this:
10000000 then that is how it prints but if the row looks like this:
00010000 then it prints like this:
10000

is there any way to print that second part with the leading 0's?

#

or do i just have to deal with it