Need help using picoUART for serial commands

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

are you using a bare attiny85? Looks like the library assumes a clock speed of 8 MHz. Did you set the fuse on your attiny85 so the CPU runs at 8 MHz instead of 1 MHz?

yes thanks for replying.

it is running at 8mhz and I did finally manage to get it working.

There was a bug certainly in the ISR method Update echo-ISR.ino - waste a byte · Kaspi314/picoUART@4990e6c · GitHub

I also found out that it does not work properly using both ISR and 1 wire as the one wire method rx/tx seems to trigger the ISR.

It does, however, work on the same pin with a 16 channel analogue digital multiplexer demultiplexer if you switch to an rx and tx channel between rx and tx windows.

It seems I also did not properly understand overriding the #define PU_TX and PU_RX and baud.

the baud is in pu_config.h:

#ifndef PU_BAUD_RATE
#define PU_BAUD_RATE 115200L            // default baud rate
#endif

how would I go about changing that in my sketch do I need to #undef or just #define?

#define PU_BAUD_RATE 9600L is not working

but changing it in pu_config works (as well as for the pins.)

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.