Repository navigation
Smt_Microcom_sample
Ko-ichiro Sugiyama edited this page Jan 28, 2026
·
7 revisions
gpio13 = GPIO.new( 13, GPIO::OUT )
gpio12 = GPIO.new( 12, GPIO::OUT )
loop do
gpio13.write( 1 )
gpio12.write( 0 )
sleep(1)
gpio13.write( 0 )
gpio12.write( 1 )
sleep(1)
end
gpio13 = GPIO.new( 13, GPIO::OUT )
gpio12 = GPIO.new( 12, GPIO::OUT )
gpio34 = GPIO.new( 34, GPIO::IN )
loop do
if gpio34.read == 0
gpio13.write( 1 )
gpio12.write( 0 )
sleep(1)
gpio13.write( 0 )
gpio12.write( 1 )
sleep(1)
else
gpio13.write( 0 )
gpio12.write( 0 )
end
sleep(0.01)
end
pwm13 = PWM.new( 13, timer:0, frequency:1000 )
pwm12 = PWM.new( 12, timer:0, frequency:1000 )
pwm14 = PWM.new( 14, timer:0, frequency:1000 )
pwm15 = PWM.new( 15, timer:1, frequency:1000 )
pwm15.frequency( 440 )
pwm15.duty( 50 )
sleep(1)
pwm15.duty( 0 )
pwm13.duty( 100 )
pwm12.duty( 50 )
pwm14.duty( 10 )
adc39 = ADC.new( 39 )
loop do
puts( adc39.read )
sleep(1)
end
i2c = I2C.new( scl_pin:22, sda_pin:21 )
i2c.write( 0x3E, 0x00, 0x38 )
i2c.write( 0x3E, 0x00, 0x39 )
i2c.write( 0x3E, 0x00, 0x14 )
i2c.write( 0x3E, 0x00, 0x70 )
i2c.write( 0x3E, 0x00, 0x56 )
i2c.write( 0x3E, 0x00, 0x6C )
sleep(0.1)
i2c.write( 0x3E, 0x00, 0x38 )
i2c.write( 0x3E, 0x00, 0x0C )
i2c.write( 0x3E, 0x00, 0x01 )
sleep(0.1)
i2c.write( 0x3E, 0x40, "H".ord )
i2c.write( 0x3E, 0x40, "E".ord )
i2c.write( 0x3E, 0x40, "L".ord )
i2c.write( 0x3E, 0x40, "L".ord )
i2c.write( 0x3E, 0x40, "O".ord )
i2c = I2C.new( scl_pin:22, sda_pin:21 )
i2c.write( 0x32, 0xE0, 0x38 )
i2c.write( 0x32, 0xF0, 0x39 )
i2c.write( 0x32, 0x00, 0x40 ) #秒
i2c.write( 0x32, 0x01, 0x50 ) #分
i2c.write( 0x32, 0x20, 0x01 ) #時
i2c.write( 0x32, 0x30, 0x06 ) #曜日
i2c.write( 0x32, 0x40, 0x27 ) #日
i2c.write( 0x32, 0x50, 0x12 ) #月
i2c.write( 0x32, 0x60, 0x25 ) #年
i2c.write( 0x32, 0xF0, 0x00 )
sleep(0.1)
loop do
$var = i2c.read( 0x32, 7, 0x00 ).bytes
puts( $var[6].to_s(16) + "年" )
puts( $var[5].to_s(16) + "月" )
puts( $var[4].to_s(16) + "日" )
puts( $var[3].to_s(16) + "曜日" )
puts( $var[2].to_s(16) + "時" )
puts( $var[1].to_s(16) + "分" )
puts( $var[0].to_s(16) + "秒" )
sleep(10)
end
puts( "*********************" )
puts( " UART check (GPS) " )
puts( "*********************" )
gpio5 = GPIO.new( 5, GPIO::OUT )
gpio5.write( 0 )
uart2 = UART.new( 2, baudrate:9600 )
sleep(1)
uart2.puts( "$PMTK314,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0*29" )
puts( "------ Loop Start -----" )
loop do
sleep(3)
$items = uart2.gets().split(",")
$num = $items.size
if $num == 13
puts( $items )
else
puts( "XXXXX" )
end
uart2.clear_tx_buffer()
sleep(7)
endspi = SPI.new(miso_pin:19, mosi_pin:23, clk_pin:18)
sdspi = SDSPI.new(spi, cs_pin:2, mount_point: '/sd')
puts "-----puts-----"
f1 = File.open("/sd/herohero.txt", "w")
f1.puts("Hello mruby/c!")
f1.close
f2 = File.open("/sd/herohero.txt", "a")
f2.puts("Hi, mruby/c!\n")
f2.close
f2 = File.open("/sd/herohero.txt", "a")
f2.puts("Kon-nichiwa, mruby/c!")
f2.close
puts "-----read-----"
f4 = File.open("/sd/herohero.txt", "r")
puts f4.read
f4.close
puts "-----gets-----"
f5 = File.open("/sd/herohero.txt", "r")
while (text = f5.gets)
puts text
end
f5.close
puts "-------------"
# rename bar.txt to piyo.txt
File.rename("/sd/herohero.txt", "/sd/hogehero.txt")
puts Dir.childrenFiles("/sd")
puts ""
puts Dir.childrenDirs("/sd")
puts ""
puts Dir.children("/sd")
puts ""
puts "-------------"
File.delete("/sd/herohero.txt")
File.delete("/sd/hogehero.txt")
puts Dir.childrenFiles("/sd")
puts ""
# Clear up.
sdspi.umount
i2c = I2C.new( scl_pin:22, sda_pin:21 )
aqm0802a = AQM0802A.new(i2c)
dps310 = DPS310.new(i2c)
$my_variable = 0
loop do
dps310.read
if dps310.pressure > $my_variable
$my_variable = dps310.pressure
end
aqm0802a.cursor(line: 1)
aqm0802a.print(" ")
aqm0802a.cursor(line: 1)
aqm0802a.print(dps310.pressure)
aqm0802a.cursor(line: 2)
aqm0802a.print(" ")
aqm0802a.cursor(line: 2)
aqm0802a.print($my_variable)
sleep(1)
end