42
Java with Raspberry Pi Stephen Chin (@steveonjava) Java Community Manager JavaOne Conference Chair

Raspberry Pi with Java (JJUG)

Embed Size (px)

Citation preview

Page 1: Raspberry Pi with Java (JJUG)

Java with Raspberry Pi

Stephen Chin (@steveonjava)Java Community ManagerJavaOne Conference Chair

Page 2: Raspberry Pi with Java (JJUG)

Java ScaleRaspberry Pi Coffee

Page 3: Raspberry Pi with Java (JJUG)

Fuglen Coffee

3

Page 4: Raspberry Pi with Java (JJUG)

The Coffeeshop Roast Works

4

Page 5: Raspberry Pi with Java (JJUG)

About Life Coffee

5

Page 6: Raspberry Pi with Java (JJUG)

Bridge Coffee and Ice Cream

6

Page 7: Raspberry Pi with Java (JJUG)

Bridge Coffee and Ice Cream

7

Page 8: Raspberry Pi with Java (JJUG)

Latte at Bridge

8

Page 9: Raspberry Pi with Java (JJUG)

Peace Coffee Roasters

9

Page 10: Raspberry Pi with Java (JJUG)

Aeropress at Peace

10

Page 11: Raspberry Pi with Java (JJUG)

Little Nap Coffee Stand

11

Page 12: Raspberry Pi with Java (JJUG)

Espresso from Little Nap

12

Page 13: Raspberry Pi with Java (JJUG)

AeroPress

13

Page 14: Raspberry Pi with Java (JJUG)

Porlex Grinder

14

Page 15: Raspberry Pi with Java (JJUG)

Finding a USB Scalepublic static UsbScaleTest findScale() throws UsbException {

UsbServices services = UsbHostManager.getUsbServices();

UsbHub rootHub = services.getRootUsbHub();

// Dymo M10 Scale:

UsbDevice device = findDevice(rootHub, (short) 0x0922, (short) 0x8003);

// Dymo M25 Scale:

if (device == null) {

device = findDevice(rootHub, (short) 0x0922, (short) 0x8004);

}

return new UsbScaleTest(device);

}

15

Page 16: Raspberry Pi with Java (JJUG)

Printing out Weightpublic void dataEventOccurred(UsbPipeDataEvent upde) {

boolean empty = data[1] == 2;

boolean overweight = data[1] == 6;

boolean negative = data[1] == 5;

boolean grams = data[2] == 2;

int scalingFactor = data[3];

int weight = (data[4] & 0xFF) + (data[5] << 8);

System.out.println(String.format("Weight = %,.1f%s",

scaleWeight(weight, scalingFactor),

grams ? "g" : "oz"));

}

16

Page 17: Raspberry Pi with Java (JJUG)

17

Driving Test

https://www.flickr.com/photos/davidyuweb/1352312273

Page 18: Raspberry Pi with Java (JJUG)

18

Page 19: Raspberry Pi with Java (JJUG)

19

Page 20: Raspberry Pi with Java (JJUG)

20

Page 21: Raspberry Pi with Java (JJUG)

21

Page 22: Raspberry Pi with Java (JJUG)

22

Page 23: Raspberry Pi with Java (JJUG)

23

Page 24: Raspberry Pi with Java (JJUG)

Up-Up-Down-Down-Left-Right-Left-Right B, A, Start

24

Page 25: Raspberry Pi with Java (JJUG)

Meet Mr. Grabby

25

https://www.flickr.com/photos/pasukaru76/8278458818/https://www.flickr.com/photos/fallentomato/5656700432/

+ =

Page 26: Raspberry Pi with Java (JJUG)

Meet Mr. Grabby

26

Page 27: Raspberry Pi with Java (JJUG)

Mr. Grabby's Back

27

Controller

Grabber

Page 28: Raspberry Pi with Java (JJUG)

Controller

• Raspberry Pi

• Cooking Hacks Shield

• MakeBlocks ME Base Shield

28

Page 29: Raspberry Pi with Java (JJUG)

Mr. Grabby's Belly

29

Line Follower

Batteries

DC Motors

Page 30: Raspberry Pi with Java (JJUG)

How Line Followers Work

30

• Infrared LED

– Bounced light off the ground

• Infrared Luminosity Sensor

– Detects reflected light

Page 31: Raspberry Pi with Java (JJUG)

Getting GPIO

gpio = GpioFactory.getInstance();

lineFollowA = gpio.provisionDigitalInputPin(RaspiPin.GPIO_13, "LineFollowA");

lineFollowB = gpio.provisionDigitalInputPin(RaspiPin.GPIO_14, "LineFollowA");

startGPIO();

boolean leftSensor = lineFollowA.getState().isHigh();

boolean rightSensor = lineFollowB.getState().isHigh();

31

Page 32: Raspberry Pi with Java (JJUG)

Line Following Algorithm

if (leftSensor && rightSensor) { //we are lost

doDrive(lineLocation);

} else if (!leftSensor && !rightSensor) { //on the line

lineLocation = Drive.forward; doDrive(Drive.forward);

} else if (!leftSensor && rightSensor) { //off the right

lineLocation = Drive.left; doDrive(Drive.forward);

} else if (leftSensor && !rightSensor) { //off the left

lineLocation = Drive.right; doDrive(Drive.forward);

}

32

Page 33: Raspberry Pi with Java (JJUG)

Make your own Mr. Grabby

• MakeBlock Advanced Robotics Kit

• MakeBlock ME Base Shield

• Cooking Hacks Shield

• USB Battery (1A)

• Code here:

https://github.com/steveonjava/LineFollower

33

Page 34: Raspberry Pi with Java (JJUG)

Ultimaker 2

34

Page 35: Raspberry Pi with Java (JJUG)

35

Page 36: Raspberry Pi with Java (JJUG)

Java Constructive Geometry (JCSG / JFXScad)

• Create geometries from pure Java code

• Visualize with a JavaFX user interface

• Generate STL files for 3D printing

• Project sites:

https://github.com/miho/JCSG

https://github.com/miho/JFXScad

36

Page 37: Raspberry Pi with Java (JJUG)

37

Page 38: Raspberry Pi with Java (JJUG)

38

Page 39: Raspberry Pi with Java (JJUG)

JJUG Exclusive Pepper Workshop

39

Page 40: Raspberry Pi with Java (JJUG)

Stephen Chintweet: @steveonjavablog: http://steveonjava.com

nighthacking.com

Real Geeks

Live Hacking

NightHacking Tour

Page 41: Raspberry Pi with Java (JJUG)

Safe Harbor Statement

The preceding is intended to outline our general product direction. It is intended for information purposes only, and may not be incorporated into any contract. It is not a commitment to deliver any material, code, or functionality, and should not be relied upon in making purchasing decisions. The development, release, and timing of any features or functionality described for Oracle’s products remains at the sole discretion of Oracle.

41

Page 42: Raspberry Pi with Java (JJUG)