首页 > > 详细

代做ECET 35901 Computer Based Data Acquisition Applications Summer 2025 Practical Assignment 6调试R语言

项目预算:   开发周期:  发布时间:   要求地区:

ECET 35901

Computer Based Data Acquisition Applications

Summer 2025

[Practical Assignment 6]

Raspberry Pi GPIO in Node Red

Objectives:

• Configure the Raspberry Pi’s GPIO with Node Red.

• Familiarize with the pinout of the Raspberry Pi 4 Model B.

• Create a binary to seven segment decoder.

Hardware Requirements:

• Raspberry Pi 4 Model B (w/ Monitor, Keyboard & Mouse)

• Breadboard

• 4 Single Pole Double Throw (SPDT) Switches

• Breadboard Wires

• Common Cathode Seven Segment Display (Common Anode version is also possible)

• 330 Ω Resistors

[GPIO & Seven Segment Display]

1. Raspberry Pi GPIO:

Observe the Raspberry Pi 4 Model B Pinout below in fig. 1. There are several things that must be considered before accessing the GPIO. Note that certain pins have dual functions in addition to being a GPIO pin, for example, GPIO 10 can also be programmed to be the MOSI line in SPI communication. Also notice the locations of the power and ground pins and that there are two different supply levels: +5 V and +3.3 V. Even though there are +5V pins, the Raspberry Pi operates using the 3.3 V logic level! Don’t be confused with the GPIO numbers (0-27) and the Raspberry Pi pin numbers (1-40)!!

Figure 1 Raspberry Pi 4 Model B Pinout and Pin interfaces

We can configure these pins using Node-RED by utilizing the GPIO node library. Recall that the nodes are located on the lefthand side panel. Scroll down until you see the Raspberry Pi section, and you will see the following nodes as shown in fig. 2.

Figure 2 Raspberry Pi nodes

We will focus on the top two nodes, “rpi – gpio in” and “rpi – gpio out” ,which configure a pin as an input or output. Drag the “rpi – gpio out” node onto the workspace and double click the node. You should see a window shown in fig. 3. In this window you can select which of the GPIO pins you want to map to. Under “Type” you have an option to set the output as regular bit output (HIGH/LOW) or a PWM output. In this lab we will use the regular “Digital Output” option.

Figure 3 Raspberry Pi GPIO output properties

In later labs, to configure the pin as GPIO input modes, you must select an option for a pull-up or pull-down resistor or none. You will see the GPIO input properties shown in fig.4.

Figure 4 Raspberry Pi GPIO Input properties

2. Seven Segment Display:

Study your common cathode seven segment display’s pinout in its datasheet. The most common pinout is shown in fig. 5, but yours might be different. Also if your segment display is common anode type, the ground connection should be to Vcc.

Figure 5 Common Cathode Seven Segment Display Pinout - this can be vary by each product

Your task is to create a binary to seven segment decoder, where four switches will represent each binary bit counting up to 15 or “A” in hexadecimal. With these four bits, you must decode the resulting number to a seven segment display. For example, “0001” should decode to “1” on the seven segment display, and “1111” should decode to “F”. See table 1 for exact details.

Table 1:

Binary to Seven Segment Conversion

Binary Number                          Seven Segment Display

0000                                  “0”

0001                                   “1”

0010                                    “2”

0011                                    “3”

0100                                    “4”

0101                                    “5”

0110                                    “6”

0111                                    “7”

1000                                    “8”

1001                                     “9”

1010                                     “A”

1011                                     “B”

1100                                     “C”

1101                                     “D”

1110                                      “E”

1111                                      “F”

[Node-RED implementation]

Observe the following fig. 6. You must obtain the inputs from the switches using the GPIO nodes, then convert them into flow variables to be called in the “Binary to SS Decoder” Function. The hardware schematic using a common cathode segment display is provided in Fig. 7.

Figure 6 Node-RED implementation examples with Rasberry Pi GPIOs

Figure 7 Hardware Schematic with a common cathod segment led

From the fig.6, the “Binary to SS Decoder” function then outputs Boolean values to be sent to the output GPIO nodes. The code for “Binary to SS Decoder” is provided below for your reference (not for copy and paste). Study the code, and note the flow variable names, and make sure you match those names to the outputs of the set/switch nodes. The GPIO pins to be used as inputs and outputs you use are free for you to choose. Also, the code can be greatly simplified, again, the code is for your reference, feel free to edit the code.

