Using PicoUART I was able to run the example sketches however attempting to use the serial connection for anything seems to cause me much pain in trying, as even toggling an LED seems to cause the code to act drastically differently and constantly spam the output with "got: ?????????????" and not receive data correctly.
This is obviously not the intended outcome and the library seems to use a lot of optimized ways of going about things. such as using direct registers PORTB and such things. I am still learning but don't know too much about the Attiny85 and it is a lot harder to use for such a simple project that I had thought it would work great for just returning sensor data over uart from analog sensors and turning a few pins on or off. (It doesnt have the built in hardware serial and this has caused a lot of pain.)
Ideally I would like to use the picoUart with an analoge/digital multiplexer and only enable the rx for a duation of time. Does anyone have any advice on how I might go about this?
The picoUART library is on github: GitHub - nerdralph/picoUART: small, fast, and precise bit-bang UART for 8-bit AVR MCUs
Here is an example of my code I am trying to toggle an LED, but I would like this to work ultimately with a CD74HC4067 and half duplex.
#include <pu_print.h>
#include <picoUART.h>
const int buflen = 20;
char linebuf[buflen];
bool ledstate = false;
int readline()
{
int count = 0;
char c;
do {
while ( ! purx_dataready() ); // wait for data
c = pu_read();
linebuf[count++] = c;
} while ( (c != '\n') && (count < buflen - 1) );
linebuf[count] = '\0';
return count;
}
void setup()
{
pinMode(1, OUTPUT);
ledstate = 0;
prints("\nrxISR line echo\n");
}
void loop()
{
if ( purx_dataready() )
{
readline();
prints(ledstate ? "\n1:" : "\n0:");
prints("got: ");
prints(linebuf);
}
switch (linebuf[0])
{
case '0' : {
digitalWrite(1, LOW);
ledstate = 0;
}
case '1' : {
digitalWrite(1, HIGH);
ledstate = 1;
}
}
}
Settings:
// port and bit for Tx and Rx - can be same
#define PU_TX B,4
#define PU_RX B,0
// disable interrupts during Tx and Rx
#define PU_DISABLE_IRQ 1