0

I had a motor controller connected to GP0 and GP1 so I know they work, however I cant seem to get a response from the SIM controller. Without the pico attached to the board, I can get it to work, but when I add the pico it seems like it wont send AT commands or translate received data if the pico is getting any at all. I have tried to run the code line by line in a live session and all I get is a single number that is equal to the number of letters inside the string that I am sending to the sim controller. ie uart.write(bytearray(b'ATE1\r\n')) would return >>> 6 6 being the number of characters in the code after b. I'm ordering a new pico to see if just maybe it was my sub par soldering, but in the mean time I could see if anyone more experienced than I can point out a error.

import machine
import os
import utime
import time
import binascii
from machine import UART


pwr_enable = 22  # EG25_4G Power key connected on GP22
uart_port = 0
uart_baud = 115200




# Initialize UART0
uart = machine.UART(uart_port, uart_baud)
print(os.uname())


def wait_resp_info(timeout=3000):
        prvmills = utime.ticks_ms()
        info = b""
        while (utime.ticks_ms()-prvmills) < timeout:
            if uart.any():
                info = b"".join([info, uart.read(1)])
        print(info.decode())
        return info



def Check_and_start(): # Initialize SIM Module 
        while True:
            uart.write(bytearray(b'ATE1\r\n')) 
            utime.sleep(10)
            uart.write(bytearray(b'AT\r\n'))
            rec_temp = wait_resp_info()
            print(wait_resp_info())
            print(rec_temp)
            print(rec_temp.decode())
            utime.sleep(10)
            if 'OK' in rec_temp.decode():
                print('OK response from AT command\r\n' + rec_temp.decode())
                break
            else:
                power = machine.Pin(pwr_enable, machine.Pin.OUT)
                power.value(1)
                utime.sleep(2)
                power.value(0)
                print('No response, restarting\r\n')
                utime.sleep(10)
               


def Network_check():# Network connectivity check
        for i in range(1, 3):
            if Send_command("AT+CGREG?", "0,1") == 1:
                print('Connected\r\n')
                break
            else:
                print('Device is NOT connected\r\n')
                utime.sleep(2)
                continue


def Str_to_hex_str(string):
    str_bin = string.encode('utf-8')
    return binascii.hexlify(str_bin).decode('utf-8')



            
    Check_and_start() 
    Network_check() 

Response is

>>> Check_and_start()


b''
b'\x00\x00'

No response, restarting
Jonas
  • 121,568
  • 97
  • 310
  • 388
Kashutu
  • 11
  • 4
  • 1
    `uart.write` returns the number of bytes that was written, so that's expected behaviour. Are you sure that your Pico is transmitting and receiving on the right pins (maybe you should [specify these](http://docs.micropython.org/en/latest/rp2/quickref.html#uart-serial-bus) when you open the port)? To debug a serial communication issue you really need to be able to test it on the hardware level e.g. use an oscilloscope or logic probe to verify that signals are appearing at the expected pins - even an LED (with suitable series resistor) can tell you whether anything is happening or not. – nekomatic Mar 18 '22 at 14:49
  • Ok I added ```uart = machine.UART(0, 115200, tx=Pin(0), rx= Pin(1))``` same problem. I think it is not actually sending any data across the serial line. I have no fancy equipment to test of course. When I run ```uart``` I get the response ```UART(0, baudrate=115200, bits=8, parity=None, stop=1, tx=0, rx=1, txbuf=256, rxbuf=256, timeout=0, timeout_char=1, invert=None)``` Which at least to me look like its set up right. Is ```uart.write``` the correct use here? Also this is the expansion board I am using https://github.com/sbcshop/Pico-4G-Expansion – Kashutu Mar 18 '22 at 15:56

1 Answers1

1

New Pico fixed my issue, I believe it to be that my inadequate soldering skills created the issue. Symptoms were, no UART data was being transmitted or received through UART pins 0 and 1. Solution was new Pico board was inserted in place of old one, same code was uploaded and ran successfully first time.

Kashutu
  • 11
  • 4