Marvin

From Noisebridge Wiki
Jump to navigation Jump to search

See also: MTCDT (Ethernet/LoRa gateway)

Some kind of LoRa device http://www.rdmmakerspace.nl/Marvin/

Source code here: https://github.com/iotacademy/marvin

The device is a bare PCB with a USB on one end. Plugging this in to a computer shows up as a Arduino Leonardo and can be reprogrammed as such from the Arduino IDE. There is also a micro usb connection presumably duplicating the male PCB connector.


Docs[edit]

Note that this version varies from original kickstarter project, it uses the Microchip RN2903 at 915 Mhz for US.

Datasheet: http://www.microchip.com/mymicrochip/filehandler.aspx?ddocname=en578921 (available from digikey and others for < $15)

Command Refernce: http://ww1.microchip.com/downloads/en/DeviceDoc/40001811A.pdf


Pics[edit]

File:Marvin-PCB.jpg

File:Marvin-PCB-Back.jpg


Commands[edit]

sys[edit]

System commands for general module configuration

sys sleep MILLIS
sys reset
sys eraseFW
sys factoryRESET

sys set nvm ADDRESS DATA
sys set pindig PIN_NAME PIN_STATE 
sys set pinmode PIN_NAME PIN_MODE

sys get ver
sys get nvm ADDRESS
sys get vdd
sys get hweui
sys get pindig PIN_NAME
sys get pinana PIN_NAME
  • PIN_NAME == GPIO0-GPIO13, UART_CTS, UART_RTS, TEST0, TEST1
  • PIN_STATE == 1 or 0
  • PIN_MODE == digout, digin, ana
    • GPIO0-GPIO3 & GPIO5-GPIO13 can be set to analog (ana)
    • Pins default to output mode, driven low


mac[edit]

MAC physical network interface layer

mac reset
mac tx TYPE PORT_NO DATA
mac join MODE
mac save
mac forceENABLE
mac pause
mac resume

mac set devaddr ADDRESS
mac set deveui DEV_EUI
mac set appeui APP_EUI
mac set nwkskey NETWORK_SESSION_KEY
mac set appskey APP_SESSION_KEY
mac set appkey APP_KEY
mac set pwridx POWER_INDEX
mac set dr DATA_RATE
mac set adr ADAPTIVE_DATA_RATE
mac set bat BATTERY_LEVEL
mac set retx RETRANSMISSION_NUMBER
mac set linkchk LINK_CHECK_INTERVAL
mac set rxdelay1 RX_DELAY
mac set ar AUTOMATIC_REPLY
mac set rx2 DATA_RATE FREQUENCY
mac set sync SYNC_WORD
mac set upctr UP_LINK_COUNTER
mac set dnctr DOWN_LINK_COUNTER
mac set ch drrange CHANNEL_ID MIN_RANGE MAX_RANGE
mac set ch status CHANNEL_ID STATUS

mac get devaddr
mac get deveui
mac get appeui
mac get dr
mac get pwridx
mac get adr
mac get retx
mac get rxdelay1
mac get rxdelay2
mac get ar
mac get rx2
mac get dcycleps
mac get mrgn
mac get gwnb
mac get status
mac get sync
mac get upctr
mac get dnctr
mac get ch

POWER_INDEX == 5, 7, 8, 9, 10


radio[edit]

Radio specific control such as frequency and power levels.

radio rx RX_WINDOW_SIZE
radio tx DATA
radio cw CW_STATE

radio set mod lora
radio set freq FREQUENCY
radio set pwr OUTPUT_POWER
radio set sf SPREADING_FACTOR
radio set crc CRC_HEADER
radio set iqi IQ_INVERT
radio set cr CODING_RATE
radio set wdt WATCH_DOG_TIMER
radio set sync SYNC_WORD
radio set bw BANDWIDTH

radio get mod
radio get freq
radio get pwr
radio get sf
radio get crc
radio get iqi
radio get cr
radio get wdt
radio get sync
radio get bw
radio set snr 


Sketch[edit]

This is a basic sketch that allows for interaction over serial sys ver for example returns the firmware version. Connection can be made using arduino serial monitor or any serial terminal program with configuration set to 57,600bps 8N1, all messages must end with <CR> + <LF>.

/*

  Marvin Hello

    VER: RN2903 0.9.8 Feb 14 2017 20:17:03

*/

// LoRa module params
const int RESET_PORT = 5;
const int POWER_PORT = 6;

int sensorPin = A3;    // select the input pin for the potentiometer
int pirPin = 4;
int ledA = 13;      // select the pin for the LED
int ledB = 11;
int sensorValue = 0;  // variable to store the value coming from the sensor

unsigned long lastTime = 0;
unsigned long nextTime = 1;

void setup() {
  pinMode(ledA, OUTPUT);
  pinMode(ledB, OUTPUT);
  pinMode(pirPin, INPUT);

  // Virtual Serial thru USB connection
  Serial.begin(57600);
  // Leonardo UART to RN2903A module
  Serial1.begin(57600);
  // wait to init
  while (!Serial) {
    // twiddle thumbs here
  }

  // Enable power to the RN2483
  pinMode(POWER_PORT, OUTPUT);
  digitalWrite(POWER_PORT, HIGH);
  
  Serial.println(">> Powering Module");
  delay(1000);

  // Disable reset pin
  pinMode(RESET_PORT, OUTPUT);
  digitalWrite(RESET_PORT, HIGH);
}

void loop() {
  static bool blinkOn = false;

  // proxy data between USB/Serial & Module/Serial
  if (Serial1.available() > 0)
    Serial.write(Serial1.read());
  if (Serial.available() > 0)
    Serial1.write(Serial.read());

  // Turn on LED when there's motion
  digitalWrite(ledB, !digitalRead(pirPin));
  
  // Serial.println(sensorValue);

  if (millis() >= nextTime) {
    // read the value from the sensor:
    sensorValue = analogRead(sensorPin);
    nextTime = millis() + sensorValue;
    if (!blinkOn) {
      digitalWrite(ledA, LOW);
      //analogWrite(ledA, int(sensorValue / 4));
    } else {
      // analogWrite(ledA, 0);
      digitalWrite(ledA, HIGH);
    }
    blinkOn = !blinkOn;
    lastTime = millis();
  }

  delay(20);
}