Go Down

Topic: How do I get debugging output from a digiSpark ATTiny85? (Read 1 time) previous topic - next topic

Gahhhrrrlic

I read into this and tried the "keyboard" example, which basically prints characters to notepad and it works with literals like "hello world" but doesn't seem to work with actual data generated at runtime.  I'm using the fix_fft() method to generate a 64 element array of integers and trying to print a comma delimited output with each integer separated by a comma.  Running the Keyboard commands prints the commas but doesn't print the integers.  I've got my board's LED blinking synchronously with one of the data buckets so I'm pretty sure the FFT is working but I can't figure out how to print the output.

Question:  What is the simplest method to output integers to any sort of display, be it the console, notepad, or whatever?  Here's the code:


Code: [Select]
#include "fix_fft.h"
#include "DigiKeyboard.h"

char im[128];
char data[128];
byte factor;
byte a;

void setup() {
 
  pinMode(1, OUTPUT);
 
  }

void loop(){

  delay(factor);
  digitalWrite(1, !digitalRead(1));
  int static i = 0;
  static long tt;
  int val;
 
   if (millis() > tt){
if (i < 128){
  val = analogRead(5);
  data[i] = val / 4 - 128;
  im[i] = 0;
  i++; 
 
}
else{
  //this could be done with the fix_fftr function without the im array.
  fix_fft(data,im,7,0);
  // I am only interessted in the absolute value of the transformation
  for (i=0; i< 64;i++){
     data[i] = sqrt(data[i] * data[i] + im[i] * im[i]);
  }
 
  //do something with the data values 1..64 and ignore im
//   show_big_bars(data,0);
 

}

     factor = data[60];
     for(a=0; a<64; a++) {
     
      String tempy = String(data[a]);
      DigiKeyboard.print(tempy);
      DigiKeyboard.print(",");

    }

    DigiKeyboard.println("");
   
    tt = millis();
   }
}

mudmin

It's been a while, so don't slam me if I'm wrong, but I think the pin 0/1 on the attiny is also what's used for the serial communication so if you're using it for something else, you won't have serial.

I believe if you move pinMode(1, OUTPUT);  to Pin 5 or something Serial.println will work just like any other arduino.

Robin2

The Attiny85 does not have a UART so the digikey library must be using some form of SoftwareSerial.

@Gahhhrrrlic, you will need to study the code in the digikey library. And if you need help with that you need to post a link to where you got the library.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Gahhhrrrlic

It seems there are a few different available options but most of them have severe limitations.  The easiest one seems to be DigiCDC (https://digistump.com/wiki/digispark/tutorials/digicdc) however it says it requires half your RAM and while I'm already running an FFT algorithm, there is no RAM to spare.  I feel like the only way I'm going to be able to get any kind of feedback from the digi is to do something stupid and hackish like use PWM to flip an input on another arduino and then use some convoluted conversion table to interpret the frequency and what it means (ie. 10% DC = 1, 20% DC = 2, etc.).  Every normal solution I can think of (connecting an OLED for example), would require either too much program space or too much RAM, once I have the FFT running.

Robin2

Have a look at this Thread. IIRC I wrote it to use a minimum amount of SRAM. You can delete all the parts that are involved in Rx if you don't need them.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Gahhhrrrlic

Thank you.  This may be exactly what I need.  Will it handle numerical data as well as text?

Robin2

Thank you.  This may be exactly what I need.  Will it handle numerical data as well as text?
It's a long time since I wrote it so I can't remember.

The problem with a general function for converting numbers to text is that it is rather complex and RAM consuming.

Maybe you can confine yourself to numbers that fit in a single byte?

For another project I wrote some code to convert integers into a 2, 3 or 4 byte ascii code using 64 printable characters. The purpose was to reduce the number of bytes to send compared to sending a number as text while still working with printable characters. It had the side effect of being very much faster to decode than atoi(). However, while it only uses 64 printable characters to code the numbers the coded version would need to be converted before it makes sense as a number so it is probably not much use as a debugging aid.

...R
Two or three hours spent thinking and reading documentation solves most programming problems.

Gahhhrrrlic

Well in this case, the FFT generates byte sized integers so I think they could easily be masked as another data type such as char.  The highest value the bin can take (I think) is 128.

Go Up