🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    AIN4-20mA Unit to Arduino Nano Every

    Modules
    3
    9
    620
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • S
      spectrad
      last edited by

      I am trying to talk to the module using a Nano Every using the standard wire example, I get no output at all. If I use a sniffing sketch, it detects the device on 0x55 so it is visible on the bus.

      #include <Wire.h>
      
      void setup() {
        Wire.begin(8);        // join i2c bus (address optional for master)
        Serial.begin(9600);  // start serial for output
      }
      
      void loop() {
        Wire.requestFrom(0x55, 8);    // request 8 bytes from slave device 0x55
      
        while (Wire.available()) { // slave may send less than requested
          char c = Wire.read(); // receive a byte as character
          Serial.print(c,DEC);         // print the character
        }
      
        delay(250);
      }
      

      I have a 4-20mA current source which I can measure, so I am confident I have a variable input.

      I have not used I2C before, I am confident the Arduino libraries are correct, so any pointers to what it might be would be appreciated. Thanks.

      robskiR 1 Reply Last reply Reply Quote 0
      • robskiR
        robski @spectrad
        last edited by

        @spectrad said in AIN4-20mA Unit to Arduino Nano Every:

        I am trying to talk to the module using a Nano Every using the standard wire example, I get no output at all. If I use a sniffing sketch, it detects the device on 0x55 so it is visible on the bus.

        #include <Wire.h>
        
        void setup() {
          Wire.begin(8);        // join i2c bus (address optional for master)
          Serial.begin(9600);  // start serial for output
        }
        
        void loop() {
          Wire.requestFrom(0x55, 8);    // request 8 bytes from slave device 0x55
        
          while (Wire.available()) { // slave may send less than requested
            char c = Wire.read(); // receive a byte as character
            Serial.print(c,DEC);         // print the character
          }
        
          delay(250);
        }
        

        I have a 4-20mA current source which I can measure, so I am confident I have a variable input.

        I have not used I2C before, I am confident the Arduino libraries are correct, so any pointers to what it might be would be appreciated. Thanks.

        not sure if you can marry M5stack sensor/module with diff MCUs than esp32? maybe I'm wrong here.

        M5StickC, M5StickCPlus, M5StickCplus2,M5GO, M5Core, M5Tough, M5Core2, M5 Demo Board, M5Dial, M5Paper, M5Atom, M5Cardputer, M5StampS3, CoreMP135, StamPLC, AirQ

        S 1 Reply Last reply Reply Quote 0
        • S
          spectrad @robski
          last edited by

          @robski I assumed as it was I2C then anything that had an I2C port should work as it's a standard protocol, but I could be wrong as well.

          C 1 Reply Last reply Reply Quote 0
          • C
            Cognitive5525 @spectrad
            last edited by

            @spectrad have you tried with the M5Stack example here?

            S robskiR 2 Replies Last reply Reply Quote 0
            • S
              spectrad @Cognitive5525
              last edited by

              @Cognitive5525 said in AIN4-20mA Unit to Arduino Nano Every:

              @spectrad have you tried with the M5Stack example here?

              No as I am not using an M5Stack, I am trying to use an Arduino Nano Every.

              C 1 Reply Last reply Reply Quote 0
              • robskiR
                robski @Cognitive5525
                last edited by

                @Cognitive5525 said in AIN4-20mA Unit to Arduino Nano Every:

                @spectrad have you tried with the M5Stack example here?

                he doesn't have M5Stack controller, only M5Stack sensor trying to read back to Arduino NANO so not esp32 board.

                M5StickC, M5StickCPlus, M5StickCplus2,M5GO, M5Core, M5Tough, M5Core2, M5 Demo Board, M5Dial, M5Paper, M5Atom, M5Cardputer, M5StampS3, CoreMP135, StamPLC, AirQ

                1 Reply Last reply Reply Quote 1
                • C
                  Cognitive5525 @spectrad
                  last edited by

                  @spectrad said in AIN4-20mA Unit to Arduino Nano Every:

                  @spectrad have you tried with the M5Stack example here?
                  

                  No as I am not using an M5Stack, I am trying to use an Arduino Nano Every.

                  Ah sorry I overlooked that, but even though you're not using a M5stack MC I still believe that you might be able to get some "inspiration" from it. Have a look at the module MODULE_4_20MA in src-folder. As far as I can see it does not rely on any special M5stack libraries at this level.

                  S 1 Reply Last reply Reply Quote 0
                  • S
                    spectrad @Cognitive5525
                    last edited by

                    @Cognitive5525 said in AIN4-20mA Unit to Arduino Nano Every:

                    @spectrad said in AIN4-20mA Unit to Arduino Nano Every:

                    @spectrad have you tried with the M5Stack example here?
                    

                    No as I am not using an M5Stack, I am trying to use an Arduino Nano Every.

                    Ah sorry I overlooked that, but even though you're not using a M5stack MC I still believe that you might be able to get some "inspiration" from it. Have a look at the module MODULE_4_20MA in src-folder. As far as I can see it does not rely on any special M5stack libraries at this level.

                    Although you are not wrong about getting inspiration from it, using the Arduino Wire functions I should get something (and they do detect the device), the M5 library really just decodes the values its reading using the M5 version of the wire library (I assume, I don't know the M5).

                    I am not reading anything from the module using I2c (a standard protocol), that's the bit I don't understand, if I can read some data back, I can manipulate it from there to get a reading, it's just I don't get data, so I am left scratching my head.

                    C 1 Reply Last reply Reply Quote 0
                    • C
                      Cognitive5525 @spectrad
                      last edited by Cognitive5525

                      I think the MODULE_4_20MA (in the src folder) is only using some standard libraries:
                      From top src/MODULE_4_20MA.h:

                      #ifndef __MODULE_4_20MA_H
                      #define __MODULE_4_20MA_H
                      
                      #include "Arduino.h"
                      #include "Wire.h"
                      

                      Try to download only the two files in the src-folder and see if you can include them into your project and compile.

                      Also: If you look at the code in src/MODULE_4_20MA.cpp you'll see that they include some register addresses, maybe that is required for this AIN4-20mA unit?

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post