Пример #1
0
func main() {
	flag.Parse()

	if err := embd.InitI2C(); err != nil {
		panic(err)
	}
	defer embd.CloseI2C()

	bus := embd.NewI2CBus(1)

	sensor := tmp006.New(bus, 0x40)
	if status, err := sensor.Present(); err != nil || !status {
		fmt.Println("tmp006: not found")
		fmt.Println(err)
		return
	}
	defer sensor.Close()

	sensor.Start()

	stop := make(chan os.Signal, 1)
	signal.Notify(stop, os.Interrupt, os.Kill)

	for {
		select {
		case temp := <-sensor.ObjTemps():
			fmt.Printf("tmp006: got obj temp %.2f\n", temp)
		case temp := <-sensor.RawDieTemps():
			fmt.Printf("tmp006: got die temp %.2f\n", temp)
		case <-stop:
			return
		}
	}
}
Пример #2
0
func main() {
	flag.Parse()

	if err := embd.InitI2C(); err != nil {
		panic(err)
	}
	defer embd.CloseI2C()

	bus := embd.NewI2CBus(1)

	gyro := l3gd20.New(bus, l3gd20.R250DPS)
	defer gyro.Close()

	gyro.Start()

	quit := make(chan os.Signal, 1)
	signal.Notify(quit, os.Interrupt, os.Kill)

	orientations, err := gyro.Orientations()
	if err != nil {
		panic(err)
	}

	timer := time.Tick(250 * time.Millisecond)

	for {
		select {
		case <-timer:
			orientation := <-orientations
			fmt.Printf("x: %v, y: %v, z: %v\n", orientation.X, orientation.Y, orientation.Z)
		case <-quit:
			return
		}
	}
}
Пример #3
0
func main() {
	flag.Parse()

	if err := embd.InitI2C(); err != nil {
		panic(err)
	}
	defer embd.CloseI2C()

	bus := embd.NewI2CBus(1)

	dac := mcp4725.New(bus, 0x62)
	defer dac.Close()

	stop := make(chan os.Signal, 1)
	signal.Notify(stop, os.Interrupt, os.Kill)

	for {
		select {
		case <-stop:
			return
		default:
			voltage := rand.Intn(4096)
			if err := dac.SetVoltage(voltage); err != nil {
				fmt.Printf("mcp4725: %v\n", err)
			}
		}
	}
}
Пример #4
0
func main() {
	flag.Parse()

	if err := embd.InitI2C(); err != nil {
		panic(err)
	}
	defer embd.CloseI2C()

	bus := embd.NewI2CBus(1)

	baro := bmp085.New(bus)
	defer baro.Close()

	for {
		temp, err := baro.Temperature()
		if err != nil {
			panic(err)
		}
		fmt.Printf("Temp is %v\n", temp)
		pressure, err := baro.Pressure()
		if err != nil {
			panic(err)
		}
		fmt.Printf("Pressure is %v\n", pressure)
		altitude, err := baro.Altitude()
		if err != nil {
			panic(err)
		}
		fmt.Printf("Altitude is %v\n", altitude)

		time.Sleep(500 * time.Millisecond)
	}
}
Пример #5
0
func main() {
	flag.Parse()

	if err := embd.InitI2C(); err != nil {
		panic(err)
	}
	defer embd.CloseI2C()

	bus := embd.NewI2CBus(1)

	pca9955b := pca9955b.New(bus, 0x0B)

	pca9955b.Reset()

	fmt.Println("running in cycle")
	for {
		for x := 0; x < 256; x++ {
			if err := pca9955b.SetOutput(byte(7), byte(x)); err != nil {
				panic(err)
			}
		}
		for x := 255; x > 0; x-- {
			if err := pca9955b.SetOutput(byte(7), byte(x)); err != nil {
				panic(err)
			}
		}
	}
}
Пример #6
0
func main() {
	flag.Parse()

	if err := embd.InitI2C(); err != nil {
		panic(err)
	}
	defer embd.CloseI2C()

	bus := embd.NewI2CBus(1)

	controller, err := hd44780.NewI2C(
		bus,
		0x20,
		hd44780.PCF8574PinMap,
		hd44780.RowAddress20Col,
		hd44780.TwoLine,
		hd44780.BlinkOn,
	)
	if err != nil {
		panic(err)
	}

	display := characterdisplay.New(controller, 20, 4)
	defer display.Close()

	display.Clear()
	display.Message("Hello, world!\n@embd | characterdisplay")
	time.Sleep(10 * time.Second)
	display.BacklightOff()
}
Пример #7
0
func main() {
	flag.Parse()

	if err := embd.InitI2C(); err != nil {
		panic(err)
	}
	defer embd.CloseI2C()

	bus := embd.NewI2CBus(1)

	sensor := ads1115.New(bus, 0x48)

	if res, err := sensor.Read(); err != nil {
		panic(err)
	} else {
		fmt.Printf("Converted value: %04X\n", res)
	}
}
Пример #8
0
func main() {
	flag.Parse()

	if err := embd.InitI2C(); err != nil {
		panic(err)
	}
	defer embd.CloseI2C()

	bus := embd.NewI2CBus(1)

	d := pca9685.New(bus, 0x41)
	d.Freq = 50
	defer d.Close()

	pwm := d.ServoChannel(0)

	servo := servo.New(pwm)

	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt, os.Kill)

	turnTimer := time.Tick(500 * time.Millisecond)
	left := true

	servo.SetAngle(90)
	defer func() {
		servo.SetAngle(90)
	}()

	for {
		select {
		case <-turnTimer:
			left = !left
			switch left {
			case true:
				servo.SetAngle(70)
			case false:
				servo.SetAngle(110)
			}
		case <-c:
			return
		}
	}
}
Пример #9
0
func main() {
	flag.Parse()

	if err := embd.InitI2C(); err != nil {
		panic(err)
	}
	defer embd.CloseI2C()

	bus := embd.NewI2CBus(1)

	sensor := npa700.New(bus, 0x28)

	err := sensor.Read()
	if err != nil {
		panic(err)
	}

	fmt.Printf("Temp is %fC\n", sensor.Celsius())
	fmt.Printf("Temp is %fF\n", sensor.Fahrenheit())
	fmt.Printf("Pres is %fPa\n", sensor.Pascals(0, 1638, 14745, -6894.76, 6894.76))
}
Пример #10
0
func main() {
	flag.Parse()

	if err := embd.InitI2C(); err != nil {
		panic(err)
	}
	defer embd.CloseI2C()

	bus := embd.NewI2CBus(1)

	hd, err := hd44780.NewI2C(
		bus,
		0x20,
		hd44780.PCF8574PinMap,
		hd44780.RowAddress20Col,
		hd44780.TwoLine,
		hd44780.BlinkOn,
	)
	if err != nil {
		panic(err)
	}
	defer hd.Close()

	hd.Clear()
	message := "Hello, world!"
	bytes := []byte(message)
	for _, b := range bytes {
		hd.WriteChar(b)
	}
	hd.SetCursor(0, 1)

	message = "@embd | hd44780"
	bytes = []byte(message)
	for _, b := range bytes {
		hd.WriteChar(b)
	}
	time.Sleep(10 * time.Second)
	hd.BacklightOff()
}
Пример #11
0
func main() {
	flag.Parse()

	if err := embd.InitI2C(); err != nil {
		panic(err)
	}
	defer embd.CloseI2C()

	bus := embd.NewI2CBus(1)

	pca9685 := pca9685.New(bus, 0x41)
	pca9685.Freq = 1000
	defer pca9685.Close()

	if err := pca9685.SetPwm(15, 0, 2000); err != nil {
		panic(err)
	}

	c := make(chan os.Signal, 1)
	signal.Notify(c, os.Interrupt, os.Kill)

	timer := time.Tick(2 * time.Second)
	sleeping := false

	for {
		select {
		case <-timer:
			sleeping = !sleeping
			if sleeping {
				pca9685.Sleep()
			} else {
				pca9685.Wake()
			}
		case <-c:
			return
		}
	}
}
Пример #12
0
func main() {
	flag.Parse()

	if err := embd.InitI2C(); err != nil {
		panic(err)
	}
	defer embd.CloseI2C()

	bus := embd.NewI2CBus(1)

	mems := lsm303.New(bus)
	defer mems.Close()

	for {
		heading, err := mems.Heading()
		if err != nil {
			panic(err)
		}
		fmt.Printf("Heading is %v\n", heading)

		time.Sleep(500 * time.Millisecond)
	}
}
Пример #13
0
func main() {
	flag.Parse()

	if err := embd.InitI2C(); err != nil {
		panic(err)
	}
	defer embd.CloseI2C()

	bus := embd.NewI2CBus(1)

	sensor := bh1750fvi.New(bh1750fvi.High, bus)
	defer sensor.Close()

	for {
		lighting, err := sensor.Lighting()
		if err != nil {
			panic(err)
		}
		fmt.Printf("Lighting is %v lx\n", lighting)

		time.Sleep(500 * time.Millisecond)
	}
}
Пример #14
0
// NewLcd create and init new lcd output
func NewLcd() *Lcd {
	var l *Lcd
	defer func() {
		if e := recover(); e != nil {
			glog.Infof("NewLcd failed create - recover: %v", e)
		}
	}()

	l = &Lcd{
		Lines:     2,
		Width:     lcdWidth,
		lastLines: make([]string, 2, 2),
	}
	if configuration.DisplayConf.Display == "i2c" {
		l.addr = configuration.DisplayConf.I2CAddr
		glog.V(1).Infof("Starting hd44780 on i2c addr=%d", l.addr)

		if err := embd.InitI2C(); err != nil {
			glog.Error("Can't open lcd: ", err.Error())
			return nil
		}

		bus := embd.NewI2CBus(1)

		var err error
		l.hd, err = hd44780.NewI2C(
			bus,
			l.addr,
			hd44780.PCF8574PinMap,
			hd44780.RowAddress16Col,
			hd44780.TwoLine,
			//		hd44780.BlinkOff,
			hd44780.CursorOff,
			hd44780.EntryIncrement,
		)
		if err != nil {
			glog.Fatal("Can't open i2c lcd: ", err.Error())
			return nil
		}
	} else {
		glog.V(1).Infof("Starting hd44780 on GPIO")
		var err error
		l.hd, err = hd44780.NewGPIO(
			configuration.DisplayConf.GpioRs,
			configuration.DisplayConf.GpioEn,
			configuration.DisplayConf.GpioD4,
			configuration.DisplayConf.GpioD5,
			configuration.DisplayConf.GpioD6,
			configuration.DisplayConf.GpioD7,
			configuration.DisplayConf.GpioBl,
			hd44780.Positive,
			hd44780.RowAddress16Col,
			hd44780.TwoLine,
			//		hd44780.BlinkOff,
			hd44780.CursorOff,
			hd44780.EntryIncrement,
		)
		if err != nil {
			glog.Fatal("Can't open gpio lcd: ", err.Error())
			return nil
		}
	}

	l.hd.Clear()
	l.hd.BacklightOn()
	l.backlight = true

	l.active = true

	// Custom characters
	// play
	l.setChar(0, []byte{0x0, 0x8, 0xc, 0xe, 0xc, 0x8, 0x0, 0x0})
	// pause
	l.setChar(1, []byte{0x0, 0x1b, 0x1b, 0x1b, 0x1b, 0x1b, 0x0, 0x0})
	// stop
	l.setChar(2, []byte{0x0, 0x1f, 0x1f, 0x1f, 0x1f, 0x1f, 0x0, 0x0})

	return l
}