// Variable Initilization var bit0 = flow.get("bit0"); var bit1 = flow.get("bit1"); var bit2 = flow.get("bit2"); var bit3 = flow.get("bit3"); var seg_a = {payload: null}; var seg_b = {payload: null}; var seg_d = {payload: null}; var msg_d = {payload: null}; var seg_e = {payload: null}; var seg_f = {payload: null}; var seg_g = {payload: null}; // Display "1" if (bit0 == true && bit1 == false && bit2 == false && bit3 == false) { seg_a = {payload: false}; seg_b = {payload: true}; seg_d = {payload: true}; msg_d = {payload: false}; seg_e = {payload: false}; seg_f = {payload: false}; seg_g = {payload: false}; } // Display "2" else if (bit0 == false && bit1 == true && bit2 == false && bit3 == false) { seg_a = {payload: true}; seg_b = {payload: true}; seg_d = {payload: false}; msg_d = {payload: true}; seg_e = {payload: true}; seg_f = {payload: false}; seg_g = {payload: true}; } // Display "3" else if (bit0 == true && bit1 == true && bit2 == false && bit3 == false) { seg_a = {payload: true}; seg_b = {payload: true}; seg_d = {payload: true}; msg_d = {payload: true}; seg_e = {payload: false}; seg_f = {payload: false}; seg_g = {payload: true}; } // Display "4" else if (bit0 == false && bit1 == false && bit2 == true && bit3 == false) { seg_a = {payload: false}; seg_b = {payload: true}; seg_d = {payload: true}; msg_d = {payload: false}; seg_e = {payload: false}; seg_f = {payload: true}; seg_g = {payload: true}; } // Display "5" else if (bit0 == true && bit1 == false && bit2 == true && bit3 == false) { seg_a = {payload: true}; seg_b = {payload: false}; seg_d = {payload: true}; msg_d = {payload: true}; seg_e = {payload: false}; seg_f = {payload: true}; seg_g = {payload: true}; } // Display "6" else if (bit0 == false && bit1 == true && bit2 == true && bit3 == false) { seg_a = {payload: true}; seg_b = {payload: false}; seg_d = {payload: true}; msg_d = {payload: true}; seg_e = {payload: true}; seg_f = {payload: true}; seg_g = {payload: true}; } // Display "7" else if (bit0 == true && bit1 == true && bit2 == true && bit3 == false) { seg_a = {payload: true}; seg_b = {payload: true}; seg_d = {payload: true}; msg_d = {payload: false}; seg_e = {payload: false}; seg_f = {payload: false}; seg_g = {payload: false}; } // Display "8" else if (bit0 == false && bit1 == false && bit2 == false && bit3 == true) { seg_a = {payload: true}; seg_b = {payload: true}; seg_d = {payload: true}; msg_d = {payload: true}; seg_e = {payload: true}; seg_f = {payload: true}; seg_g = {payload: true}; } // Display "9" else if (bit0 == true && bit1 == false && bit2 == false && bit3 == true) { seg_a = {payload: true}; seg_b = {payload: true}; seg_d = {payload: true}; msg_d = {payload: true}; seg_e = {payload: false}; seg_f = {payload: true}; seg_g = {payload: true}; } // Display "A" else if (bit0 == false && bit1 == true && bit2 == false && bit3 == true) { seg_a = {payload: true}; seg_b = {payload: true}; seg_d = {payload: true}; msg_d = {payload: false}; seg_e = {payload: true}; seg_f = {payload: true}; seg_g = {payload: true}; } // Display "B" else if (bit0 == true && bit1 == true && bit2 == false && bit3 == true) { seg_a = {payload: false}; seg_b = {payload: false}; seg_d = {payload: true}; msg_d = {payload: true}; seg_e = {payload: true}; seg_f = {payload: true}; seg_g = {payload: true}; } // Display "C" else if (bit0 == false && bit1 == false && bit2 == true && bit3 == true) { seg_a = {payload: true}; seg_b = {payload: false}; seg_d = {payload: false}; msg_d = {payload: true}; seg_e = {payload: true}; seg_f = {payload: true}; seg_g = {payload: false}; } // Display "D" else if (bit0 == true && bit1 == false && bit2 == true && bit3 == true) { seg_a = {payload: false}; seg_b = {payload: true}; seg_d = {payload: true}; msg_d = {payload: true}; seg_e = {payload: true}; seg_f = {payload: false}; seg_g = {payload: true}; } // Display "E" else if (bit0 == false && bit1 == true && bit2 == true && bit3 == true) { seg_a = {payload: true}; seg_b = {payload: false}; seg_d = {payload: false}; msg_d = {payload: true}; seg_e = {payload: true}; seg_f = {payload: true}; seg_g = {payload: true}; } // Display "F" else if (bit0 == true && bit1 == true && bit2 == true && bit3 == true) { seg_a = {payload: true}; seg_b = {payload: false}; seg_d = {payload: false}; msg_d = {payload: false}; seg_e = {payload: true}; seg_f = {payload: true}; seg_g = {payload: true}; } // Display "0" else { seg_a = {payload: true}; seg_b = {payload: true}; seg_d = {payload: true}; msg_d = {payload: true}; seg_e = {payload: true}; seg_f = {payload: true}; seg_g = {payload: false}; } return [seg_a, seg_b, seg_d, msg_d, seg_e, seg_f, seg_g];

Note that the power and ground lines are from the Raspberry Pi's outputs; you do not need external power supplies for your circuit.

Below (fig.8) segment display’s schematic and connections are for the common anode type. Observe the common anode connection – the connected resister values can vary, typically 200-500Ω.

Figure 8 Common anode segment display connections and pinouts

[Submission]

Once you complete the flow,

1. Export it as a .JSON file and submit the file in the Brightspace assignment folder.

2. Make a short video (50sec ~1min) to demonstrate the functionality. Just provide the video link for me to check (do not upload the video to Brightspace directly, otherwise some penalty will apply).




软件开发、广告设计客服
  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp
热点标签

联系我们 - QQ: 9951568
© 2021 www.rj363.com
软件定制开发网!