@Johnex:I tried to do TinyPinChange_DisablePin before drawing to the led's
This should be equivalent to remove the TinyPinChange, so, your NeoPixels should work as usual. Without the full sketch, it's not possible to investigate.
@digispark (original or pro) users:To complete the remark of Erik (digistump) about Hardware Serial versus Software Serial, find below in what cases it's interesting to use Hardware built-in serial and softserial:
1) When do you need to use built-in HardwareSerial: a) in priority, use hardware resource such as the built-in HardwareSerial available in the Digispark pro (not available in the original). This will reduce the microcontroller load (MCU load). The TX and RX pins are using TTL levels (0/5V).
b) if you need to interface
directly with another TTL Serial port (some GPS, another Digispark by crossing TX and RX, etc). The 1K resistors are not mandatory, but are recommended: they protect the TX outputs if they are connected together with opposite levels.
TTL HARDWARE SERIAL TO TTL SERIAL
=================================
,-----------------------, ,------------------------------,
| Arduino Digispark PRO | | - another Digispark |
| .--|HwSerialTx 1K* Rx|--, - GPS |
| | >--------------###-------------> | - TTL serial/USB adapter |
| Sketch |HS| |TS| - etc |
| | <--------------###-------------< | |
| '--|HwSerialRx 1K* Tx|--' |
| | | |
| (VCC=+5V) GND|------------------------------|GND |
'-----------------------' '------------------------------'
HS: Hardware Serial *: optional, but recommended TS: 5V TTL Serial
It's also possible to interface with some bluetooth modules such as HC05, but even the TTL signals have the right logic (not inverted), a 5.0 <-> 3.3V level shifter is required since HC05 I/O are not 5V I/O tolerant. A simple passive level shifter is given below:
0/3.3V <-> 0/5V TTL LEVEL SHIFTER FOR DIGISPARK PRO AND BLUETOOTH MODULE
========================================================================
+5V +5V
--- ---
| |
| #
,-----------------+--, # 4.7K ,-----------------------,
| VCC | # | Arduino Digispark PRO |
| BLUETOOTH UART |BT_Tx 1N4148 | HwSerialRx|--, |
| HC05 TX>-------|<|---o----####----> | |
| Module | RS232 TTL 150 |HS| Sketch |
| RX<-------o--####------------< | |
| (I/0=3.3V) |BT_Rx | 2.2K HwSerialTx|--' |
| GND | # | (VCC=+5V) |
'----+--------+---+--' # 3.3K '-----------------------'
| Switch | | # HS: Hardware Serial
'-.-.----' | |
| | --- ---
'-' GND GND
AT Mode<- -> Transparent Mode c) If you need to interface with a true RS232 port (eg: COM port of a PC or RS232/USB adpater), it's mandatory to insert a RS232 line driver such as the MAX232 in order to adapt the logic and electric levels (0/5V <-> +12V/-12V). Please note a +5V (TTL) corresponds to a -12V for RS232: the logic is inverted and the absolute electric levels are different. Please, refer to the MAX232 datasheet for the full wiring.
TTL HARDWARE SERIAL TO RS232 SERIAL INTERFACE THROUGH A MAX232 LINE DRIVER
===========================================================================
____
,-----------------------, | \
| GND|-----------------o-----------o5 \
| | | | 9o |
| Arduino Digispark PRO | | | o4 |
| .--|HwSerialRx .----+----. | 8o |
| | <------------< <------o3 | ---> To regular RS232 SubD 9 pins Male of PC
| Sketch |HS| | MAX 232 | | 7o | or to RS232/USB adapter
| | >------------> >------o2 |
| '--|HwSerialTx '----+----' | 6o |
| (VCC=+5V) | | | o1 /
| +5V|-----------------' |____/
'-----------------------'
HS: Hardware Serial
2) When do you need to use one or several softserial(s): a) if the built-in HardwareSerial of the Digispark pro is already used and you need additional serial port
b) if you do not want to insert a R232 line drive (MAX232) to adapt the logic and the electric levels (AFAIK, it's not possible to invert the logic for the HardwareSerial). In this case, you have to use a softserial with
true for the third optional argument:
#define TX_PIN 0
#define RX_PIN 1
SoftSerial MySerial(RX_PIN, TX_PIN, true); //true allows to connect to a regular RS232 without RS232 line driver
TTL SOFTWARE SERIAL TO RS232 SERIAL INTERFACE WITHOUT A MAX232 LINE DRIVER
==========================================================================
____
,-----------------------, | \
| GND|-----------------------------o5 \
| | | 9o |
| Arduino Digispark PRO | | o4 |
| .--|SwSerialRx 1K | 8o |
| | <--------------###------------o3 | ---> To regular RS232 SubD 9 pins Male of PC
| Sketch |SS| | 7o | or to RS232/USB adapter
| | >--------------###------------o2 |
| '--|SwSerialTx 1K | 6o |
| (VCC=+5V) | | o1 /
| +5V| |____/
'-----------------------'
SS: SoftSerial
c) If you have to interface with another serial with TTL levels (some GPS, another Digispark by crossing TX and RX, etc):
#define TX_PIN 0
#define RX_PIN 1
SoftSerial MySerial(RX_PIN, TX_PIN); // without the 3rd argument, the softserial is configured to interface with another TTL serial
TTL SOFTWARE SERIAL TO TTL SERIAL
=================================
,-------------------------, ,------------------------------,
| Arduino Digispark (PRO) | | - another Digispark |
| .--|SwSerialTx 1K* Rx|--, - GPS |
| | >--------------###-------------> | - TTL serial/USB adapter |
| Sketch |SS| |TS| - etc |
| | <--------------###-------------< | |
| '--|SwSerialRx 1K* Tx|--' |
| | | |
| (VCC=+5V) GND|------------------------------|GND |
'-------------------------' '------------------------------'
SS: SoftSerial *: optional, but recommended TS: 5V TTL Serial
It's also possible to interface with some bluetooth modules such as HC05, but even the TTL signals have the right logic (not inverted), a 5.0 <-> 3.3V level shifter is required since HC05 I/O are not 5V I/O tolerant. A simple passive level shifter is given below:
SERIAL<->BLUETOOTH ADPATER VIA A DIGISPARK (Original or PRO)
============================================================
+5V +5V
--- ---
| |
| #
,-----------------+--, # 4.7K ,-------------------------,
| VCC | # | Arduino Digispark (PRO) |
| BLUETOOTH UART |BT_Tx 1N4148 | HwSerialRx|--, |
| HC05 TX>-------|<|---o----####----> | |
| Module | RS232 TTL 150 |SS| Sketch |
| RX<-------o--####------------< | |
| (I/0=3.3V) |BT_Rx | 2.2K HwSerialTx|--' |
| GND | # | (VCC=+5V) |
'----+--------+---+--' # 3.3K '-------------------------'
| Switch | | # SS: Software Serial
'-.-.----' | |
| | --- ---
'-' GND GND
AT Mode<- -> Transparent Mode
d) If you need a serial port, but a single pin is available (all the other pins are used), you can configure the softserial to work with a single pin:
#define TX_RX_PIN 0
SoftSerial MySerial(TX_RX_PIN, TX_RX_PIN, true); //true allows to connect to a regular RS232 without RS232 line driverTo interface this single wire soft serial port to a regular RS232 port, you need to build the following adapter: (2 x resistors and a diode)
SINGLE WIRE SOFTWARE SERIAL TO RS232
==================================== ____
,-------------------------, | \
| GND|-------------------------o---o5 \
| Arduino Digispark (PRO) | 47K | | 9o |
| .--| .--###--' | o4 |
| | | 4.7K | | 8o |
| |SSx------------###--o--|<|------o3 | ---> To regular RS232 SubD 9 pins Male of PC
| Sketch | | | 1N4148 | 7o | or to RS232/USB adapter
| '--| '-----------o2 |
| | | 6o |
| (VCC=+5V) | | o1 /
'-------------------------' |____/
SS: Software Serial
with Tx Pin = Rx Pin
To summarize:A) Hardware serial:
- efficient, to be used in priority
- full duplex: can receive whilst transmitting (TBC)
- can be connected directly to another TTL serial (eventually through a voltage level shifter for devices I/O in 3.3V)
- shall be connected to a true RS232 COM port through a MAX232 line driver
- cannot be connected directly to a true RS232 COM (logic cannot be inverted)
B) Software serial (softserial library):
- half duplex: cannot receive whilst transmitting
- same API of the regular arduino <SoftwareSerial> library + some additional methods for usage on a single pin.
- can be connected directly to another TTL serial (eventually through a voltage level shifter for devices I/O in 3.3V)
- can be connected directly to a a true RS232 COM port (with true as 3rd argument)
- can be connected to a true RS232 COM port through a MAX232 line driver (without the 3rd argument)
- can be used with a single I/O for receiving and transmitting from/to a true RS232 COM port without a MAX232 line driver
- unlike the regular arduino <SoftwareSerial> library, can be used with pin change interrupt (<TinyPinChange> library)
- it's not possible to listen simultaneously to several software serial ports
- less efficient: for receiving, it stays in the ISR for all the 10 bits of the character (1 start, 8 data, 1 stop). For transmitting all the interrupts are disabled
during the 10 bits of the character. It's less intrusive if a high serial data rate is used.
Note:
All these features are available with <softserial> library (delivered with digistump arduino IDE). Do not be confused with the regular arduino <SoftwareSerial> library which do not allow this.
Hope this clarifies the different use cases.