Got my new receivers. After a few extremely frustrating evenings, I've got the basics working....
I send it like this:
var txpin=A1;
function sendTest2() {
for (i = 0; i < 20; i++) { //20ms long training burst. Had crap results with shorter ones.
digitalPulse(txpin,1,0.5);
digitalPulse(txpin,0,0.5);
}
digitalPulse(txpin,1,0.5); //end training burst
digitalPulse(txpin,0,2); //sync
digitalPulse(txpin,1,0.7); //send a 0
digitalPulse(txpin,0,0.5); //pause
digitalPulse(txpin,1,1.3); //send a 1
digitalPulse(txpin,0,0.5); //pause
digitalPulse(txpin,1,0.7); //send a 0
digitalPulse(txpin,0,0.5); //pause
digitalPulse(txpin,1,1.3); //send a 1
digitalPulse(txpin,0,0.5); //pause
digitalPulse(txpin,1,1.3); //send a 1
digitalPulse(txpin,0,0.5); //pause
digitalPulse(txpin,1,0.7); //send a 0
digitalPulse(txpin,0,0.5); //pause
digitalPulse(txpin,1,1.3); //send a 1
digitalPulse(txpin,0,0.5); //pause
digitalPulse(txpin,1,1.3); //send a 1
digitalPulse(txpin,0,0.5); //pause
digitalPulse(txpin,0,0);
digitalWrite(txpin,0);
}
[#define](https://forum.espruino.com/search/?q=%23define) ListenST 1
[#define](https://forum.espruino.com/search/?q=%23define) rxpin 19
int lastPinState;
unsigned long lastPinHighTime;
unsigned long lastPinLowTime;;
unsigned long lastTempHighTime=0;
unsigned long lastTempLowTime=0;
unsigned long rxdata;
int lastTempPinState;
int bitsrx;
int rxing;
int MyState;
unsigned long curTime;
void setup() {
lastPinState=0;
lastPinLowTime=0;
lastPinHighTime=0;
rxdata=0;
bitsrx=0;
rxing=0;
MyState=2;
Serial.begin(9600);
}
void loop() {
curTime=micros();
onListenST();
}
void onListenST() {
int pinState=digitalRead(rxpin);
if (pinState==lastPinState) {
return;
} else {
lastPinState=pinState;
}
if (pinState==0) {
lastPinLowTime=curTime;
unsigned long bitlength=lastPinLowTime-lastPinHighTime;
//Serial.println("bitlength:");
if (bitlength < 1400 && bitlength > 600) {
//Serial.println(bitlength);
}
if (bitlength > 1500) {
//bogus bit
// Serial.println(bitlength);
resetListen();
return;
} else if (rxing==1) {
//Serial.print("Receiving");
// Serial.println(bitlength);
if (bitlength > 575 && bitlength < 750) {
rxdata=rxdata<<1;
Serial.print("F");
Serial.println(bitlength);
} else if (bitlength > 1200 && bitlength < 1350 ) {
rxdata=(rxdata<<1)+1;
Serial.print("T");
Serial.println(bitlength);
} else {
//Serial.println(bitlength);
resetListen();
return;
}
bitsrx++;
if (bitsrx==8) {
Serial.println("Got 8 bits");
Serial.println(rxdata);
resetListen();
}
return;
}
} else {
lastPinHighTime=curTime;
if (lastPinHighTime-lastPinLowTime > 1900 && lastPinHighTime-lastPinLowTime <2100) {
//Serial.println("Starting");
rxing=1;
return;
}
if (lastPinHighTime-lastPinLowTime > 700 && rxing==1) {
//Serial.print("oddly long delay during rx");
//Serial.println(lastPinHighTime-lastPinLowTime);
resetListen();
return;
}
}
}
void resetListen() {
//Serial.print("end");
bitsrx=0;
rxdata=0;
rxing=0;
}
Obviously, I need to do some work on both ends.
Do you have any thoughts on how to improve the Espruino side, while making sure that the code executes fast enough?
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Got my new receivers. After a few extremely frustrating evenings, I've got the basics working....
I send it like this:
Obviously, I need to do some work on both ends.
Do you have any thoughts on how to improve the Espruino side, while making sure that the code executes fast enough?