Welcome to the Pycom forum Forum
    • \[\[global:header.categories\]\]
    • \[\[global:header.recent\]\]
    • \[\[global:header.tags\]\]
    • \[\[global:header.popular\]\]
    • Login

    Explore Pybytes | Official Documentation | Report a Firmware Bug/Issue | GitHub

    EXPORT CODE FROM ARDUINO TO PYMAKR

    Scheduled Pinned Locked Moved Pymakr
    sipypymakrmicropython
    5 Posts 3 Posters 2.9k Views 3 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.
    • J Offline
      julian cifuentes
      last edited by

      Hello everyone. Please I need help, I have a code in arduino where I read an analog value and with respect to that value I execute a series of cases. I need to pass that code to urgent pymakr, but could you help me?0_1488936277596_arduino.png

      L 1 Reply Last reply Reply Quote 0
      • L Offline
        livius @julian cifuentes
        last edited by

        @julian-cifuentes
        It is really simple code - but you must convert it to micropython
        I do not like to show exact translation - better is doing it self :)

        arduino analogread equivalent is described here https://docs.pycom.io/pycom_esp32/library/machine.ADC.html#machine.ADC

        digitalRead/write:
        https://docs.pycom.io/pycom_esp32/library/machine.Pin.html

        in python you do not declare vars as typed
        instead of float db = you simple write db =
        instead Serial.print you simply write print
        or uart.write if you have it created in boot.py

        line break is "

        '\n'
        

        think about people first, then computers

        J 1 Reply Last reply Reply Quote 1
        • C Offline
          constantinos
          last edited by

          There is no tool for this. You have to learn python. This does not need skills to port.

          1 Reply Last reply Reply Quote 0
          • J Offline
            julian cifuentes @livius
            last edited by

            @livius
            Thank you so much friend, I'm going to work on it

            1 Reply Last reply Reply Quote 0
            • C Offline
              constantinos
              last edited by constantinos

              Take a look to an arduino like wrapper for pycom at https://github.com/dinosd/pyCom/blob/master/examples/arduino_sample.py

              import arduino
              
              
              estado = 0
              estado2 = 0
              cont = 0
              A = 10
              B = 11
              C = 12
              D = 13
              E = 14
              def setup():
                  arduino.pinMode(15, "ANALOG_INPUT")  #PIN P15,  there is no mode analog input in arduino but pycom needs it
                  arduino.pinMode(8, "INPUT")          # modes are "INPUT","OUTPUT","INPUT_PULLUP","INPUT_PULLDOWN","ANALOG_INPUT"
                  arduino.pinMode(7, "INPUT")     
                  arduino.pinMode(A, "OUTPUT")     
                  arduino.pinMode(B, "OUTPUT")     
                  arduino.pinMode(C, "OUTPUT")     
                  arduino.pinMode(D, "OUTPUT")     
                  arduino.pinMode(E, "OUTPUT")     
                  
                  
              def loop():
                  global estado, estado2, cont
                  
                  value = arduino.analogRead(13)
                  millivolts = 1100 * value / 1.1      #max volts for analog in is 1.1V
                  db = millivolts / 10
                  print(db, "DB")
                  estado2 = arduino.digitalRead(8)
                  if estado2:   #this means high  or you can write if estado2==1
                      estado = arduino.digitalRead(7)
                      if estado:
                          arduino.delay(500)
                      cont += 1
                  if cont==1:
                      arduino.digitalWrite(A, 1)
                      arduino.digitalWrite(B, 1)
                      arduino.digitalWrite(C, 1)
                      arduino.digitalWrite(D, 1)
                      arduino.digitalWrite(E, 1)
              
              setup()
              while True:
                  loop()        
              
              1 Reply Last reply Reply Quote 1

              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
              • 1 / 1
              • First post
                Last post

              Pycom on Twitter

              Pycom