Continuing to work on an FSK audio link between an analog sampling board and an Android phone this week.

Making another FSKsampler_v1 board since my previous one got stepped on over thanksgiving

Running code just on regular Arduino for now to test the android decoding.

The clock was off by 4x when I used the actual arduino, i.e., the pulses are coming 4x slower than they should. The arduino is a 16 MHz clock speed

Currently the phone is listening to the external mic, not the headphone jack, unfortunately.

Need something like this

See this picture for the correct connection pattern:

Looks like my 3 terminal connector does work for the computer's dedicated mic input but not for the android or iphone bi-directional jack

At least Audacity on the computer is able to see the FSK through the mic port:
Simplest thing to do here for now is just to modify AndroinoTerm to the minimum extent consistent with working as a sampler and then go from there.

Just going to do this trivially with an arduino, speaker and potentiometer, and the microphone input of the android -- for the final I will work out the bi-directional communication through the audio jack itself.

I also aim to plot out the decoded values using the graphview library.

Starting with just modifying the arduino side of the AndroinoTerm setup to be a sampler, too.

Got arduino to output character representation of sampled analog integers as FSK. But so far AndroinoTerm is not able to decode it on the Android: possibly the sound is still too noisy / not loud enough.


* Copyright (C) 2011 Androino authors
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* See the License for the specific language governing permissions and
* limitations under the License.

/* Modified by Adam Marblestone on 2012-12-04 */


#define PARITY_EVEN 64
#define PARITY_ODD 32

int sensor1 = A0;
int FSKpin = 0;

int lastMessageSent = -1;
long lastMessageTime = -1;
boolean lastMessageAckReceived = true;
int x;
char c;
String stringToSend;

SoftModem modem; //create an instance of SoftModem

void setup ()
pinMode(sensor1, INPUT);
pinMode(FSKpin, OUTPUT);
modem.begin (); // setup () call to begin with

void loop ()
// grab integer sample
x = analogRead(sensor1);

// convert integer sample to a series of characters followed by a newline
stringToSend = String(String(x) + "\r\n");
int i;
for(i = 0; i < stringToSend.length(); i++){
c = stringToSend[i];
// write this character over FSK
// sendMessage(c-48, false); // 48=0, 49=1


void sendMessage(int number, boolean persistent){
// encodes and sends the message to the modem
// number must [0,16]
int msg = encodeMessage(number);

int encodeMessage(int number){
// adds the checksum
// Example: 3 (000.00011) => (101.00011)
int cSum = checkSum(number);
int msg = number + cSum;
Serial.print(" encodeMessage:number="); Serial.print(number, DEC); Serial.print(":"); Serial.println(number, BIN);
Serial.print(" encodeMessage:chk="); Serial.print(cSum, DEC); Serial.print(":"); Serial.println(cSum, BIN);
Serial.print(" encodeMessage:message="); Serial.print(msg, DEC); Serial.print(":"); Serial.println(msg, BIN);
return msg;

int checkSum(int number){
// calculates the checkSum for error correction
// simple implementation even => 010, odd =>001
int sign = 1;
for (int i=0; i < 5; i++){
int b = bitRead(number, i);
if (b==1){
sign = sign * (-1);
if (sign>0)
return PARITY_ODD;