# How to Connect PM1200 to Arduino Mega 2560

**URL:** <https://forum.arduino.cc/t/how-to-connect-pm1200-to-arduino-mega-2560/1297970>\
**Category:** General Guidance\
**Created:** [September 3, 2024, 7:43am UTC](https://forum.arduino.cc/t/how-to-connect-pm1200-to-arduino-mega-2560/1297970 "2024-09-03T07:43:41Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![pesanurmawan](https://avatars.discourse-cdn.com/v4/letter/p/f04885/32.png) [@pesanurmawan](https://forum.arduino.cc/u/pesanurmawan)\
**Post date:** [September 3, 2024, 7:43am UTC](https://forum.arduino.cc/t/how-to-connect-pm1200-to-arduino-mega-2560/1297970/1 "2024-09-03T07:43:41Z")

</div>

Please help me. I’m trying to create a power meter data logger using an Arduino Mega 2560, but when I try, the values are always unreadable, and the connection always fails. I tried using Modbus Poll, and the connection works, and the values are readable, but when I try using the Mega 2560, the values are always unreadable.

Wiring diagram:

- VCC --\> Vin 5V Mega2560
- Tx --\> Pin 18 Tx1
- Rx --\> Pin 19 Rx1
- GND --\> GND Mega2560
- A+ --\> A(D1) PM1200
- B- --\> B(D0) PM1200

I am using an RS485 to TTL, Slave ID 1, Baud rate 9600, Parity Even.

```arduino
#include "SimpleModbusMaster.h"
/*
   The example will use packet1 to read a register from address 0 (the adc ch0 value)
   from the arduino slave (id=1). It will then use this value to adjust the brightness
   of an led on pin 9 using PWM.
   It will then use packet2 to write a register (its own adc ch0 value) to address 1
   on the arduino slave (id=1) adjusting the brightness of an led on pin 9 using PWM.
*/
//////////////////// Port information ///////////////////
#define baud 9600
#define timeout 1000
#define polling 200 // the scan rate
#define retry_count 10
// used to toggle the receive/transmit pin on the driver
#define TxEnablePin 0
#define LED 9
// The total amount of available memory on the master to store data
#define TOTAL_NO_OF_REGISTERS 2
// This is the easiest way to create new packets
// Add as many as you want. TOTAL_NO_OF_PACKETS
// is automatically updated.
enum
{
  PACKET1,
// PACKET2,
  TOTAL_NO_OF_PACKETS // leave this last entry
};
// Create an array of Packets to be configured
Packet packets[TOTAL_NO_OF_PACKETS];
// Masters register array
unsigned int regs[TOTAL_NO_OF_REGISTERS];
void setup()
{
  Serial.begin(9600);
  // Initialize each packet
  modbus_construct(&packets[PACKET1], 1, READ_HOLDING_REGISTERS, 3911, 2, 0);
// modbus_construct(&packets[PACKET2], 1, PRESET_MULTIPLE_REGISTERS, 1, 1, 0);
  // Initialize the Modbus Finite State Machine
  modbus_configure(&Serial1, baud, SERIAL_8E1, timeout, polling, retry_count, TxEnablePin, packets, TOTAL_NO_OF_PACKETS, regs);
  pinMode(LED, OUTPUT);
}
void loop()
{
  if (Serial.available()){
     int inByte =Serial1.read();
     Serial.write(inByte);
  }
  modbus_update();
  Serial.println("==================================");
  Serial.print("successful_requests \t : ");
  Serial.println(packets[PACKET1].successful_requests);
  Serial.print("failed_requests \t : ");
  Serial.println(packets[PACKET1].failed_requests);
  Serial.print("exception_errors \t : ");
  Serial.println(packets[PACKET1].exception_errors);
  Serial.print("connection \t\t : ");
  Serial.println(packets[PACKET1].connection);
  Serial.println("==================================");
  delay(1000);
  float A = *(float*)&regs[0]; Serial.print (" F : "); Serial.println (A);
  
}

```

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [September 3, 2024, 8:04am UTC](https://forum.arduino.cc/t/how-to-connect-pm1200-to-arduino-mega-2560/1297970/2 "2024-09-03T08:04:13Z")

</div>

Welcome to the forum

```arduino
Tx --> Pin 18 Tx1
Rx --> Pin 19 Rx1

```

Looks wrong.

Tx from one device would normally go to Rx of the second device for obvious reasons, but I am not familiar with whatever a PM1200 is

---

<div class="post-metadata">

**Author:** ![pesanurmawan](https://avatars.discourse-cdn.com/v4/letter/p/f04885/32.png) [@pesanurmawan](https://forum.arduino.cc/u/pesanurmawan)\
**Post date:** [September 3, 2024, 8:49am UTC](https://forum.arduino.cc/t/how-to-connect-pm1200-to-arduino-mega-2560/1297970/3 "2024-09-03T08:49:35Z")

</div>

I’ve already tried swapping Tx to Rx and Rx to Tx, but the result is still the same.

EasyLogic PM1200 schenider, PM1200/ Power Meter 1200

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [September 3, 2024, 8:54am UTC](https://forum.arduino.cc/t/how-to-connect-pm1200-to-arduino-mega-2560/1297970/4 "2024-09-03T08:54:07Z")

</div>

I see this in the data sheet for the PM2000

> Communication (PM1200)  
> RS-485 serial channel connection  
> Industry standard Modbus RTU protocol

Note that the Serial interface is RS-485, not TTL used by the Mega

Have you got any hardware converting from one to the other between the Mata and the PM1200 ?

---

<div class="post-metadata">

**Author:** ![pesanurmawan](https://avatars.discourse-cdn.com/v4/letter/p/f04885/32.png) [@pesanurmawan](https://forum.arduino.cc/u/pesanurmawan)\
**Post date:** [September 3, 2024, 8:58am UTC](https://forum.arduino.cc/t/how-to-connect-pm1200-to-arduino-mega-2560/1297970/5 "2024-09-03T08:58:09Z")

</div>

![image](https://europe1.discourse-cdn.com/arduino/original/4X/c/c/9/cc93a16305b494bc808ac2d3f37cc51fc34e362c.png)

I am using this hardware.

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [September 3, 2024, 9:00am UTC](https://forum.arduino.cc/t/how-to-connect-pm1200-to-arduino-mega-2560/1297970/6 "2024-09-03T09:00:14Z")

</div>

What is that a picture of and how is it connected to the two devices in your project ?

A schematic, even a photo of a hand drawn circuit, is good enough

---

<div class="post-metadata">

**Author:** ![pesanurmawan](https://avatars.discourse-cdn.com/v4/letter/p/f04885/32.png) [@pesanurmawan](https://forum.arduino.cc/u/pesanurmawan)\
**Post date:** [September 3, 2024, 9:17am UTC](https://forum.arduino.cc/t/how-to-connect-pm1200-to-arduino-mega-2560/1297970/7 "2024-09-03T09:17:51Z")

</div>

![image](https://europe1.discourse-cdn.com/arduino/original/4X/4/4/1/44134989335911d0f3fea6a271e0de90e038a28b.jpeg)

Wiring diagram:

- VCC --\> Vin 5V Mega2560
- Tx --\> Pin 18 Tx1
- Rx --\> Pin 19 Rx1
- GND --\> GND Mega2560
- A+ --\> A(D1) PM1200
- B- --\> B(D0) PM1200

---

<div class="post-metadata">

**Author:** ![pesanurmawan](https://avatars.discourse-cdn.com/v4/letter/p/f04885/32.png) [@pesanurmawan](https://forum.arduino.cc/u/pesanurmawan)\
**Post date:** [September 3, 2024, 9:20am UTC](https://forum.arduino.cc/t/how-to-connect-pm1200-to-arduino-mega-2560/1297970/8 "2024-09-03T09:20:01Z")

</div>

![image](https://europe1.discourse-cdn.com/arduino/original/4X/6/4/2/642338968a22fe678c12a86474bad76bbbbf8a00.jpeg)

I tried using Modscan, and it reads correctly.

---

<div class="post-metadata">

**Author:** ![pesanurmawan](https://avatars.discourse-cdn.com/v4/letter/p/f04885/32.png) [@pesanurmawan](https://forum.arduino.cc/u/pesanurmawan)\
**Post date:** [September 3, 2024, 9:23am UTC](https://forum.arduino.cc/t/how-to-connect-pm1200-to-arduino-mega-2560/1297970/9 "2024-09-03T09:23:15Z")

</div>

![image](https://europe1.discourse-cdn.com/arduino/original/4X/5/c/7/5c789dad80fc53ada650c2852419540a2a3589c8.png)

However, when I run it on the Arduino Mega, it doesn't work, and the connection is not established.

---

<div class="post-metadata">

**Author:** ![davidefa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/davidefa/32/1088935_2.png) [@davidefa](https://forum.arduino.cc/u/davidefa)\
**Post date:** [September 3, 2024, 9:37am UTC](https://forum.arduino.cc/t/how-to-connect-pm1200-to-arduino-mega-2560/1297970/10 "2024-09-03T09:37:48Z")

</div>

If you check in the modscan32 log ( show traffic option ) you will see that it will use address 3910.  
Arduino modbusmaster library, on the contrary, uses the exact address you set ( not sure if simplemodbusmaster does the same )

---

<div class="post-metadata">

**Author:** ![UKHeliBob](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/ukhelibob/32/215663_2.png) [@UKHeliBob](https://forum.arduino.cc/u/UKHeliBob)\
**Post date:** [September 3, 2024, 9:50am UTC](https://forum.arduino.cc/t/how-to-connect-pm1200-to-arduino-mega-2560/1297970/11 "2024-09-03T09:50:57Z")

</div>

```arduino
Tx --> Pin 18 Tx1
Rx --> Pin 19 Rx1

```

Still looks wrong to me

When the Arduino **transmits** the other device **receives** it. Hence Tx on the Arduino needs to connect to Rx on whatever is receiving it

---

<div class="post-metadata">

**Author:** ![jim-p](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jim-p/32/922840_2.png) [@jim-p](https://forum.arduino.cc/u/jim-p)\
**Post date:** [September 3, 2024, 10:01am UTC](https://forum.arduino.cc/t/how-to-connect-pm1200-to-arduino-mega-2560/1297970/12 "2024-09-03T10:01:23Z")

</div>

Your RS485 board does not have a TxEnablepin. The software needs that pin.

---

<div class="post-metadata">

**Author:** ![pesanurmawan](https://avatars.discourse-cdn.com/v4/letter/p/f04885/32.png) [@pesanurmawan](https://forum.arduino.cc/u/pesanurmawan)\
**Post date:** [September 3, 2024, 10:03am UTC](https://forum.arduino.cc/t/how-to-connect-pm1200-to-arduino-mega-2560/1297970/13 "2024-09-03T10:03:58Z")

</div>

> [@UKHeliBob](#):
>
> Still looks wrong to me
> 
> When the Arduino **transmits** the other device **receives** it. Hence Tx on the Arduino needs to connect to Rx on whatever is receiving it

I’ve already swapped Tx to Rx or Rx to Tx, but it’s the same.

---

<div class="post-metadata">

**Author:** ![pesanurmawan](https://avatars.discourse-cdn.com/v4/letter/p/f04885/32.png) [@pesanurmawan](https://forum.arduino.cc/u/pesanurmawan)\
**Post date:** [September 3, 2024, 10:08am UTC](https://forum.arduino.cc/t/how-to-connect-pm1200-to-arduino-mega-2560/1297970/14 "2024-09-03T10:08:36Z")

</div>

TxEnablepin in my software 0

---

<div class="post-metadata">

**Author:** ![jim-p](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jim-p/32/922840_2.png) [@jim-p](https://forum.arduino.cc/u/jim-p)\
**Post date:** [September 3, 2024, 10:10am UTC](https://forum.arduino.cc/t/how-to-connect-pm1200-to-arduino-mega-2560/1297970/15 "2024-09-03T10:10:06Z")

</div>

Do you have pin 0 connected to the enable pin on your RS485 board?

---

<div class="post-metadata">

**Author:** ![pesanurmawan](https://avatars.discourse-cdn.com/v4/letter/p/f04885/32.png) [@pesanurmawan](https://forum.arduino.cc/u/pesanurmawan)\
**Post date:** [September 3, 2024, 10:15am UTC](https://forum.arduino.cc/t/how-to-connect-pm1200-to-arduino-mega-2560/1297970/16 "2024-09-03T10:15:38Z")

</div>

I’m not connecting it to pin 0 on the RS485. Could you please check my code above?

---

<div class="post-metadata">

**Author:** ![davidefa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/davidefa/32/1088935_2.png) [@davidefa](https://forum.arduino.cc/u/davidefa)\
**Post date:** [September 3, 2024, 10:17am UTC](https://forum.arduino.cc/t/how-to-connect-pm1200-to-arduino-mega-2560/1297970/17 "2024-09-03T10:17:35Z")

</div>

The enable pin is not strictly needed these board generate it on the fly ( the board is always in rx, and switch to tx only when requested, after a short delay reverts to rx ).  
From the [image on the back](https://www.aliexpress.com/item/1005006440363797.html) of the board the tx pin is 'from tx' and the rx is 'to rx' so your connection is ok  
Regarding the library I used modbusmaster so can't help on this but check the 'address-1' as explained above

---

<div class="post-metadata">

**Author:** ![jim-p](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/jim-p/32/922840_2.png) [@jim-p](https://forum.arduino.cc/u/jim-p)\
**Post date:** [September 3, 2024, 10:17am UTC](https://forum.arduino.cc/t/how-to-connect-pm1200-to-arduino-mega-2560/1297970/18 "2024-09-03T10:17:56Z")

</div>

```arduino
#define TxEnablePin 0

```

set to pin 2  
connect pin 2 to the TxEnable pin on your RS485 board but your board does not have a Txenable pin

---

<div class="post-metadata">

**Author:** ![pesanurmawan](https://avatars.discourse-cdn.com/v4/letter/p/f04885/32.png) [@pesanurmawan](https://forum.arduino.cc/u/pesanurmawan)\
**Post date:** [September 3, 2024, 10:21am UTC](https://forum.arduino.cc/t/how-to-connect-pm1200-to-arduino-mega-2560/1297970/19 "2024-09-03T10:21:23Z")

</div>

> [@davidefa](#):
>
> The enable pin is not strictly needed these board generate it on the fly ( the board is always in rx, and switch to tx only when requested, after a short delay reverts to rx ).  
> From the [image on the back](https://www.aliexpress.com/item/1005006440363797.html) of the board the tx pin is 'from tx' and the rx is 'to rx' so your connection is ok  
> Regarding the library I used modbusmaster so can't help on this but check the 'address-1' as explained above

Does 'address-1' mean address 3910?

---

<div class="post-metadata">

**Author:** ![davidefa](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/davidefa/32/1088935_2.png) [@davidefa](https://forum.arduino.cc/u/davidefa)\
**Post date:** [September 3, 2024, 10:21am UTC](https://forum.arduino.cc/t/how-to-connect-pm1200-to-arduino-mega-2560/1297970/20 "2024-09-03T10:21:36Z")

</div>

yes

[Next page](https://forum.arduino.cc/t/how-to-connect-pm1200-to-arduino-mega-2560/1297970.md?page=2)
