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() {}

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).



Multiple libraries were found for "tinyNeoPixel.h"
 Used: C:\Users\Dean\AppData\Local\Arduino15\packages\ATTinyCore\hardware\avr\1.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
    Can you please show your code and the full error message, that you get? When including the library, you should be able to use the tws_delay() function, just as it is used in this example from the library – chrisl Jul 29 at 12:36
  • Alright I have added the code and error message, just to note I tried putting tws_delay(50) as well and still got the same error – tatty fish pickle Jul 29 at 13:24

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!

| improve this answer | |
  • 1
    Thanks 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 Jul 29 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 Jul 29 at 13:47
  • Sorry, 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 Jul 31 at 1:14
  • 1
    Okay that actually makes sense, I'll look into it, thanks! – tatty fish pickle Jul 31 at 10:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.