Black Lives Matter - Action and Equality. ... Adafruit is open and shipping.
0

RFM69 w/ ItsyBItsy M4 Express will not work when unplugged f
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

RFM69 w/ ItsyBItsy M4 Express will not work when unplugged f

by natedog0125 on Wed Apr 08, 2020 3:56 pm

Hello,

I am currently creating a remote for a radio-controlled robot using Adafruit's ItsyBitsy M4 Express and RFM69 433Mhz and 2 joysticks. I am using CircuitPython as well. When connected to the serial port on Mu, my code runs perfectly, but as soon as I disconnect from my computer, nothing happens. I am powering it using Adafruit's LiPo backpack w/ 500mAh battery. Does anyone know why this might happen? I have tested it using a Metro M0 Express and 9V with the same results.

Code: Select all | TOGGLE FULL SIZE

import board
import busio
import analogio
import digitalio
import time
import usb_hid
import adafruit_rfm69

from adafruit_hid.gamepad import Gamepad


# Define radio parameters.
RADIO_FREQ_MHZ = 433.0

# Define pins connected to the chip, use these if wiring up the breakout according to the guide:
CS = digitalio.DigitalInOut(board.D4)
RESET = digitalio.DigitalInOut(board.D3)

# Initialize SPI bus.
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)

# Initialze RFM radio
rfm69 = adafruit_rfm69.RFM69(spi, CS, RESET, RADIO_FREQ_MHZ)

# Optionally set an encryption key (16 byte AES key). MUST match both
# on the transmitter and receiver (or be set to None to disable/the default).
rfm69.encryption_key = b'\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08'

gp = Gamepad(usb_hid.devices)

xPin = analogio.AnalogIn(board.A0)
yPin = analogio.AnalogIn(board.A1)

# Equivalent of Arduino's map() function.
def range_map(x, in_min, in_max, out_min, out_max):
    return (x - in_min) * (out_max - out_min) // (in_max - in_min) + out_min

xDir = 0
yDir = 0

while True:
    gp.move_joysticks(x=range_map(xPin.value, 0, 65535, -127, 127),
                  y=range_map(yPin.value, 0, 65535, -127, 127))

    if xPin.value > 0 and xPin.value < 500:
        #print('x is up')
        xDir = 1

    elif xPin.value > 30000 and xPin.value < 35000:
        #print('x is down')
        xDir = 2
    else:
        xDir = 0

    if yPin.value > 30000 and yPin.value < 35000:
        #print('y is left')
        yDir = 4
    elif yPin.value > 0 and yPin.value < 1200:
        #print('y is right')
        yDir = 7
    else:
        yDir = 0

    sendPin = xDir + yDir
    print(sendPin)
    rfm69.send(bytes('{0}'.format(sendPin),"utf-8"))
    print(sendPin)

Attachments
Controller Design.png
Controller Design.png (339.81 KiB) Viewed 45 times

natedog0125
 
Posts: 2
Joined: Wed Apr 08, 2020 3:02 pm

Re: RFM69 w/ ItsyBItsy M4 Express will not work when unplugg

by siddacious on Wed Apr 08, 2020 7:55 pm

Please post one or more clear, well lit pictures that show how everything is connected. From what you said it sounds like a hardware issue, likely wiring or possibly something else.

Please also go into more detail about how you are testing:
How are you verifying that it is working when it is
How do you know that it isn't working; what are you expecting to see but you don't?

When running off of the battery, are any of the LEDs on the ItsyBitsy lit?

What is on the receiving side? How close or far from the transmitter is it?

The more detail you can give, the better we'll be able to help

siddacious
 
Posts: 274
Joined: Fri Apr 21, 2017 3:09 pm

Re: RFM69 w/ ItsyBItsy M4 Express will not work when unplugg

by natedog0125 on Wed Apr 08, 2020 10:24 pm

I have added a few photos to this reply, though, they may not be as useful as the diagram I posted originally.
https://ibb.co/WGgfsZD
https://ibb.co/zXfmJ32
https://ibb.co/sRqXzfZ
https://ibb.co/gJ2YNzq

https://ibb.co/LNwrddN

So, to run down how the code works (apologies I need to go back and comment it better) and how I am testing it. The first several lines are just to set up the variables for the pins and such and mapping the joysticks. How the code within the while loop works is that after the mapping process has occurred, I found the range for each direction on the joysticks and set them equal to a one-digit integer to be sent to the car. This digit is then interpreted by the car as a direction, in which it drives.

