Hello there, newbie here
I recently bought a digispark with attiny85 and work pretty well for most of the part. But i've stumbled upon some problems that i'm not being able to fix: How can i transmit data to serial port using but the board itself and it's usb connection. From what i've read it's possible to send strings via DigiUSB to a serial monitor but without sucess. Using DigiCDC creats a virtual port and i can open ot without problems, but i am not able to read/write to it.
On the pc side the code must be written in C, and from what i have until now works fine with Arduino boards like the Nano.
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
#define BAUDRATE B9600
#define MODEMDEVICE "/dev/ttyS0"
#define _POSIX_SOURCE 1 /* POSIX compliant source */
#define FALSE 0
#define TRUE 1
volatile int STOP=FALSE;
main()
{
int fd,c, res;
struct termios oldtio,newtio;
char buf[255];
fd = open(MODEMDEVICE, O_RDWR | O_NOCTTY );
if (fd <0) {perror(MODEMDEVICE); exit(-1); }
tcgetattr(fd,&oldtio); /* save current port settings */
bzero(&newtio, sizeof(newtio));
newtio.c_cflag = BAUDRATE | CRTSCTS | CS8 | CLOCAL | CREAD;
newtio.c_iflag = IGNPAR;
newtio.c_oflag = 0;
/* set input mode (non-canonical, no echo,...) */
newtio.c_lflag = 0;
newtio.c_cc[VTIME] = 0; /* inter-character timer unused */
newtio.c_cc[VMIN] = 2; /* blocking read until 5 chars received */
tcflush(fd, TCIFLUSH);
tcsetattr(fd,TCSANOW,&newtio);
while (STOP==FALSE) { /* loop for input */
res = read(fd,buf,1); /* returns after 5 chars have been input */
buf[res]=0; /* so we can printf... */
printf("%s", buf);
if (buf[0]=='z') STOP=TRUE;
}
tcsetattr(fd,TCSANOW,&oldtio);
}
The code sets the port for non-canonnical mode and receives a string, stops when detects a 'z' unto the string.
I've already changed the Serial Port and even Baud rates but no data is ever read nor writen.
On the digispark side i derived from DigisparkExamples->DigiCDC->Echo and DigiUSB-> Echo, but only to read or write one experiment at a time.
Is there a way to read/write data to digispark? I was thinking maybe i can use SoftSerial and redirect the Tx and Rx pins to USB+ and USB-, but no sure if it will do the job.
I'm using Ubuntu btw.
Best Regards