Decoding ASCII binary over serial

I've brought it up to 300baud with no problem. I still get the same pattern of pulses.

However, I wonder what makes you so sure, Grumpy_Mike that transmitting via serial pin like this is a bad idea? Earlier in this project I have used a fast-fourier transform to accomplish the same task, but the power needed is just too much and too slow. Below is a new image, at 300baud.

Transmitting 'h'

Can anyone really look at that and say I'm not getting a binary signal?

The audio is being captured at 44100hz. At 300baud, a bit comes out to about 147 samples. Each one of the bit above the spikes in the audio is the result of the amplitude of the signal passing a threshold (the horizontal line through the middle)

I'm not sure I understand about only seeing edges either. The serial pin seems to be outputting using PWM like all the others. I'm not sure of the frequency, but it's in the audible range. Each bit consists of a multitude of wavepeaks.

So, I conclude that I must be the failwhale of the day. However, I can't seem to see what's wrong with all of this.

It's not kosher, this being an Arduino forum :slight_smile: but here is the code for Processing if anyone is curious to try it out. It requires the minim audio library.

import ddf.minim.analysis.*;
import ddf.minim.*;
//import ddf.minim.effects.*;


Minim minim;
AudioInput in;
AudioRecorder recorder;
//FFT fft;

int langth = 0;
int[] Sample = new int[300];
int showBar = 0;
int sampleSize = 16384; //16384
float[] samples;
float thresh = 48;
int crossed = 0;
float sampleRate;
int [] rxString = new int[0];

//at 44111, 300baud on the arduino should be every 147 samples but actually seems to read best at about 98% speed, 144.06.
//300baud = 144.06
//400baud = 111
//275baud = 158.9
//1200baud = 36.75

void setup()
{
  size(1110, 256);
  
  minim = new Minim(this);
  
  in = minim.getLineIn(Minim.STEREO, sampleSize);
  sampleRate = in.sampleRate();

  
  // create an FFT object that has a time-domain buffer 
  // the same size as jingle's sample buffer
  // note that this needs to be a power of two 
  // and that it means the size of the spectrum
  // will be 512. see the online tutorial for more info.
  //  fft = new FFT(in.bufferSize(), sampleRate);
  //  lpf = new LowPassFS(500 , in.sampleRate());
  //in.addEffect(lpf);
  //in.linAverages(128);

}

void draw()
{
  int readRX = 0;
  background(51);
  noFill();
  beginShape();
  //draw line to show where thresh is
  stroke(255);
  line(0, height - thresh*4, width, height - thresh*4);
  // perform a forward FFT on the samples in jingle's left buffer
  // note that if jingle were a MONO file, 
  // this would be the same as using jingle.right or jingle.left
  //  fft.forward(in.mix);
    // draw the line for frequency band i, scaling it by 300 so we can see it a bit better
    //15 = 5600hz
    //8 = 3000hz
    //line(0, height, 0, height - fft.getBand(15)*300);     

  samples = in.left.toArray();  //figure out where the first pulse is and read from there.
  for(int i = 0; i < samples.length; i++){
    if(samples[i]*50 > thresh){
    readRX = i-5;
    break;
    }
  }

  float lineNumber = (sampleSize/144.06-readRX/144.06);
  int mapped = int(map(readRX, 0, sampleSize, 0, width));
  line(mapped, 0, mapped, height);

  for(float p=readRX; p < samples.length;){
    float x = 0;
    for(float d = p+6; d < p + 144.06 && d < samples.length; d++){ 
      x = map(d, 0, in.bufferSize(), 0, width); 
      stroke(#14CAFA);
      vertex(x, height - samples[int(d)]*200);
  
      //Draw a line at each bit interval. At 300baud, about every 111 samples.
      //THIS SLOWS DOWN EVERYTHING! DEBUGGING ONLY
//      stroke(#9B4949);
//      for(int e = 0; e < lineNumber; e++){
//        float interval = mapped+width/(sampleSize/157.16)*e;
 //       line(interval, 0, interval, height); 
 //     }

      if(samples[int(d)-1]*50 < samples[int(d)]*50 && samples[int(d)-1]*50 < thresh && samples[int(d)]*50 >= thresh){
        crossed++;
      }
    }
      
    if(crossed >= 1){
      text(0, x-10, 50);
      rxString = append(rxString, 1);
    }
    else{
      text(1, x-10, 50);
      rxString = append(rxString, 0);
    }
        

        

                crossed = 0;
//println(rxString);
      p = p+144.06;
    }
    endShape();
        //String joinedrxString = join(nf(rxString, 0), "");
        //println(unbinary(joinedrxString));
        //println(joinedrxString);
}

void stop()
{
  // always close Minim audio classes when you finish with them
  in.close();
  minim.stop();
  
  super.stop();
}