Initially, I started testing by keeping the remote connected to the serial monitor so I could make sure it was sending the correct integer value or sending one at all. And up to this point, it was. The car would go in the correct direction and would continue until I lifted my fingers from the joysticks. I then went to unplug my remote from my computer so I could take it to another location. Once I unplugged the ItsyBitsy, the built-in led would light up green (as it stayed while plugged into my computer) but, then it would start blinking yellow 3x then turquoise 3x and then repeat that process. When I would move the joysticks, there was no response from the car.

On the receiving side is an Adafruit Feather with the FeatherWing Motor Driver and another RFM69 433mhz transmitter. It is only about a yard away from me, but could go about 10+ yards away when the remote was connected to my computer. I haven't had any reason to believe there were issues with it since it was working independently, but I could be wrong.

Here is an image and the code from the car:
https://ibb.co/vjBPTy6

Code: Select all | TOGGLE FULL SIZE

import board
import busio
import digitalio
from adafruit_motorkit import MotorKit
import adafruit_rfm69

kit = MotorKit()

# Define radio parameters.
RADIO_FREQ_MHZ = 433.0  # Frequency of the radio in Mhz. Must match your
                        # module! Can be a value like 915.0, 433.0, etc.

# Define pins connected to the chip, use these if wiring up the breakout according to the guide:
CS = digitalio.DigitalInOut(board.D5)
RESET = digitalio.DigitalInOut(board.D6)

LED = digitalio.DigitalInOut(board.D13)
LED.direction = digitalio.Direction.OUTPUT

# Initialize SPI bus.
spi = busio.SPI(board.SCK, MOSI=board.MOSI, MISO=board.MISO)
# Initialze RFM radio
rfm69 = adafruit_rfm69.RFM69(spi, CS, RESET, RADIO_FREQ_MHZ)

# Optionally set an encryption key (16 byte AES key). MUST match both
# on the transmitter and receiver (or be set to None to disable/the default).
rfm69.encryption_key = b'\x01\x02\x03\x04\x05\x06\x07\x08\x01\x02\x03\x04\x05\x06\x07\x08'

kit.motor1.throttle = 0
kit.motor2.throttle = 0
kit.motor3.throttle = 0
kit.motor4.throttle = 0

x = 1
direction = '0'
while x == 1:

    direction_text = rfm69.receive()
    print(direction_text)

    if direction_text is not None:
        directions = str(direction_text, 'ascii')
        direction = directions
        print(directions)
    print('move:', direction)

    #stop = 0
    #forward = 1
    #forwardLeft = 5
    #forwardRight = 8
    #back = 2
    #backLeft = 6
    #backRight = 9
    #left = 4
    #right = 7

    if direction == '0':
        kit.motor1.throttle = 0
        kit.motor2.throttle = 0
        kit.motor3.throttle = 0
        kit.motor4.throttle = 0

    elif direction == '1':
        kit.motor1.throttle = 1
        kit.motor2.throttle = 1
        kit.motor3.throttle = 1
        kit.motor4.throttle = 1
    elif direction == '2':
        kit.motor1.throttle = -1
        kit.motor2.throttle = -1
        kit.motor3.throttle = -1
        kit.motor4.throttle = -1
    elif direction == '4':
        kit.motor1.throttle = 1
        kit.motor2.throttle = 0
        kit.motor3.throttle = 0
        kit.motor4.throttle = 1
    elif direction == '7':
        kit.motor1.throttle = 0
        kit.motor2.throttle = 1
        kit.motor3.throttle = 1
        kit.motor4.throttle = 0
    elif direction == '5':
        kit.motor1.throttle = 1
        kit.motor2.throttle = .5
        kit.motor3.throttle = 1
        kit.motor4.throttle = 1
    elif direction == '8':
        kit.motor1.throttle = .5
        kit.motor2.throttle = 1
        kit.motor3.throttle = 1
        kit.motor4.throttle = 1
    elif direction == '6':
        kit.motor1.throttle = -1
        kit.motor2.throttle = -.5
        kit.motor3.throttle = -1
        kit.motor4.throttle = -1
    elif direction == '9':
        kit.motor1.throttle = -.5
        kit.motor2.throttle = -1
        kit.motor3.throttle = -1
        kit.motor4.throttle = -1
    else:
        print('Error')


natedog0125
 
Posts: 2
Joined: Wed Apr 08, 2020 3:02 pm

Please be positive and constructive with your questions and comments.