Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compatibility with Arduino nano 33 IoT #53

Open
zygisjas opened this issue Mar 16, 2021 · 5 comments
Open

Compatibility with Arduino nano 33 IoT #53

zygisjas opened this issue Mar 16, 2021 · 5 comments
Milestone

Comments

@zygisjas
Copy link

zygisjas commented Mar 16, 2021

I was trying to connect PZEM004 to Arduino nano 33 IoT board, and this library is using SofwareSerial.h,
I tried to dig deeper, and Nano 33 IoT does not use SoftwareSerial anymore, so I'm not sure how to make
PZEM004 compatible with Nano 33 IoT board, could not find anything in the internet about this issue.
Maybe someone has an idea how to solve this?

This is from arduino official site:

Serial ports on the Arduino NANO 33 IoT

The USB connector of the board is directly connected to the USB host pins of the SAMD21. This routing enables you to use the Arduino NANO 33 IoT as a client USB peripheral (acting as a mouse or a keyboard connected to the computer) or as a USB host device so that devices like a mouse, keyboard, or an Android phone can be connected to the Arduino NANO 33 IoT. This port can also be used as a virtual serial port using the Serial object in the Arduino programming language. The RX0 and TX1 pins are a second serial port available as Serial1

So I've tried to simply write the code like this:

#include <PZEM004Tv30.h>

PZEM004Tv30 pzem(Serial1);

void setup() {
  Serial.begin(115200);

  Serial.print("Reset Energy");
  pzem.resetEnergy();


  Serial.print("Set address to 0x42");
  pzem.setAddress(0x42);
}

void loop() {
  float volt = pzem.voltage();
  float cur = pzem.current();
  float powe = pzem.power();
  float ener = pzem.energy();
  float freq = pzem.frequency();
  float pf = pzem.pf();
  

  Serial.print(volt);
  Serial.print(" ");
  Serial.print(cur);
  Serial.print(" ");
  Serial.print(powe);
  Serial.print(" ");
  Serial.print(ener,3);
  Serial.print(" ");
  Serial.print(freq);
  Serial.print(" ");
  Serial.println(pf);

  delay(1000);
}

But getting error output in aruino IDE:

error: no matching function for call to 'PZEM004Tv30::PZEM004Tv30(Uart&)'

PZEM004Tv30 pzem(Serial1);

Documents\Arduino\libraries\PZEM-004T-v30/PZEM004Tv30.h:65:5: note: candidate: PZEM004Tv30::PZEM004Tv30(arduino::HardwareSerial*, uint8_t)

PZEM004Tv30(HardwareSerial* port, uint8_t addr=PZEM_DEFAULT_ADDR);

^~~~~~~~~~~

Documents\Arduino\libraries\PZEM-004T-v30/PZEM004Tv30.h:59:7: note: candidate: constexpr PZEM004Tv30::PZEM004Tv30(const PZEM004Tv30&)

class PZEM004Tv30

^~~~~~~~~~~

exit status 1
no matching function for call to 'PZEM004Tv30::PZEM004Tv30(Uart&)'

@sergiocntr
Copy link

sergiocntr commented Mar 16, 2021 via email

@zygisjas
Copy link
Author

zygisjas commented Mar 16, 2021

It was complaining about the Usb Serial conflict in the CPP file, I commented line 54 in CPP.

#define UPDATE_TIME     200

#define RESPONSE_SIZE 32
#define READ_TIMEOUT 100

#define PZEM_BAUD_RATE 9600

**//extern HardwareSerial Serial;**



#define DEBUG

// Debugging function;
void printBuf(uint8_t* buffer, uint16_t len){

And passing Serial to PZEM by using this line:

PZEM004Tv30 pzem(&Serial1);

Now code compiles with no problem, but... when I install this code to Arduino nano 33 IoT, the board simply crashes, and I need to
do hard reset. Still no luck.

Update:

If I don't comment HardwareSerial Serial I get this error now:

from C:\Users\Zygimantas Jasiunas\Documents\Arduino\libraries\PZEM-004T-v30\PZEM004Tv30.h:41,

                 from C:\Users\Zygimantas Jasiunas\Documents\Arduino\libraries\PZEM-004T-v30\PZEM004Tv30.cpp:23:

C:\Users\Zygimantas Jasiunas\AppData\Local\Arduino15\packages\arduino\hardware\samd\1.8.11\variants\nano_33_iot/variant.h:240:37: error: conflicting declaration 'arduino::HardwareSerial SerialUSB'

 #define Serial                      SerialUSB

@zygisjas
Copy link
Author

zygisjas commented Mar 17, 2021

Update:

I followed suggestions of this thread: #43
And seems that Arduino Nano 33 IoT started to communicate with PZEM, but I still not getting any output

Any advice how could I debug it?

@mandulaj mandulaj added this to the Release 1.2.0 milestone Jul 16, 2021
@mandulaj
Copy link
Owner

Unfortunately I don't have a Nano 33 IoT. Could you try with the new version v1.1.1 of the library to see if you still face the same issues.

@robertoperuzzo
Copy link

robertoperuzzo commented Dec 12, 2022

For anyone using the same processor's family (Cortex-M0 32-bit SAMD21) the library PZEM-004T-V30-SAMD21 works. I tested with MKR WAN 1310.

Thanks to @zygisjas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants