Skip to content

Commit

Permalink
Merge pull request #1 from ivoknutsel/master
Browse files Browse the repository at this point in the history
Merging upstream PR #5 - Update README
  • Loading branch information
proffalken authored Nov 26, 2016
2 parents a299217 + 27a7cea commit b20c3d5
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 35 deletions.
23 changes: 13 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,19 @@ Dependencies

Connections
-----------
SX1272 - Raspberry

3.3V - 3.3V (header pin #1)
GND - GND (pin #6)
MISO - MISO (pin #21)
MOSI - MOSI (pin #19)
SCK - CLK (pin #23)
NSS - GPIO6 (pin #22)
DIO0 - GPIO7 (pin #7)
RST - GPIO0 (pin #11)

This lbrary uses wiringpi. **The pin names used in wiringpi are different from those in the official Pi documentation**

SX1272 | Wiring name | Pin number | signal | Direction
-------|-------------|------------|--------|-----------
3.3V | 3.3V | #1 | 3.3 Volt supply voltage form PI | Pi => SX1272
GND | GND | #6 | Ground | Pi => SX1272
MISO | MISO | #21 | Master In Slave Out | SX1272 => Pi
MOSI | MOSI | #19 | Master Out Slave In | Pi => SX1272
SCK | CLK | #23 | Serial Clock for SPI | Pi => SX1272
NSS | GPIO6 | #22 | Chip enable for SX1272 | Pi => SX1272
DIO0 | GPIO7 | #7 | signals an available packet | SX1272 => Pi
RST | GPIO0 | #11 | Chip reset for SX1272 | Pi => SX1272

Configuration
-------------
Expand Down
60 changes: 35 additions & 25 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ char message[256];
char b64[256];

bool sx1272 = true;
int maxMessages = 10;

byte receivedbytes;

Expand All @@ -63,9 +64,9 @@ enum sf_t { SF7=7, SF8, SF9, SF10, SF11, SF12 };
*******************************************************************************/

// SX1272 - Raspberry connections
int ssPin = 6;
int dio0 = 7;
int RST = 0;
int csPin = 6; // SX1272 nss on Pi GPIO1
int dio0Pin = 7; // SX1272 dio0 on Pi GPIO17
int rstPin = 0; // SX1272 rst on Pi GPIO0

// Set spreading factor (SF7 - SF12)
sf_t sf = SF7;
Expand All @@ -74,14 +75,14 @@ sf_t sf = SF7;
uint32_t freq = 868100000; // in Mhz! (868.1)

// Set location
float lat=0.0;
float lon=0.0;
int alt=0;
float lat=51.572101;
float lon=4.797998;
int alt=2;

/* Informal status fields */
static char platform[24] = "Single Channel Gateway"; /* platform definition */
static char email[40] = ""; /* used for contact email */
static char description[64] = ""; /* used for free form description */
static char email[40] = "[email protected]"; /* used for contact email */
static char description[64] = "Test of Pi and NiceRF module."; /* used for free form description */

// define servers
// TODO: use host names and dns
Expand Down Expand Up @@ -168,25 +169,25 @@ void die(const char *s)
exit(1);
}

void selectreceiver()
void enableCS()
{
digitalWrite(ssPin, LOW);
digitalWrite(csPin, LOW);
}

void unselectreceiver()
void disableCS()
{
digitalWrite(ssPin, HIGH);
digitalWrite(csPin, HIGH);
}

byte readRegister(byte addr)
{
unsigned char spibuf[2];

selectreceiver();
enableCS();
spibuf[0] = addr & 0x7F;
spibuf[1] = 0x00;
wiringPiSPIDataRW(CHANNEL, spibuf, 2);
unselectreceiver();
disableCS();

return spibuf[1];
}
Expand All @@ -197,10 +198,10 @@ void writeRegister(byte addr, byte value)

spibuf[0] = addr | 0x80;
spibuf[1] = value;
selectreceiver();
enableCS();
wiringPiSPIDataRW(CHANNEL, spibuf, 2);

unselectreceiver();
disableCS();
}


Expand Down Expand Up @@ -240,12 +241,19 @@ boolean receivePkt(char *payload)

void SetupLoRa()
{
printf("CS : %i.\n",csPin);
printf("DIO0 : %i.\n",dio0Pin);
printf("RST : %i.\n",rstPin);

digitalWrite(RST, HIGH);
printf("Startup.\n");

digitalWrite(rstPin, HIGH);
delay(100);
digitalWrite(RST, LOW);
digitalWrite(rstPin, LOW);
delay(100);

printf("Reset.\n");

byte version = readRegister(REG_VERSION);

if (version == 0x22) {
Expand All @@ -254,9 +262,9 @@ void SetupLoRa()
sx1272 = true;
} else {
// sx1276?
digitalWrite(RST, LOW);
digitalWrite(rstPin, LOW);
delay(100);
digitalWrite(RST, HIGH);
digitalWrite(rstPin, HIGH);
delay(100);
version = readRegister(REG_VERSION);
if (version == 0x12) {
Expand Down Expand Up @@ -381,9 +389,11 @@ void receivepacket() {
long int SNR;
int rssicorr;

if(digitalRead(dio0) == 1)
if(digitalRead(dio0Pin) == 1)
{
if(receivePkt(message)) {
if(receivePkt(message) && (maxMessages >0)) {
maxMessages--;

byte value = readRegister(REG_PKT_SNR_VALUE);
if( value & 0x80 ) // The SNR sign bit is 1
{
Expand Down Expand Up @@ -537,9 +547,9 @@ int main () {
uint32_t lasttime;

wiringPiSetup () ;
pinMode(ssPin, OUTPUT);
pinMode(dio0, INPUT);
pinMode(RST, OUTPUT);
pinMode(csPin, OUTPUT);
pinMode(dio0Pin, INPUT);
pinMode(rstPin, OUTPUT);

//int fd =
wiringPiSPISetup(CHANNEL, 500000);
Expand Down

0 comments on commit b20c3d5

Please sign in to comment.