How would I make a code for the ev3 touch sensor on my raspberry pi? Dexter Industries has already told me that their lego nxt touch sensor code wouldn’t work with my ev3, so how would I make code for it?
No worries. You don’t have to. There are already nxt touch sensor drivers for BrickPi.
Here’s the example.
BrickPi+:
#!/usr/bin/env python
# BRICKPI LEGO TOUCH SENSOR EXAMPLE.
############################################
# This example will show you how to use the LEGO touch sensor with the BrickPi.
# When the touch sensor is pressed, the output should read "1"
# Connect the LEGO Touch Sensor to Sensor port S4.
#
# Original Author: Jaikrishna
# Initial Date: June 24, 2013
# Updated: June 24, 2013
# Updated: Oct 28, 2016 Shoban
#
# These files have been made available online through a Creative Commons Attribution-ShareAlike 3.0 license.
# (http://creativecommons.org/licenses/by-sa/3.0/)
#
# You can learn more about BrickPi here: http://www.dexterindustries.com/BrickPi
# Have a question about this example? Ask on the forums here: http://forum.dexterindustries.com/c/brickpi
from BrickPi import * #import BrickPi.py file to use BrickPi operations
This file has been truncated. show original
BrickPi3:
#!/usr/bin/env python
#
# https://www.dexterindustries.com/BrickPi/
# https://github.com/DexterInd/BrickPi3
#
# Copyright (c) 2016 Dexter Industries
# Released under the MIT license (http://choosealicense.com/licenses/mit/).
# For more information, see https://github.com/DexterInd/BrickPi3/blob/master/LICENSE.md
#
# This code is an example for reading a touch sensor connected to PORT_1 of the BrickPi3
#
# Hardware: Connect an EV3 or NXT touch sensor to BrickPi3 Port 1.
#
# Results: When you run this program, you should see a 0 when the touch sensor is not pressed, and a 1 when the touch sensor is pressed.
from __future__ import print_function # use python 3 syntax but make it compatible with python 2
from __future__ import division # ''
import time # import the time library for the sleep function
import brickpi3 # import the BrickPi3 drivers
This file has been truncated. show original
Thanks graykevinb, but I do not have the BrickPi, only the Breadboard adapter.
karan
February 10, 2017, 6:26am
4
@yousefgomaa : do you want to directly connect the EV3 touch sensor to the Raspberry Pi via the GPIO pins ?