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

    M5Dial UART Write not sending data

    Scheduled Pinned Locked Moved UiFlow 2.0
    3 Posts 2 Posters 1.2k Views 2 Watching
    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.
    • X Offline
      xbr11332003
      last edited by

      The following M5Dial/UIFlow 2.0 code is able to receive data from Arduino Uno r4 wifi, but i cannot get data to Arduino. Using basic example Arduino code that works on other devices. Am i missing something? Tried every write command in UART list.

      import os, sys, io
      import M5
      from M5 import *
      from hardware import *
      
      
      
      label0 = None
      label1 = None
      label2 = None
      rotary = None
      uart1 = None
      
      
      def btnA_wasClicked_event(state):
        global label0, label1, label2, rotary, uart1
        rotary.reset_rotary_value()
        label0.setText(str(rotary.get_rotary_value()))
        label1.setText(str(rotary.get_rotary_value()))
        print(uart1.read(1)[0])
        uart1.write(bytes([1]))
      
      
      def btnA_wasHold_event(state):
        global label0, label1, label2, rotary, uart1
        label1.setText(str('hold'))
        label2.setText(str('Label'))
      
      
      def setup():
        global label0, label1, label2, rotary, uart1
      
        M5.begin()
        Widgets.fillScreen(0x222222)
        label0 = Widgets.Label("0", 96, 80, 1.0, 0xffa000, 0x222222, Widgets.FONTS.DejaVu72)
        label1 = Widgets.Label("label1", 88, 158, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu18)
        label2 = Widgets.Label("label2", -21, 114, 1.0, 0xffffff, 0x222222, Widgets.FONTS.DejaVu9)
      
        BtnA.setCallback(type=BtnA.CB_TYPE.WAS_CLICKED, cb=btnA_wasClicked_event)
        BtnA.setCallback(type=BtnA.CB_TYPE.WAS_HOLD, cb=btnA_wasHold_event)
      
        label1.setColor(0xcc33cc, 0x33ff33)
        rotary = Rotary()
        uart1 = UART(1, baudrate=9600, bits=8, parity=None, stop=1, tx=13, rx=15, txbuf=256, rxbuf=256, timeout=0, timeout_char=0, invert=0, flow=0)
      
      
      def loop():
        global label0, label1, label2, rotary, uart1
        M5.update()
        if rotary.get_rotary_status():
          label0.setText(str(rotary.get_rotary_value()))
      
      
      if __name__ == '__main__':
        try:
          setup()
          while True:
            loop()
        except (Exception, KeyboardInterrupt) as e:
          try:
            from utility import print_error_msg
            print_error_msg(e)
          except ImportError:
            print("please update to latest firmware")
      

      Arduino Code:

      int incomingByte = 0; // for incoming serial data
      
      void setup() {
        Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
      Serial1.begin(9600);
      }
      
      void loop() {
        // reply only when you receive data:
        if (Serial1.available() > 0) {
          // read the incoming byte:
          incomingByte = Serial.read();
      
          // say what you got:
          Serial1.print("I received: ");
          Serial1.println(incomingByte, DEC);
        }
      }
      
      X 1 Reply Last reply Reply Quote 0
      • X Offline
        xbr11332003 @xbr11332003
        last edited by xbr11332003

        @xbr11332003
        Tried every UART write command and arduino is not receiving data.
        Serial monitor on Arduino prints -1. Again, I can send data to m5dial but arduino does not receive. Other arduino boards work flawlessly. Please help felix.

        felmueF 1 Reply Last reply Reply Quote 0
        • felmueF Online
          felmue @xbr11332003
          last edited by

          Hello @xbr11332003

          have you tried to send the data with trailing CR LF? E.g. uart1.write('hallo\r\n')? Works for me.

          Thanks
          Felix

          GPIO translation table M5Stack / M5Core2
          Information about various M5Stack products.
          Code examples

          1 Reply Last reply Reply Quote 0

          Hello! It looks like you're interested in this conversation, but you don't have an account yet.

          Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.

          With your input, this post could be even better 💗

          Register Login
          • First post
            Last post