#help-with-arduino
1 messages · Page 67 of 1
will that loop still work
its long but at the end of the script it tells what pins to turn off
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
is it binary clock?
looks like an LED old school clock with hands
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
yes, there is room for improvement, looking at my example above it can be shortened further as well. Just starting out @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
array would be more flexible and can be put on PROGMEM (idk how much memory you have)
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
Yeah this code works long wise
then as @candid topaz is suggesting even more optimization can be had by using different techniques such as arrays
Ill learn more later
good luck with it, share a pic when you're done!
does anyone have use a makeblock orion cuz it seems im having issues with my buzzer and sensors
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
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.
@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!
@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
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
Yes, if you print it to serial do you see the whole string?
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
Yeah, you need to check over serial to see if its a issue in creating the json document, or if its the bluetooth MTU
I've tried a much longer, and a shorter sting, both had the closing } truncated
Ah, when you send the document, do you have a size value you provide?
@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
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
Possibly but to me that wouldnt make a ton of sense
doesn't explain it working locally though
Well lets just figure out if its printing to serial first, otherwise we're just taking stabs in the dark
Okay, can I see the code? Pastbin if you could
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
@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.
actually i think the last change may of fixed it
Thats good, looking at it you made the correct fix
@safe shell Thanks!
....or an nRF52840 + Airlift FeatherWing / BitsyWing
@stuck coral thanks for taking the time to help 🙂
@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
@reef ravine i will tanks
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".
@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.
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 ?
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.
Also depends on whether you want an FCC-certified module (larger), or if the bare chip is OK (e.g., as on the TinyPICO https://www.adafruit.com/product/4335)
This is ESP32s2 (no BT), but I hadn't seen this tiny antenna form factor before: https://unexpectedmaker.com/shop/feathers2-esp32-s2
I've used chip antennæ like that (in particular, a Taiyo Yuden AH316M245001-T)
2.5mm, nice
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
That's not my library, but I like the name
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
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.
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
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?
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
@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)
no its checking if hour is 10
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?
@twin ginkgo - a clean up of that code, and an example of what to do next to start debugging this: https://gist.github.com/mzero/67f58e71a63e34a6515755de82910f98
@obtuse spruce are the curly braces around the for statement optional?
@obtuse spruce good suggestion, I was going to give a versions with constants but thats way cleaner
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.
thanks @obtuse spruce but that is actualy just a test script my other script is a lot more then that
thanks @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
oh ok thanks im not a strong scripter but im getting there its my first time working with i
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?
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.)
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
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)
Yes, I had a 330 ohm resistor in series with the LED.
Ah, that should be fine. Maybe you just had a duff LED (it happens)
that would make sense. It was very new, I got it in an Arduino kit for my birthday. Oh well. Thanks for your help!
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?
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
Bluetooth GATT is the usual way of sending data
@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.
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?
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.
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
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.
just does not want to light up but if i go to another script and turn one led on at a time they work
this is my test script
i would change the mcp5 to mcp4 and change pins to test and it does work
but not in the main script
Does "day" print out correctly?
(By the way, your code could be simplified a lot by using some variables instead of if statements.)
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.
Okay - so clearly I can't test this, as I don't have your hardware, but this is how I'd go about starting to debug that code: By making functions that did the repetitive business: https://gist.github.com/mzero/c2c501a0334610a8d998c7aa34b40f40
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
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
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.
@fallen canyon
while(true) {}
@fallen canyon - do you mean you want to halt all further processing - or "I'm just done with this time through loop()"?
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"
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
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
}
so return is the command to make it restart the loop
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
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
no, it isn't - that is just a power pin.
ok
then code side it is
thanks for the examples up there i will see if i can butcher it on my end lol
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
Is it an output? Just set it low until you need it high.
@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?
inputs are high-z or pull up
or can that be any pin
unless you want open collector mode?
whats open collector?
im new to arduino so not all these terms are known to me yet
what processor board are you using?
last time i had to go pulup on the pin so it would throw between low and high constantly
i have an uno
what is on the input
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
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
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?
@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
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?
@fallen canyon I think the tildes are for PWM, almost any pin should be able to do digital input
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)
alright cool that makeds things that much easier then
yeah im avoiding d0/1
using 2 through 13 and the analog
BTW, uno has internal pull-ups but no internal pull-downs - for that you would other boards, such as those based on m0 chip
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?
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
so thats proabably what i need to have running my pulse on the drivers for my steppers
stepper drivers work differently, so you do not control them using analogWrite(), but there is no harm in using PWM enabled pins for them
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
thanks!
can someone link me something how to use a 7 segment 4 digit display without backpack
thanks
that's why they make backpacks, only need 2 wires 🙂
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"
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.
Is it ok to ask a question about C# here?
It's kinda related to Arduino but not really at the same time.
#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>
The error message itself is missing, so we can only guess. Possibly a library issue?
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
Might start here https://learn.adafruit.com/lesson-0-getting-started
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 🙂
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? 🙂
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;
}
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.
@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 */
}
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
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!
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```
yup - do you need to run code once for each bad character? or only once if there are any bad characters?
no once it finds a bad char it can stop
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++!)
I had split them up but I do like less code for the same answer
right, but in C/C++ you can't write case 'x', 'y':
you have to write it case 'x': case 'y':
you have to write it
case 'x': case 'y':
@obtuse spruce So that would have them all inline then
yup - though they can be on separate lines, like in my example
so under each case would I have to put thegood=true
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)
Once it happens I just do a device reboot to fix the issue.
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.
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();
}
}
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.
I did that because the LoRa library requires a Char[] to transmit.
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());
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?
can someone help me please
@rotund nebula You need to ask the actual question.
That's very vague. 😉 Which errors and where?
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
248 would be 0xF8. Is that what you sent during that test?
I sent just ‘3’
And both the 248 and 0 popped out
When i printed the data
@cedar mountain
@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.
The board matrix isnt what is printing ill show ya
I didn't think so - but I thought I'd point that out anyway
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?
I can try that
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
@cedar mountain any ideas?
should i paste my code here?
Sure, go ahead and give me a pastebin

Sure, go ahead and give me a pastebin
@stuck coral https://pastebin.com/xWahGJ5g
@nova comet is there anything in the documentation from the module about what it returns?
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
@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 }
const long threshold = 100 (for example) comes in the beginning to all other const variables?
Well const just makes it constant, meaning its not meant to change
Another way would be #define THRESHHLD your_number
if(threshhold>="50" "cm"){ //not sure what to put next to >=
digitalWrite(ledPin, HIGH);
digitalWrite(buzzPin, HIGH);
}
else {
digitalWrite (ledPin, LOW);
}
}
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.
so
#define treshhold 50
and
if(threshhold>=cm)
Yeah
getting an error now
entfernung_messen:40:1: error: expected declaration before '}' token
}
^
exit status 1
'microsecondsToCentimeters' was not declared in this scope
Put microsecondsToCentimeters() above your setup
as an "int"?
No, copy your function named microsecondsToCentimeters() and put it above your set() function
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?
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
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()
Hey, I am trying to connect an airlift co-processor to a metro mini to add some wifi capability, but I cannot get the scan network example to work.
Here's the code I'm attempting to use: https://www.codepile.net/pile/857Mq2DW
{{ description }}
this is the airlift coprocessor, if that helps:
i hate that english is not my main language...
i undid everything. starting with the paste i sent you again
yes
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 https://pastebin.com/8px3G8Ew
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
FML................... i thought you ment i need to copy line 25 and put it there
jeeesus... that wouldve been long to figure out
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
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?
yes
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
yes that is connected to digital 1
Could i see your setup with the board and co-processor?
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
I would disconnect that from power ASAP
uhoh. why?
Send me a link of the board you have?
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
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
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.
@ripe flint Im going to make you a quick library branch
okay
First, could you try adding WiFi.init(); right after WiFi.setPins()?
`'static void WiFiClass::init()' is private within this context
thats the error that appears
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
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
BUSY and MISO are outputs from the airlift
You are right
5V logic with 3.3V compatible inputs
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.
Connections look good to me, not sure why it would be hanging unless it cant read the BUSY signal looking at the library
okay, question though, are there supposed to be any LEDs active on the airlift when power is given ?
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
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
loop() acts like a big while loop, you can change the while to a if and prodide an else to turn them off
yeah i got a bunch of if else now thats working the way i intended
but i was hoping for a more efficient method...
What do you mean you have a bunch of if else?
one moment let me haste it\
Untitled Paste | Paste #73226 - Simpler Pastebin - Denizen Script
gotta have a bunch of areas so i can enable or disable the drivers when they hit my limit switch\
Im not understanding your complaint
Looks normal to me, maybe add toggles but that I would consider all of that to be correct.
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
Not in c, Im not sure what languages your refer to, and thats not many if statements
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
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
@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.
@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.
ill add in comments later
to explain it
most of it at this point is to get it working on all 8 limit switches
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.
sounds good
if you try to expand this code, in the form it is in, to 8 limit switches - you'll go nuts!
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
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;
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
again - don't worry about the efficiency in execution - it is efficient in expression!
as this is my first basic c code ive ever written
That's fine - let me help you understand it - all the calls are the same ones you had.
ask away!
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"
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
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!
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?
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
i mean i follow that better than the shorthand bits there
so i can agree for sure there
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
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
No problem - let me help you see it - it isn't hard.
test ? result_if_test_is_true : result_if_test_is_false;
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.
@safe shell do you know which pins do i need to use to turn on the onboard LEDs
@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
"yesssssss.... now we've hooked them...... reel in slowly..... slowly...."
haha braincells just had a colission
I try to make the code read - in code - what I'd say about what I want to have happen. Consider:
- Read the
switch_into 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_1orlimit_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.
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
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.
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
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.
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
okay - and you probably have several of these things - each with an in and an out side, right?
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 ?
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
so its more of a choose command than an if statement
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).
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
@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
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.
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
@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.
i think i get whats happening there now
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.
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
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
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
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
SPI is a class?
it's the SPI port, from <SPI.h>. I'm assuming that's as it should be
That makes sense.
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?
Thats what I have them set to
It's clear on the Metro which are the 3 SPI pins?
yes, 11-13 are the SPI pins (MOSI, MISO, CLK)
No LEDs, or Serial.println("enter loop");
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
Metro mini:
https://learn.adafruit.com/adafruit-metro-mini?view=all#pinouts
AirLift co-processor:
https://learn.adafruit.com/adafruit-airlift-breakout/pinouts
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!
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
wonderful!
I cant believe it was that simple. Thank you so much for going through all of that with me.
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!
thank you.
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
@sterile niche How did you connect the second LED?
the same way @lone ferry
I don't know what you mean by that. 😉
The Voltage theems to low for the second LED, try it to wire it parralel circuit
did you put the 2nd one in place of the 1st to see if it works? else you need to use another LED
It's best if you show us a picture of exactly what you did, @sterile niche
ok
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).
yup
aren't the 2 LEDs going to be half as bright as the 1st LED was because they're sharing the..voltage?
I guess that depends on how they are connected.
The same voltage is applied over both parallel branches. The current is split up.
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. 😄
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?
Does String(("," + f) + ",") work?
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
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.
Ahh I see, okay, thanks!
anyone here to help me with my project?
Just ask the question, @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
https://pastebin.com/aYeRN7iy
this is my old code i added the else and if function
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
i dont know how i add that if and else function to my code
Change int distance; to float distance;
that just changed that the distance is 0,00 instead of 0
Also, note with with duration = 20, the distance variable is 0.34. Because it's an int, that gets rounded down to 0.
thats why i get 0 distance in the seriel monitor?
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.
ok i got it to flash becuase distance is shown at 0,34
but its a constant 0,34
not changing
Well, your code doesn't contain any logic for changing it. Not that I can see anyway...
i thought the ultrasonic sensor just shows the value. 😦
@lone ferry do you have time to help me in a call or something?
yes i am. sorry for not answering
RFID Card Reader Serial: Reads Card Multiple Times (via Software Serial)
@stable hamlet whats the problem exactly?
@nova comet
thats the code currently.
and the led blinks everytime a measurement is done.
and i want the led to blink under 50cm and get faster the closer i get
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
what exactly is the issue right now
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
and you want the LED to light up progressively faster as the sensor value decreases?
Yes
and echopin is ur ultrasonic??
@stable hamlet it doesn't look like flashtime changes anywhere
Echo and trig Pins are ultrasonic sensor
the problem is that you never set distance
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
but flashtime never changes
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.
Will test in like a half hour
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
Appreciated
@obtuse spruce you there?
tried to do as you said. but now im getting a constant beep+blinking led.
serial monitor shows 0cm everytime the led lights up
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
on a different code it worked to show me values
but now as i added flashtime and stuff
is there a way to know which code i flashed on my arduino nano?
i think i got it to work
@stuck coral
thanks for the help from yesterday
the parksensor
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
Glad to hear
I was wondering if there is some way to communicate with an xbox one controller to an arduino, or indirectly through like processing?
What's that controller communicate with?
xbox one
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
thx
;)
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?
You can use the same buffer, provided it is large enough.
(And you're not using it for something else at the same time.)
Thank you very much @lone ferry ! 😄 have a nice day!
@sterile niche - two quick things:
- make constants for your pins, either like:
const uint32_t pinGreenLED = 3;
- or like: -
enum {
pinGreenLED = 3,
pinYellowLED = 4,
...
- 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.
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
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)
Thank you
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.
it seems like const int would take up storage
Not necessarily. And#definewould take up the same amount of storage in the same situation.
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.
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.
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!
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
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.
https://www.adafruit.com/product/2884 -- is an example, but they make others as well.
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!)
This prototyping shield is the best out there (well, we think so, at least), and now is even better with Version R3 - updated for the most compatibility with just about all the Arduinos! It ...
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
screw terminals have their problems too - I think the safest would be to use some latchign connectors such as Grove. There are grove shields for full-size arduino: https://www.robotshop.com/en/i-o-grove-base-shield-arduino.html
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
@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
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
And getting a phone call while holding the screwdriver
There are these Arduinos without pins http://www.righto.com/2015/05/bitcoin-mining-on-55-year-old-ibm-1401.html
oops wrong link I meant https://www.sparkfun.com/products/10915
how do I figure out which pins are MISO, MOSI on the BME280?
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.
smart, ty
@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
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```
No, it doesn't have a USB port, it's designed to be used with a USB-serial converter like an FTDI cable or https://www.adafruit.com/product/3309
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.
@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.
Cool stuff
@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)
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.
@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
nice!
have you ever written sensor data to a sql database? Sqlite specifically.
unfortunately not
I have some experience with MySQL on websites, but never used local deployment
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
it works with the feather? I'll look it up
it works with anything that is wifi enabled
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
cost? I haven't got to that point
there is also adafruits' IoT platform: https://io.adafruit.com/
and even a channel right in this discord #help-with-wippersnapper-and-adafruitio
Adafruit IO is the easiest way to get your projects onto the Internet of Things!
ok cool ty
haven't used it myself
how much is it to use Blynk for developers? I didnt see it anywhere.
free hosting seems too good lol
for personal use or to develop for clients?
personal
for personal use, it works like that: every "widget" you add in blynk app on your cell phone cost some "energy"
ok
you get some amount for free, then you pay
thats cool
but it is peanuts - maybe a couple of dollars for a project
ok
and it is one-time per project, not monthly
oh thats not bad
at least it used to be so
thanks for all of the info. Glad there are potential libraries for me to work from instead of going from scratch.
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..:
anyone have any ideas of how i could send a 2d array over ble
like
how to convert it into hex or smth
Hex could work or you could use a higher level protocol like Firmata
@north stream how would i go about that conversion
@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.
@obtuse spruce what do you mean? What type of device?
no, what software - you're sending a 2D array over BLE to what? What software will take and use that 2D array?
im sending over to an ios app
one that you are writing? so it is a companion?
yes
Ah - okay - then you have lots of options - it is a 2D array of what kind of data? and about how big is it?
oh - just boolean? not like the chess piece itself?
no no im inferring all of that via software. It's a reed switch matrix
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.
so just something like left to right top to bottom
yup
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
this is only sent upon a move being confirmed so it should be fine
then sure - there ya go
😁
:)
@obtuse spruce you think i should just append the numbers to a string and then convert to hex?
no
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 -
i guess just to shorten it since everything else i have is in hex too
all my other commands
shorten? that would make it longer
the hex string would be longer than the binary??
i dont mean in terms of runtime
i mean in terms of the string length
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) ...
i guess ill leave it in binary
I guess I wouldn't call what I wrote "binary" - I mean the two characters could have been * and `.``
Alright
@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
@nova comet - was at dinner - will look now.
er - that code doesn't send anything over BLE ...
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?)
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?
Ive got an arduino hooked up to the hm18
So - er - how does writing to Serial go out both the USB port and some serial UART?
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
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
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
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
never mind, the Arduino Mega pins are different than the other boards
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.
Similar techniques will work with Arduino, you can write a subroutine that accepts arguments for which servo and what parameters.
@calm hatch arduino is using a version of c++, so you can define funcctions in the same way as in c++
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:
I am using the EPS8266 Boardmanager.
and obviously I will change the webhook adress once implemented :P
two quick thoughts:
statusis never updated - so all those tests for!= WL_CONNECTEDare pointless- If it is a secure client, then why is it using port 80? Shouldn't it be 443?
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:
Open-source electronic prototyping platform enabling users to create interactive electronic objects.
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?
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....
ohhh ok
I cant turn the outdated ESP libraries off because they come included with the boardmanager
what would be the solution?
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.
I would like to use the standart arduino/adafruit libraries instead of the ESP libraries
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.
ahh ok thanks ^^
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?
@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
More info on what Im talking about can be found here https://learn.adafruit.com/arduino-to-circuitpython/overview
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.
Which in a super cut down and basic sense, is CP
Right, just thinking of something that could fit on an Arduino.
Ah, I see.
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)
Lol, you made me search for embedded lisp and of course thats a thing, love it, even supports an UNO 😆
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
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
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.
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
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?
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.
nice
CP does not support the ESP32 or ESP8266 which is what nodemcu uses
where do u recomend buying them as the shipping is really expensive from adadfruit
Digikey but thats not really cheaper in most cases
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.
I doubt Micropython supports any 32U4 devices...
The 32U4 can emulate a USB keyboard device, but it can't run Python.
rip
i found someone who kinda did somthing i am trying to do so im going to look into that
Is anyone familiar with Nrf24l01 modules?
Im getting a repeated 0 in the serial monitor.
@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
or - put it in a pastebin ( https://pastebin.com/ )
Your if test is backwards
if (radio.available()) { is what you want in the receiver.
your eyes are better than mine lol
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?
you have if radio not available
!
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.
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);
}
}
}
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.
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
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);
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?
the bottom is easiest, if you start with the top, it tends to fall onto the bench quickly.
If you don't have anything lying around that will fit, I'd buy a case and then modify it to suit your needs.
@opal mirage this site has tons of cases of all sizes: https://www.polycase.com/
Polycase is a premier manufacturer of plastic electronic enclosures and boxes. Purchase high-quality plastic, aluminum, steel and NEMA-rated enclosures for any application from Polycase.com.
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
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.
There are wires of 24vdc, 5vdc and 230vac in its close proximity, could those be it?
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.
Thanks I'll try doing that, however previously it was already connected to my NodeMCU and it still did the switching
That is odd, unless the NodeMCU didn't have its I/O pins configured as outputs, or they didn't share a common ground.
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
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.
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
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)”
Looks like you might be able to use something like mcp.readGPIO();: https://github.com/adafruit/Adafruit-MCP23008-library/blob/master/Adafruit_MCP23008.cpp#L107
It's conceptually a multiplexer, but easy enough to write a helper function to read and sum the inputs.
the register read @north stream highlights has the advantage of simultaneous state on each pin
So something just like int readAll = mcp.readGPIO(); ?
@safe shell If you could elaborate more. I’m not fully sure now
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?
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
no - you've got it right - and that call will give you that value.
Ahh awesome .. so just set them all high in the set up and the loop could have the uint8_t allPins = mcp.readGPIO();
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!
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
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!
welcome and good luck
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**
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
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
I am using a standard arduino uno board, what would be the conditions for the if statement, I am rather new to this
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
For an example similar to what you want to do, I would reference this https://www.arduino.cc/en/Tutorial/Switch
Open-source electronic prototyping platform enabling users to create interactive electronic objects.
Can this work without a button?
Sure, a button is just two contacts
Alright perfect, thank you
@stuck coral u around?
Yep, just got home from work
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)
Well the result you defined is 32 bit, so no it shouldnt, it can only be 32 bits long
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
Im not sure, Im not familiar with the Arduino bt stack but I can take a look ig
i just changed the uint32 to int and it still prints ffffffff
What Arduino are you using? Its probably still 32 bits
uno
You sure its the same value? Should be 16 bits so shorter not longer
"FFFFFFFF"
Alright, what are you trying to do again?
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
Why do you have strings of 1/0? That seems silly to me.
someone here told me to do it :/
im very open to suggestions this isnt working for me at all
Could I see your code in a pastebin?
Looks to me those strings are just for the console, not for general storage + transport.
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
Well you dont want it to send what piece is what? Just if there is a piece in a spot correct?
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
you are saying a nested for loop to go through each digit of the array correct
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
two hex digits can represent 8 bytes right
isnt uint8 only 8 bits?
Correct, thats why result is an array 8 values long
omg im stupid sorry
No you're fine
lmao
oh
oops
anyways
so
each position in the result array will hold a row
or column
Well, that is true. Wasnt the goal, but is true
so can i send result all at once or do i need to send each entry of the array seperately
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
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
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.
@stuck coral would gatt be better?
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
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?
@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;
}
}
uint8_t result[8] = {0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0 }; or use memset but yes, you got it
@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:
Whenever you set a bit, print something to console to see if the if statement is working right