MBC PS2 / PS4 Controller receiver × EV3 clev3r

Read the Controller receiver with clev3r in three steps

A clev3r (EV3 BASIC) program goes in this order. First create the project and pick the port. Then set the receiver mode. Last, read values and show them on the EV3 screen. Follow the steps on the left, and the program on the right grows with you. Click the buttons on the gamepad simulator and drag the sticks to see what the EV3 screen shows.

1

Create the project, pick the port

clev3r needs no extension and no files to import. On the EV3, the receiver pretends to be the LEGO infrared sensor (type 33), so you read it with the normal Sensor commands. The first line, folder, sets the folder the program goes into on the EV3.

  1. Install clev3r (we tested version v1.7.1.0).
  2. Turn on the EV3 first. Then plug the receiver into the port you pick below.
  3. Make a new program and write the lines below.
  4. Press "Compile and download". On the EV3, open the file menu and run it from the folder that starts with MBC_.
Which port is the receiver on?

The first number in the program (for example Sensor.SetMode(1, 0)) is the port. 1~4 are the EV3 ports 1~4.

2

Set the mode

The receiver has several "modes". Each mode sends back a few numbers at once. Sensor.SetMode(port, mode) picks one. Use only one mode in a program: the EV3 needs about 1.1 s every time it changes mode.

Pick a mode (if you pick a reading from another mode in step 3, this changes too):

3

Read and show on the screen

Sensor.ReadRawValue(port, which one) takes one number from the current mode (counting starts at 0). LCD.Text writes it on the EV3 screen. The EV3 screen can only show English letters and numbers, so the labels are short English words. Click a reading, and the program and screen change to its example.

Gamepad simulator: click the buttons, drag the sticks, and watch the output on the right

The simulator is only a sketch: click a button once to hold it, click it again to let go. Drag the dot on a stick to move it (it stays where you let go; press "Release all" to centre it). Sticks go from 1 to 9, 5 = centre, and the number gets bigger to the right and up. The PS4 gamepad battery is fixed at 80 in this demo.

An example for every reading

Full examples


        

!


        

!


        

!

Good to know

  1. Use only one mode in a program. Use mode 1 for driving and buttons: [D-pad, LX, shapes, LY, shoulders, RX, function, RY] all come together. The EV3 waits about 1.1 s every time it changes mode.
  2. Unplugged = 0. In clev3r, Sensor.ReadRawValue gives 0 when there is no data, and the program keeps running. Careful: 0 on a stick means "pushed all the way", so the robot may rush off when unplugged. In a driving program, check with Sensor.GetType that the receiver is still there. Tick "Unplug the sensor" on the right to try it.
  3. Button numbers add up. D-pad: up 1, right 2, down 4, left 8. Shapes: △ 1, ○ 2, ✕ 4, □ 8. Shoulders: L2 1, R2 2, L1 4, R1 8. Function: SELECT 1, L3 2, R3 4, START 8. To check one button, use the maths from the "Is ✕ pressed?" card.
  4. Sticks go from 0 to 99, 50 = centre. Right and up make it bigger. A tiny push makes it jump, so treat 40 to 60 as "not pushed". When the gamepad is not connected, the buttons are 0 and the sticks are 50. In mode 3, a status of 256 or more means connected.
  5. What clev3r cannot read or do: gamepad battery, PS4 rumble and light bar (the EV3 sensor port can only read, not send). The EV3 screen only shows English letters and numbers, so use short English labels in LCD.Text.