EDIT: Alright I'm stupid, I had the 2012 library installed somehow, maybe when I downloaded it indirectly from another old tutorial site. Thanks a ton to Peter Freerick for pointing that out! It finally compiled now
So I'm currently doing a little project where I have an ATTiny85 controlling some (neopixel) RGB addressable LEDs, which is controlled over i2c from an Arduino UNO Master. The goal is to make an Attiny85 into an i2c slave that receives a simple command (such as a single digit int) and decide which premade LED display program to use.
I'm using ATTinyCore, TinyWireS, and Adafruit's tinyNeopixel library for the tiny, and programming it using an Arduino UNO as ISP.
My issue is this: The led code requires a delay to change the speed of the light show. But I see in the TinyWireS example here that I should be using tws_delay instead of the normal delay.
Various googling attempts have left me nowhere to learn how to use tws_delay, what it is, or how to even declare it. I get a declaration error when I try to use the delay with the TinyWireS library included.
I would like to find a resource for learning how to declare and use this delay. Thank you for reading this far
EDIT: I have now added my code and error below, you can find the tws_delay in void loop near the bottom
// NeoPixel Ring simple sketch (c) 2013 Shae Erisson
// released under the GPLv3 license to match the rest of the AdaFruit NeoPixel library
#if (F_CPU>7370000) //neopixel library required 7.37MHz minimum clock speed; this line is used to skip this sketch in internal testing. It is not needed in your sketches.
#include <tinyNeoPixel.h>
#include <TinyWireS.h>
// Which pin on the Arduino is connected to the NeoPixels?
#define PIN 3
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 8
// When we setup the NeoPixel library, we tell it how many pixels, and which pin to use to send signals.
// Note that for older NeoPixel strips you might need to change the third parameter--see the strandtest
// example for more information on possible values.
tinyNeoPixel pixels = tinyNeoPixel(NUMPIXELS, PIN, NEO_RGB + NEO_KHZ800);
int delayval = 500; // delay for half a second
void setup() {
pixels.begin(); // This initializes the NeoPixel library.
}
void loop() {
// For a set of NeoPixels the first NeoPixel is 0, second is 1, all the way up to the count of pixels minus one.
for(int i=0;i<NUMPIXELS;i++){
// pixels.Color takes RGB values, from 0,0,0 up to 255,255,255
pixels.setPixelColor(i, pixels.Color(0,150,0)); // Moderately bright green color.
pixels.show(); // This sends the updated pixel color to the hardware.
tws_delay(delayval); // Delay for a period of time (in milliseconds).
}
}
#else //neopixel library required 7.37MHz minimum clock speed; these and following lines are used to skip this sketch in internal testing. It is not needed in your sketches.
#warning "Neopixel control requires F_CPU > 7.37MHz"
void setup() {}
void loop() {}
#endif
And the error:
C:\Users\Dean\AppData\Local\Temp\arduino_modified_sketch_145294\simple.ino: In function 'void loop()':
simple:36:5: error: 'tws_delay' was not declared in this scope
tws_delay(delayval); // Delay for a period of time (in milliseconds).
^~~~~~~~~
C:\Users\Dean\AppData\Local\Temp\arduino_modified_sketch_145294\simple.ino:36:5: note: suggested alternative: 'delay'
tws_delay(delayval); // Delay for a period of time (in milliseconds).
^~~~~~~~~
delay
Multiple libraries were found for "tinyNeoPixel.h"
Used: C:\Users\Dean\AppData\Local\Arduino15\packages\ATTinyCore\hardware\avr1円.3.2\libraries\tinyNeoPixel
Multiple libraries were found for "TinyWireS.h"
Used: C:\Users\Dean\Documents\Arduino\libraries\TinyWireS
exit status 1
'tws_delay' was not declared in this scope
2 Answers 2
tws_delay()
is a function provided by the TinyWireS library here. As you can see from the declaration - void tws_delay(unsigned long);
- it accepts a parameter of unsigned long
, just like delay()
does.
In fact, the comment on the line above that declaration says...
// Implement a delay loop that checks for the stop bit (basically direct copy of the stock arduino implementation from wiring.c)
... so, it's safe to say that wherever you would have used delay()
, you can use tws_delay()
.
So there should be no need to declare or define it. But to simply use it. If using tws_delay()
in code that includes TinyWireS.h
doesn't work, I would be checking that you have a version of the library that declares/defines it. Which you should, given the example you linked, as that repo has had the function since 2012!
-
1Thanks for the reply! So I've added my code and error to the original post. It seems I still get the error even though the library should have declared it right? Also yes I have the newest version of the library installed. I will go double check now just in case. Edit: Oh crap I actually somehow have the code from 2012!! That must be the issue! I'm going to install the new library right now and try that.tatty fish pickle– tatty fish pickle2020年07月29日 13:25:02 +00:00Commented Jul 29, 2020 at 13:25
-
Okay sorry to be a pest but I have now solved the issue thanks to you but immediately came across another slight issue, the timing for the delays seems to be way off. For example if I put 1000 in the parenthesis it blinks for a fraction of a second. I wanted to ask you since you seemed to know how it works but I'll open another full question post for this if needed.tatty fish pickle– tatty fish pickle2020年07月29日 13:47:01 +00:00Commented Jul 29, 2020 at 13:47
-
1Sorry, can't help you with that one off the top of my head... the twi_delay function looks like it should operate properly... if the clock speed of your device is set properly. It should basically put in a 'blocking' 500ms delay (blocking as far as nothing else except
TinyWireS_stop_check
can repeatedly run, but no longer does anything, as the comment above the implementation suggests TinyWireS became interrupt driven). I bet that is the actual issue, and that tinyNeopixel uses the interrupt TinyWireS wants to use.Peter Feerick– Peter Feerick2020年07月31日 01:14:27 +00:00Commented Jul 31, 2020 at 1:14 -
1Okay that actually makes sense, I'll look into it, thanks!tatty fish pickle– tatty fish pickle2020年07月31日 10:30:40 +00:00Commented Jul 31, 2020 at 10:30
-
1Voting your answer up because they didn't despite clearly finding it helpful.timemage– timemage2020年12月26日 16:10:16 +00:00Commented Dec 26, 2020 at 16:10
Answer: Make sure you install the right library :P
-
1It would make more sense to bring your answer-material out of the question and down here into your "answer" to make it a proper answer.timemage– timemage2021年07月17日 12:38:17 +00:00Commented Jul 17, 2021 at 12:38
-
Sorry I'm not sure how to do that at all. Is there some button I'm not seeing?tatty fish pickle– tatty fish pickle2021年07月18日 13:13:22 +00:00Commented Jul 18, 2021 at 13:13
-
You have edit links under both your question and answer, so can effectively cut and paste between them. It's also possible to mark your own answer as accepted, so that there is an accept answer to the question.timemage– timemage2021年07月18日 14:04:53 +00:00Commented Jul 18, 2021 at 14:04
tws_delay()
function, just as it is used in this example from the library