TinyScreen+ coupled with 433MHZ Radio (Setup)

kourosh

  • Newbie
  • *
    • Posts: 1
    • View Profile
I'm using the following shields in my project:

1.TINYSCREEN+ (PROCESSOR, OLED & USB IN ONE)

2.433MHZ LONG RANGE RADIO TINYSHIELD

And here's my code (very simple):

Code: [Select]
#include <Wire.h>
#include <SPI.h>
#include <TinyScreen.h>
#include "RH_RF22.h"

TinyScreen display = TinyScreen(TinyScreenPlus);
RH_RF22 rf22(7,3);

void setup() {
  display.begin();
  display.setBrightness(10);

  SerialUSB.begin(9600);

  if(rf22.init())
  {
   SerialUSB.println("Radio Set");
  } else {
   SerialUSB.println("Radio Failed");
  }
}

The same code if I use it with TinyDuino processor works fine (for TinyDuino processor I use Serial instead of SerialUSB)

However when I use TinyScreen+ I never get the return value of "
Code: [Select]
rf22.init()"

It seems like the process gets stuck when it reaches
Code: [Select]
rf22.init()
I am very new in this field and really looking forward to your help.

Thank you,
« Last Edit: May 08, 2018, 08:20:46 AM by kourosh »


thesko

  • Full Member
  • ***
    • Posts: 22
    • View Profile
I have the exact same problem! Nothing happens beyond rf22.init();

I have also tried the code from the football example:
https://tinycircuits.com/blogs/learn/121634375-football-play-calling-watch-tutorial

But here the lockup also happens on manager.init()

EDIT:
This also happens with all TinyScreen code removed (even the include), so I assume a hardware/pin issue?

@Ben: Any idea what is going on? Is the LORA board incompatible with the TinyScreen+?
If so, I have wasted money on those chips that instead I could have put into alternatives :(((


EDIT2:
Ok I have no clue what changed over night, but today the same code just works....  :o
Here is the Example I'm using for the TinyScreen+

Important: I'm using the latest version of RadioHead available on their site!

Code: [Select]
#include <Wire.h>
#include <SPI.h>
#include <RHReliableDatagram.h>
#include <RH_RF22.h>

//#define NOSCREEN

#ifndef NOSCREEN
#include <TinyScreen.h>
TinyScreen display = TinyScreen(TinyScreenPlus);
#endif

//define the address
#define CLIENT_ADDRESS 1

bool started = false;

RH_RF22 driver(7,3);
// Class to manage message delivery and receipt, using the driver declared above
RHReliableDatagram manager(driver, CLIENT_ADDRESS);


// This function gets the battery VCC internally, you can checkout this link
// if you want to know more about how:
// http://atmel.force.com/support/articles/en_US/FAQ/ADC-example
float getVCC() {
  SYSCTRL->VREF.reg |= SYSCTRL_VREF_BGOUTEN;
  while (ADC->STATUS.bit.SYNCBUSY == 1);
  ADC->SAMPCTRL.bit.SAMPLEN = 0x1;
  while (ADC->STATUS.bit.SYNCBUSY == 1);
  ADC->INPUTCTRL.bit.MUXPOS = 0x19;         // Internal bandgap input
  while (ADC->STATUS.bit.SYNCBUSY == 1);
  ADC->CTRLA.bit.ENABLE = 0x01;             // Enable ADC
  while (ADC->STATUS.bit.SYNCBUSY == 1);
  ADC->SWTRIG.bit.START = 1;  // Start conversion
  ADC->INTFLAG.bit.RESRDY = 1;  // Clear the Data Ready flag
  while (ADC->STATUS.bit.SYNCBUSY == 1);
  ADC->SWTRIG.bit.START = 1;  // Start the conversion again to throw out first value
  while ( ADC->INTFLAG.bit.RESRDY == 0 );   // Waiting for conversion to complete
  uint32_t valueRead = ADC->RESULT.reg;
  while (ADC->STATUS.bit.SYNCBUSY == 1);
  ADC->CTRLA.bit.ENABLE = 0x00;             // Disable ADC
  while (ADC->STATUS.bit.SYNCBUSY == 1);
  SYSCTRL->VREF.reg &= ~SYSCTRL_VREF_BGOUTEN;
  float vcc = (1.1 * 1023.0) / valueRead;
  return vcc;
}

// Calculate the battery voltage
float getBattVoltage(void) {
  const int VBATTpin = A4;
  float VCC = getVCC();

  // Use resistor division and math to get the voltage
  float resistorDiv = 0.5;
  float ADCres = 1023.0;
  float battVoltageReading = analogRead(VBATTpin);
  battVoltageReading = analogRead(VBATTpin); // Throw out first value
  float battVoltage = VCC * battVoltageReading / ADCres / resistorDiv;

  return battVoltage;
}

void setup()
{
  Wire.begin();
  SerialUSB.begin(9600);
  // give 5 sec to connect the serial monitor
  delay(5000);
 
#ifndef NOSCREEN
  display.begin();
  display.setFlip(true);
  display.setBrightness(15);
  display.clearScreen();
  display.setFont(thinPixel7_10ptFontInfo);
 
  display.fontColor(TS_8b_White, TS_16b_Black);
  display.setCursor(0, 0);
  display.print("TinyLORA starting..");
#endif 
  SerialUSB.println("starting rf22..");
  started = manager.init();
  if (started)
  {
#ifndef NOSCREEN
    display.setCursor(0, 10);
    display.print("TinyLORA started.");
#endif
    SerialUSB.println("..started.");
    delay(2000);
    display.clearScreen();
  }
  else
  {
#ifndef NOSCREEN
    display.setCursor(0, 10);
    display.print("init() failed!");
#endif
    SerialUSB.println("init() failed!");
  }
}

void loop()
{
  if (!started) return;
   
  uint8_t buf[RH_RF22_MAX_MESSAGE_LEN];
  // Send a message to manager_server2
  #define SERVER_ADDRESS 2
  uint8_t len = sizeof(buf);

#ifndef NOSCREEN
  display.fontColor(TS_8b_White, TS_16b_Black);
  display.setCursor(0, 0);
  display.print("Sending:");
  display.setCursor(0, 10);
#endif
 
  uint8_t data[2];
  int voltage = getBattVoltage() * 100;
#ifndef NOSCREEN
  display.print(voltage);
#endif
  data[0]=voltage>>8;
  data[1]=voltage;
  if (manager.sendtoWait(data, sizeof(data), SERVER_ADDRESS))
  {
    uint8_t from;
    //check if we received a reply
    if (manager.recvfromAckTimeout(buf, &len, 2000, &from))
    {
      SerialUSB.print("got reply from : 0x");
      SerialUSB.print(from, HEX);
      SerialUSB.print(": ");
      SerialUSB.println((char*)buf);
#ifndef NOSCREEN
      display.setCursor(0, 20);
      display.print("Received:");
      display.setCursor(0, 30);
      display.print((char*)buf);
#endif
    }
  }
  delay(10);
}
« Last Edit: July 01, 2018, 05:59:53 AM by thesko »


 

SMF spam blocked by CleanTalk