Notifications
Clear all

Ship model with custom made transmitter and Raspberry Pi control  

Page 3 / 3
  RSS

robotBuilder
(@robotbuilder)
Reputable Member
Joined: 1 year ago
Posts: 492
2020-06-04 11:11 pm  

@coco777

That is so kind of you, helping me out that way! Thanks a lot.

 

It would be just sharing my learning experience with the components and I may turn out to be of no help at all!

Good old China. Once we made our own electronics, even here in Australia, now we have outsourced the manufacturing to China with its cheap labour.

At this stage I have had no experience with using WiFi and the RPi or Arduino.

I use the Arduino Mega as it has plenty of i/o pins. It is not an overkill as a robot controller.

 


ReplyQuote
Coco777
(@coco777)
Eminent Member
Joined: 4 months ago
Posts: 22
2020-06-05 12:01 pm  

@robotbuilder,

I meant that the Mega is overkill for only translating the signals between the Pi and the RX/TX. The Mega actually has some advantages over the Pi when it comes to controlling servo's and motors. 

 

China certainly has a lot to offer in that regard. Would be so much better for the climate to have as much products made in all countries themselves rather then transporting all around the globe.

 

Greetings Josse

Still working on getting my transmitter to work and trying to get my boats engine's controlled with RPi.


ReplyQuote
Coco777
(@coco777)
Eminent Member
Joined: 4 months ago
Posts: 22
2020-06-24 8:28 pm  

Hi guys,

 

Today I started testing a little more with reading more inputs, expanding the script I used earlier. That resulted in my first modification without any alarms about mistakes or unknown commands etc.! See below my code, all I did was add readout's for all the different channels. It doesn't keep reading all the channels though, that will be my next step. I couldn't make enough sense of the remaining code to figure out how I can keep reading all 8 channels, can you folks help me out there?

import os
import time
import busio
import digitalio
import board
import adafruit_mcp3xxx.mcp3008 as MCP
from adafruit_mcp3xxx.analog_in import AnalogIn

# create the spi bus
spi = busio.SPI(clock=board.SCK, MISO=board.MISO, MOSI=board.MOSI)

# create the cs (chip select)
cs = digitalio.DigitalInOut(board.D22)

# create the mcp object
mcp = MCP.MCP3008(spi, cs)

# create an analog input channel on pin 0
chan0 = AnalogIn(mcp, MCP.P0)
chan1 = AnalogIn(mcp, MCP.P1)
chan2 = AnalogIn(mcp, MCP.P2)
chan3 = AnalogIn(mcp, MCP.P3)
chan4 = AnalogIn(mcp, MCP.P4)
chan5 = AnalogIn(mcp, MCP.P5)
chan6 = AnalogIn(mcp, MCP.P6)
chan7 = AnalogIn(mcp, MCP.P7)

print('Raw ADC Value: ', chan0.value)
print('ADC Voltage: ' + str(chan0.voltage) + 'V')
print('Input 0: ', chan0.value)
print('Input 1: ', chan1.value)
print('Input 2: ', chan2.value)
print('Input 3: ', chan3.value)
print('Input 4: ', chan4.value)
print('Input 5: ', chan5.value)
print('Input 6: ', chan6.value)
print('Input 7: ', chan7.value)

last_read = 0 # this keeps track of the last potentiometer value
tolerance = 250 # to keep from being jittery we'll only change
# volume when the pot has moved a significant amount
# on a 16-bit ADC

def remap_range(value, left_min, left_max, right_min, right_max):
# this remaps a value from original (left) range to new (right) range
# Figure out how 'wide' each range is
left_span = left_max - left_min
right_span = right_max - right_min

# Convert the left range into a 0-1 range (int)
valueScaled = int(value - left_min) / int(left_span)

# Convert the 0-1 range into a value in the right range.
return int(right_min + (valueScaled * right_span))

while True:
# we'll assume that the pot didn't move
trim_pot_changed = False

# read the analog pin
trim_pot = chan0.value

# how much has it changed since the last read?
pot_adjust = abs(trim_pot - last_read)

if pot_adjust > tolerance:
trim_pot_changed = True

if trim_pot_changed:
# convert 16bit adc0 (0-65535) trim pot read into 0-100 volume level
set_volume = remap_range(trim_pot, 0, 65535, 0, 100)

