adafruit metro m4 with arduino serial com with HC-12

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
aapplem1
 
Posts: 1
Joined: Fri Apr 29, 2022 5:00 pm

adafruit metro m4 with arduino serial com with HC-12

Post by aapplem1 »

I am attempting to make two HC-12s and two Adafruit metro boards, connected to a spark fun MicroOLED. communicate with each other. I am having an issue with Arduino compiling the sketch to Adafruit SAMD 51. this only one side of the code, for the first metro with the OLED.

Code: Select all

#include <Wire.h>
#include <SFE_MicroOLED.h> 
Uart Serial1( &sercom0, PIN_SERIAL1_RX, PIN_SERIAL1_TX, PAD_SERIAL1_RX, PAD_SERIAL1_TX ) ;
 

#define B0 2
#define B1 3
#define PIN_RESET A4
#define DC_JUMPER A5
MicroOLED oled(PIN_RESET,DC_JUMPER);


float temp = 0;

byte RX[4];
unsigned long interval =0;

void setup()
{
pinMode(B0,INPUT);
pinMode(B1,INPUT);
Serial.begin(9600);


oled.begin();
}

void loop()
{
if(!digitalRead(B0))
{
// Serial.println("B0 pressure ");
// Serial.print('1');
Serial.print('1');
while(digitalRead(B0)==0);
}
if(!digitalRead(B1))
{
Serial.print('2');
while(digitalRead(B1)==0);
}
if(millis() - interval >=3000)
{
interval = millis();
MicroOLED clear();
for(int i=0; i<4;i++)
{
RX[i]=0;
}

{
for(int i=0; i<4;i++)


temp =((RX[0]*256) +RX[1])/100.0;
if(temp<0 ||temp >100)
{
Serial.print("Error no sensor ");
oled.setCursor(0,0);
oled.print("TEMP: ");
oled.setCursor(6,0);
oled.print("-");
oled.setCursor(12,0);
oled.setCursor(0,1);
}
else
{
Serial.print("Temperature : ");
Serial.print( temp );
Serial.println(" *C");
oled.setCursor(0,0);
oled.print("TEMP: ");
oled.setCursor(6,0);
oled.print(temp);
oled.setCursor(12,0);
oled.print("*C");
oled.setCursor(0,1);

}
}
}
}

User avatar
blnkjns
 
Posts: 963
Joined: Fri Oct 02, 2020 3:33 am

Re: adafruit metro m4 with arduino serial com with HC-12

Post by blnkjns »

What do you want this sentence to do:

Code: Select all

Uart Serial1( &sercom0, PIN_SERIAL1_RX, PIN_SERIAL1_TX, PAD_SERIAL1_RX, PAD_SERIAL1_TX ) ;
The Metro has 2 hardware serials by default, Serial works on the USB port, Serial1 on pin 0 and 1 for the HC-12. No idea why you do this complicated Serial setup.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”