Skip to content

Commit

Permalink
add hbridge
Browse files Browse the repository at this point in the history
  • Loading branch information
tonygilkerson committed Mar 16, 2024
1 parent a5cf578 commit 3b5e330
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 51 deletions.
63 changes: 54 additions & 9 deletions cmd/soil/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package main
import (
"log"
"machine"
"math"
// "math"
"runtime"
"time"

Expand All @@ -23,6 +23,9 @@ func main() {
//
// Named PINs
//
var hBridgeEnable machine.Pin = machine.GP6
var hBridgeIn1 machine.Pin = machine.GP7
var hBridgeIn2 machine.Pin = machine.GP8
var tm1637CLK machine.Pin = machine.GP10
var tm1637DIO machine.Pin = machine.GP11
var soilSDA machine.Pin = machine.GP12
Expand All @@ -39,8 +42,8 @@ func main() {
var led machine.Pin = machine.GPIO25 // GP25 machine.LED

const (
HEARTBEAT_DURATION_SECONDS = 15
TXRX_LOOP_TICKER_DURATION_SECONDS = 10
HEARTBEAT_DURATION_SECONDS = 3
TXRX_LOOP_TICKER_DURATION_SECONDS = 7
)

//
Expand All @@ -50,6 +53,14 @@ func main() {
dsp.RunLight(led, 10)
log.SetFlags(log.LstdFlags | log.Lshortfile)

//
// Configure L293D
//
log.Println("Configure L293D Pins")
hBridgeEnable.Configure(machine.PinConfig{Mode: machine.PinOutput})
hBridgeIn1.Configure(machine.PinConfig{Mode: machine.PinOutput})
hBridgeIn2.Configure(machine.PinConfig{Mode: machine.PinOutput})

//
// Configure 4 digit 7-segment display
//
Expand Down Expand Up @@ -82,6 +93,7 @@ func main() {
//
ticker := time.NewTicker(time.Second * HEARTBEAT_DURATION_SECONDS)
var count int
x :="off"

for range ticker.C {

Expand All @@ -104,12 +116,45 @@ func main() {
log.Printf("Temperature (F): %v\n", t)
time.Sleep(time.Second)

// alternate between displaying the moisture and temperature
if math.Mod(float64(count), 2) == 0 {
tm.DisplayNumber(int16(m))
} else {
tm.DisplayNumber(int16(t))
}
// // alternate between displaying the moisture and temperature
// if math.Mod(float64(count), 2) == 0 {
// tm.DisplayNumber(int16(m))
// } else {
// tm.DisplayNumber(int16(t))
// }

// temp for testing hbridge
switch x {
case "off":
x = "cw"
log.Println("0-off")
hBridgeEnable.Low()
hBridgeIn1.Low()
hBridgeIn2.Low()
tm.DisplayNumber(0)
case "cw":
x = "ccw"
log.Println("1-CW")
hBridgeEnable.High()
hBridgeIn1.High()
hBridgeIn2.Low()
tm.DisplayNumber(1)
case "ccw":
x = "off"
log.Println("2-CCW")
hBridgeEnable.High()
hBridgeIn1.Low()
hBridgeIn2.High()
tm.DisplayNumber(2)
default:
log.Println("8-default")
hBridgeEnable.Low()
hBridgeIn1.Low()
hBridgeIn2.Low()
tm.DisplayNumber(8)

}


//
// Let someone else have a turn
Expand Down
87 changes: 45 additions & 42 deletions cmd/soil/wiring.md
Original file line number Diff line number Diff line change
@@ -1,47 +1,50 @@
# Wiring

| Pico Board Pin | Pico GPIO | Lora Breakout Board | Charger | Soil Sensor | 7-segment display |
| -------------- | -------------- | ------------------- | ------- | ----------- | ----------------- |
| 1 | GP0 (UART0 TX) | | | | |
| 2 | GP1 (UART0 RX) | | | | |
| 3 | GND | | | | |
| 4 | GP2 | | | | |
| 5 | GP3 | | | | |
| 6 | GP4 | | | | |
| 7 | GP5 | | | | |
| 8 | GND | | | | |
| 9 | GP6 | | | | |
| 10 | GP7 | | | | |
| 11 | GP8 | | | | |
| 12 | GP9 | | | | |
| 13 | GND | | | | GND (black) |
| 14 | GP10 | | | | CLK (yellow) |
| 15 | GP11 | | | | DIO (white) |
| 16 | GP12 | | | SDA(White) | |
| 17 | GP13 | | | SCL(Green) | |
| 18 | GND | | | GND (Black) | |
| 19 | GP14 | | | | |
| 20 | GP15 | EN | | | |
| 21 | GP16 | MISO (SPI0) | | | |
| 22 | GP17 | CS | | | |
| 23 | GND | | GND | | |
| 24 | GP18 | SCK (SPI0) | | | |
| 25 | GP19 | MOSI (SPI0) | | | |
| 26 | GP20 | RST | | | |
| 27 | GP21 | G0 | | | |
| 28 | GND | | | | |
| 29 | GP22 | G1 | | | |
| 30 | RUN | | | | |
| 31 | GP26 | | | | |
| 32 | GP27 | | | | |
| 33 | GND | | | | |
| 34 | GP28 | | | | |
| 35 | ACD_VREF | | | | |
| 36 | 3v3 (out) | VIN | | VIN (Red) | VIN (red) |
| 37 | 3v3 (EN) | | | | |
| 38 | GND | GND | | | |
| 39 | 5v0 (VSYS) | | 5V | | |
| 40 | 5v0 (VBUS) | | | | |
| Pico Board Pin | Pico GPIO | Lora Breakout Board | Charger | Soil Sensor | 7-segment display | L293D | Solenoid | 9v Battery |
| -------------- | -------------- | ------------------- | ------- | ----------- | ----------------- | -------------- | ---------- | ------------ |
| 1 | GP0 (UART0 TX) | | | | | | | |
| 2 | GP1 (UART0 RX) | | | | | | | |
| 3 | GND | | | | | Pin-4 (GND) | | |
| 4 | GP2 | | | | | | | |
| 5 | GP3 | | | | | | | |
| 6 | GP4 | | | | | | | |
| 7 | GP5 | | | | | | | |
| 8 | GND | | | | | Pin-5 (GND) | | |
| 9 | GP6 | | | | | Pin-1 (Enable) | | |
| 10 | GP7 | | | | | Pin-2 (In1) | | |
| 11 | GP8 | | | | | Pin-7 (In2) | | |
| 12 | GP9 | | | | | | | |
| 13 | GND | | | | GND (black) | | | |
| 14 | GP10 | | | | CLK (yellow) | | | |
| 15 | GP11 | | | | DIO (white) | | | |
| 16 | GP12 | | | SDA(White) | | | | |
| 17 | GP13 | | | SCL(Green) | | | | |
| 18 | GND | | | GND (Black) | | | | |
| 19 | GP14 | | | | | | | |
| 20 | GP15 | EN | | | | | | |
| 21 | GP16 | MISO (SPI0) | | | | | | |
| 22 | GP17 | CS | | | | | | |
| 23 | GND | | GND | | | | | |
| 24 | GP18 | SCK (SPI0) | | | | | | |
| 25 | GP19 | MOSI (SPI0) | | | | | | |
| 26 | GP20 | RST | | | | | | |
| 27 | GP21 | G0 | | | | | | |
| 28 | GND | | | | | | | |
| 29 | GP22 | G1 | | | | | | |
| 30 | RUN | | | | | | | |
| 31 | GP26 | | | | | | | |
| 32 | GP27 | | | | | | | |
| 33 | GND | | | | | | | |
| 34 | GP28 | | | | | | | |
| 35 | ACD_VREF | | | | | | | |
| 36 | 3v3 (out) | VIN | | VIN (Red) | VIN (red) | | | |
| 37 | 3v3 (EN) | | | | | | | |
| 38 | GND | GND | | | | Pin-13 (GND) | | Neg terminal |
| 39 | 5v0 (VSYS) | | 5V | | | Pin-16 (VSS) | | |
| 40 | 5v0 (VBUS) | | | | | | | |
| | | | | | | Pin-8 (VSmot) | | Pos terminal |
| | | | | | | Pin-3 (Out1) | Terminal A | |
| | | | | | | Pin-6 (Out2) | Terminal B | |

Not exposed as board pins

Expand Down

0 comments on commit 3b5e330

Please sign in to comment.