# set OS volume playback volume
print('Volume = {volume}' .format(volume = set_volume))
set_vol_cmd = 'sudo amixer cset numid=1 -- {volume} > /dev/null' \
.format(volume = set_volume)
os.system(set_vol_cmd)

# save the potentiometer reading for the next loop
last_read = trim_pot

# hang out and do nothing for a half second
time.sleep(0.5)

image

 

Still working on getting my transmitter to work and trying to get my boats engine's controlled with RPi.


ReplyQuote
Coco777
(@coco777)
Eminent Member
Joined: 4 months ago
Posts: 22
2020-06-25 9:10 pm  

Hi folks,

 

Today I decided to dig a little deeper, no time to test yet, will try soon. What do you think of the code below?

I added some reference for the to be attached for the future connection of the remaining 3 MCP3008's, those 3 have been commented for now since I need to figure out how to properly adress and wire those.

I also expanded the lists so I think I should now have a list of 8 inputs constantly being monitored. I also changed the map value from 0-100 to 0-255 which is for better suited for the servo's. To the best of my knowledge this should work, or do you folks find any mistake I missed?

 

import os

import time

import busio

import digitalio

import board

import adafruit_mcp3xxx.mcp3008 as MCP

from adafruit_mcp3xxx.analog_in import AnalogIn




# create the spi bus

spi = busio.SPI(clock=board.SCK, MISO=board.MISO, MOSI=board.MOSI)




# create the cs (chip select)

cs = digitalio.DigitalInOut(board.D22)




# create the mcp object

mcp1 = MCP.MCP3008(spi, cs)

#mcp2 = MCP.MCP3008( , )

#mcp3 = MCP.MCP3008( , )

#mcp4 = MCP.MCP3008( , )




# create an analog input channel on pin 0

chan0 = AnalogIn(mcp1, MCP.P0)

chan1 = AnalogIn(mcp1, MCP.P1)

chan2 = AnalogIn(mcp1, MCP.P2)

chan3 = AnalogIn(mcp1, MCP.P3)

chan4 = AnalogIn(mcp1, MCP.P4)

chan5 = AnalogIn(mcp1, MCP.P5)

chan6 = AnalogIn(mcp1, MCP.P6)

chan7 = AnalogIn(mcp1, MCP.P7)




print('Raw ADC Value: ', chan0.value)

print('ADC Voltage: ' + str(chan0.voltage) + 'V')

print('Input 0: ', chan0.value)

print('Input 1: ', chan1.value)

print('Input 2: ', chan2.value)

print('Input 3: ', chan3.value)

print('Input 4: ', chan4.value)

print('Input 5: ', chan5.value)

print('Input 6: ', chan6.value)

print('Input 7: ', chan7.value)




last_read0 = 0       # this keeps track of the last potentiometer value

last_read1 = 0       # this keeps track of the last potentiometer value

last_read2 = 0       # this keeps track of the last potentiometer value

last_read3 = 0       # this keeps track of the last potentiometer value

last_read4 = 0       # this keeps track of the last potentiometer value

last_read5 = 0       # this keeps track of the last potentiometer value

last_read6 = 0       # this keeps track of the last potentiometer value

last_read7 = 0       # this keeps track of the last potentiometer value

tolerance = 100     # to keep from being jittery we'll only change

                    # volume when the pot has moved a significant amount

                    # on a 16-bit ADC




def remap_range(value, left_min, left_max, right_min, right_max):

    # this remaps a value from original (left) range to new (right) range

    # Figure out how 'wide' each range is

    left_span = left_max - left_min

    right_span = right_max - right_min




    # Convert the left range into a 0-1 range (int)

    valueScaled = int(value - left_min) / int(left_span)




    # Convert the 0-1 range into a value in the right range.

    return int(right_min + (valueScaled * right_span))




while True:

    # we'll assume that the pot didn't move

    trim_pot_changed = False




    # read the analog pin

    trim_pot0 = chan0.value

    trim_pot1 = chan1.value

    trim_pot2 = chan2.value

    trim_pot3 = chan3.value

    trim_pot4 = chan4.value

    trim_pot5 = chan5.value

    trim_pot6 = chan6.value

    trim_pot7 = chan7.value







    # how much has it changed since the last read?

    pot_adjust = abs(trim_pot - last_read)




    if pot_adjust > tolerance:

        trim_pot_changed = True




    if trim_pot_changed:

        # convert 16bit adc0 (0-65535) trim pot read into 0-255 input level

        set_input0 = remap_range(trim_pot0, 0, 65535, 0, 255)

        set_input1 = remap_range(trim_pot1, 0, 65535, 0, 255)

        set_input2 = remap_range(trim_pot2, 0, 65535, 0, 255)

        set_input3 = remap_range(trim_pot3, 0, 65535, 0, 255)

        set_input4 = remap_range(trim_pot4, 0, 65535, 0, 255)

        set_input5 = remap_range(trim_pot5, 0, 65535, 0, 255)

        set_input6 = remap_range(trim_pot6, 0, 65535, 0, 255)

        set_input7 = remap_range(trim_pot7, 0, 65535, 0, 255)







        # set OS volume playback volume

        print('Input0 = {input0}' .format(input0 = set_input0))

        print('Input1 = {input1}' .format(input1 = set_input1))

        print('Input2 = {input2}' .format(input2 = set_input2))

        print('Input3 = {input3}' .format(input3 = set_input3))

        print('Input4 = {input4}' .format(input4 = set_input4))

        print('Input5 = {input5}' .format(input5 = set_input5))

        print('Input6 = {input6}' .format(input6 = set_input6))

        print('Input7 = {input7}' .format(input7 = set_input7))

        #set_vol_cmd = 'sudo amixer cset numid=1 -- {volume} > /dev/null' \

        #.format(volume = set_volume)

        #os.system(set_vol_cmd)




        # save the potentiometer reading for the next loop

        last_read0 = trim_pot0

        last_read1 = trim_pot1

        last_read2 = trim_pot2

        last_read3 = trim_pot3

        last_read4 = trim_pot4

        last_read5 = trim_pot5

        last_read6 = trim_pot6

        last_read7 = trim_pot7




    # hang out and do nothing for a tenth of a second

    time.sleep(0.1)

 

Thanks in advance.

 

Greetings Josse

Still working on getting my transmitter to work and trying to get my boats engine's controlled with RPi.


ReplyQuote
Coco777
(@coco777)
Eminent Member
Joined: 4 months ago
Posts: 22
2020-08-04 4:02 pm  

Hi folks,

 

It's been a while. I have tested the software from my last post, and it works. Though it doesn't yet keep reading all inputs. My father is now trying to find a way to improve the programming by making a matrix of it all, but he hasn't yet managed to get a complete working program yet. 

 

Meanwhile I have ordered and received a new Pi 4 with 2GB and got that installed. Now I need to find some time to start testing, especially with the PWM module. I still need to connect the battery pack to the side connections. Does anyone have any reference on the range of the build-in WiFi of the Pi 4? If the range would be like at least say 150m it could well be a good way to connect between the transmitter and the boat, also because I need WiFi anyways for sending the video feeds back to the transmitter.

 

In the mean time I'm now thinking about how to get the propulsion modified for my use, with steppermotors for steering and with the electric motors installed vertical rather then horizontal.

 

Software wise, the next step will be to send the input values to the PWM module, first using only 1 Pi, and later with a wireless connection. Can you guys give any thoughts on how I can make the Pi send the values? I don't no the command for that yet. 

The step after that will be controlling the stepper motor. They already have an H-bridge controller attach to it, but that will need commands too.

 

Thanks for the help.

 

Greetings Josse

Still working on getting my transmitter to work and trying to get my boats engine's controlled with RPi.


ReplyQuote
codecage
(@codecage)
Member Admin
Joined: 1 year ago
Posts: 721
2020-08-05 12:37 pm  

@coco777

Have you thought about using the nRF24L01+ modules for remote control versus just the embedded WiFi?  You would have much better range with these modules.  I am assuming since we are talking about controlling a model ship that our "playing" surface is a lake or a small pond of water.  In other words no buildings or terrain to interfere with our control signals.

Just a thought and an alternate solution to put some more tools in your toolkit. 😀 

SteveG


ReplyQuote
Coco777
(@coco777)
Eminent Member
Joined: 4 months ago
Posts: 22
2020-08-06 9:20 pm  

@codecage,

Thanks for thoughts! I actually intended to use the NRF, I was only trying to find out if WiFi could be an alternative, since the NRF can't handle video I think. Due to the 7" touchscreen resolution the feed doesn't need HD resolution, which will give greater range then HD quality.

 

Greetings Josse

Still working on getting my transmitter to work and trying to get my boats engine's controlled with RPi.


ReplyQuote
Page 3 / 3