Last active
February 24, 2018 19:10
-
-
Save Mictronics/e959ce730838c4e1893cfc7602a925cd to your computer and use it in GitHub Desktop.
Log SPI bus from LCD of a Sndway SW-A40 laser distance meter.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Log SPI bus from LCD of a Sndway SW-A40 laser distance meter. | |
* | |
* Developed and tested on Arduino Mini 328P@16MHz. | |
* Requires circular buffer library from https://github.com/rlogiacco/CircularBuffer | |
* See https://www.mictronics.de/2018/02/laser-distance-meter-hack/ | |
* Mictronics 2018 @ www.mictronics.de | |
*/ | |
#include <CircularBuffer.h> | |
/** | |
* Pin connection to LCD SPI bus. | |
*/ | |
const byte clkPin = 2; // LCD clock signal = IO2 | |
const byte dataPin = 4; // LCD data signal = IO4 | |
const byte csPin = 3; // LCD chip select signal = IO3 | |
byte data = 0; | |
byte bitcount = 8; | |
CircularBuffer<byte,210> frame; | |
void setup() { | |
Serial.begin(115200); | |
Serial.println("Sndway Rangefinder v1.0"); | |
pinMode(clkPin, INPUT); | |
pinMode(dataPin, INPUT); | |
pinMode(csPin, INPUT); | |
attachInterrupt(digitalPinToInterrupt(clkPin), readDataPin, RISING); | |
attachInterrupt(digitalPinToInterrupt(csPin), sendByte, RISING); | |
} | |
void loop() { | |
if(frame.isEmpty() == false){ | |
Serial.write(frame.shift()); | |
} | |
} | |
void readDataPin() { | |
if(digitalRead(csPin) == LOW) { | |
if(bitcount == 8) { | |
--bitcount; | |
return; | |
} | |
data |= (digitalRead(dataPin) << bitcount); | |
--bitcount; | |
} | |
} | |
void sendByte() { | |
frame.push(data); | |
data = 0; | |
bitcount = 8; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment