3 Simple Ways to
Share What You Make

With Instructables you can share what you make with the world — and tap into an ever-growing community of creative experts.

PhotosPhotos

Share one or more photos of a project, recipe, or whatever you've made, quickly and easily.

Step by StepStep-By-Step

Share your step-by-step photos with text instructions of what you made so others can do it too!

VideoVideo

Share your how-to video. You'll need your embed code from a video site such as YouTube.


Build your own Wifi radio

Step 9Code

Code
I'll just add the full code here. It is a bit messy as I didn't have any time left to clean it up. When I've cleaned it up (and improved it), I'll post the new code. I'll also add the pictures here that I used so that you can use them too.

When you program your Atmega, you should also disable JTAG in the fusebits and set the internal oscillator to 8MHz.

The code will fit into an Atmega16 but I used an Atmega32 as I want to add some extra features later.


$regfile = "m32def.dat"
$crystal = 8000000
$baud = 9600

Config Serialin = Buffered , Size = 255
Config Serialout = Buffered , Size = 100
Config Graphlcd = 240 * 128 , Dataport = Porta , Controlport = Portc , Ce = 5 , Cd = 4 , Wr = 7 , Rd = 6 , Reset = 2 , Fs = 3 , Mode = 8

Config Scl = Portc.0
Config Sda = Portc.1

Cha Alias Pind.3
Chb Alias Pind.4

Config Cha = Input
Config Chb = Input

Const Ds1307w = &HD0 'write DS1307
Const Ds1307r = &HD1 'read ds1307
Const Adsecs = &H00 'address seconds
Const Admins = &H01 'address minutes

Dim Count As Byte
Dim I As Byte
Dim J As Byte
Dim Pos As Byte
Dim Oldpos As Byte
Dim Maxpos As Byte
Dim State As Byte
Dim Volume As Byte
Dim Temp As Byte
Dim Uart_in As Byte
Dim Uart_buffer As Byte
Dim Hours As Byte
Dim Mins As Byte
Dim Secs As Byte
Dim Length As Byte
Dim Boxx As Byte
Dim Boxx2 As Byte
Dim Tube(4) As Byte
Dim X As Byte

Dim Uart_in_str As String * 255
Dim Stationname As String * 60
Dim Title As String * 60
Dim Station_pos As Byte
Dim Title_pos As Byte
Dim Pointer As Byte
Dim Station_length As Byte
Dim Title_length As Byte
Dim Temp_str As String * 4
Dim Volumestr As String * 3
Dim Station(20) As String * 30
On Int0 0int
Enable Int0
Enable Interrupts

'Set Chb

On Int1 1int ,
Enable Int1
Enable Interrupts

Wait 1
Cls

Init:
Showpic 0 , 0 , Intro
Box(115 , 90) -(200 , 104) , 255

For I = 118 To 194 Step 4

J = I + 3
Boxfill(i , 92) -(j , 102) , 255
Wait 3

Next
Print Chr(13)
Wait 2
Print "mpc clear"
For I = 0 To 3
Stationname = Lookupstr(i , Tunerlist2)
Print "mpc add " ; Stationname
Next
Print "mpc volume 50"
Print "mpc play"
Volume = 20
Gosub Empty_buffer
I = 1
Count = 1
Main:
State = I
Cls
If State = 1 Then Goto Radio
If State = 2 Then Goto Tuning
If State = 3 Then Goto Vol
If State = 4 Then Goto Setup

Radio:

Maxpos = 6
Pos = 1
Oldpos = 1
Boxx = 0
Boxx2 = 40

Showpic 0 , 88 , Play
Showpic 40 , 88 , Pause
Showpic 80 , 88 , Stopp
Showpic 120 , 88 , Volume
Showpic 160 , 88 , Tuner
Showpic 200 , 88 , Clock
Box(0 , 88) -(40 , 127) , 255



Do
If I <> State Then Goto Main
If Pos <> Oldpos Then
Box(boxx , 88) -(boxx2 , 127) , 0
Boxx = Pos - 1
Boxx = Boxx * 40
Boxx2 = Boxx + 40
Box(boxx , 88) -(boxx2 , 127) , 255
Oldpos = Pos
End If

Print "echo " ; Chr(34) ; "currentsong" ; Chr(34) ; " | nc localhost 6600 | grep -e " ; Chr(34) ; "^Title: " ; Chr(34) ; " -e " ; Chr(34) ; "^Name: " ; Chr(34) ; " > /dev/tts/0" ; Chr(13)
Waitms 500
Gosub Getuart
Gosub Parser
Cls Text
Locate 5 , 1
Lcd Stationname
Locate 8 , 1
Lcd Title

Gosub Readclock
Loop

Tuning:

Cls
Count = 1
Do
Cls Text
If I <> State Then Goto Main
Gosub Readclock

For J = 1 To 4
Station(j) = Lookupstr(j , Tunerlist)
Next
J = Count
Locate 5 , 5
Lcd Station(j)
J = Count + 1
Locate 6 , 5
Lcd Station(j)
J = Count + 2
Locate 7 , 5
Lcd Station(j)
Waitms 500
Loop

Vol:
Cls
Do
Gosub Readclock
If I <> State Then Goto Main
Print "echo " ; Chr(34) ; "status" ; Chr(34) ; " | nc localhost 6600 | grep -e " ; Chr(34) ; "^volume: " ; Chr(34) ; " > /dev/tts/0" ; Chr(13)
Waitms 100
Gosub Getuart
Gosub Volumeparser
Cls Text
Locate 6 , 10
Volume = Val(volumestr)
Lcd "Volume: " ; Volume

Loop

Setup:
J = 1
If J = 1 Then Count = Hours Else Count = Mins
Cls
Do
Cls
If I <> State Then Goto Main

'Gosub Readclock

If J = 1 Then Hours = Count Else Mins = Count


Tube(2) = Mins / 10 'splits the hours and minutes into
Temp = Tube(2) * 10 '4 digits so that it can be displayed
Tube(1) = Mins - Temp
Tube(4) = Hours / 10
Temp = Tube(4) * 10
Tube(3) = Hours - Temp

Temp = Tube(4)
X = 48
Gosub Clockpic
Temp = Tube(3)
X = 72
Gosub Clockpic
Temp = 11
X = 96
Gosub Clockpic
Temp = Tube(2)
X = 120
Gosub Clockpic
Temp = Tube(1)
X = 144
Gosub Clockpic


Locate 8 , 8
Lcd I
Waitms 100
Loop

End

0int:


If I = 1 And Pos = 1 Then Print "mpc play"
If I = 1 And Pos = 2 Then Print "mpc pause"
If I = 1 And Pos = 3 Then Print "mpc stop"
If I = 1 And Pos = 4 Then I = 3

If I = 1 And Pos = 6 Then I = 4
If State = 2 Then
Print "mpc play " ; Count
I = 1
End If
If I = 1 And Pos = 5 Then I = 2
Waitms 100
If State = 3 Then I = 1
If I = 4 And J = 2 Then
Gosub Setclock
I = 1
End If
If I = 4 And J = 1 Then
Gosub Setclock
J = 2
End If
Return

1int:
Waitms 1
If Cha = 1 And I <> 3 Then
If Chb = 0 Then Incr Count Else Decr Count
End If
If Cha = 1 And I = 3 Then
If Chb = 0 Then Print "mpc volume +5" Else Print "mpc volume -5"
End If
Pos = Count
If Pos > Maxpos Then Pos = Maxpos
If Pos < 1 Then Pos = 1

Return

Getuart:
Uart_in_str = ""
Do
Uart_buffer = Ischarwaiting()
If Uart_buffer > 0 Then
Uart_in = Inkey()
If Len(uart_in_str) < 254 Then Uart_in_str = Uart_in_str + Chr(uart_in)
If Len(uart_in_str) = 254 Then Uart_in_str = Uart_in_str + Chr(13)
End If
Loop Until Uart_buffer = 0
Gosub Empty_buffer
Return
Volumeparser:

Volumestr = ""
Temp = Instr(uart_in_str , "volume: ")
Temp = Temp + 8
Volumestr = Mid(uart_in_str , Temp , 3)

Return
Parser:

Stationname = ""
Title = ""
Station_pos = Instr(uart_in_str , "Name: ")
Title_pos = Instr(uart_in_str , "Title: ")


Station_pos = Station_pos + 6
Length = 0
Do
Incr Length
Pointer = Station_pos + Length
Temp_str = Mid(uart_in_str , Pointer , 1)
Loop Until Temp_str = Chr(13) Or Temp_str = ""
If Length > 60 Then Length = 60
Stationname = Mid(uart_in_str , Station_pos , Length)



Title_pos = Title_pos + 7

Length = 0
Do
Incr Length
Pointer = Title_pos + Length
Temp_str = Mid(uart_in_str , Pointer , 1)
Loop Until Temp_str = Chr(13) Or Temp_str = ""
If Length > 60 Then Length = 60
Title = Mid(uart_in_str , Title_pos , Length)

If Station_pos = 6 Then Stationname = "Name not found!"
If Title_pos = 7 Then Title = "Title not found!"

Return

Empty_buffer:

Do
Uart_in = Inkey()
Uart_buffer = Ischarwaiting()
Loop Until Uart_buffer = 0
Return

Readclock:

I2cstart
I2cwbyte Ds1307w
I2cwbyte Admins
I2cstop
I2cstart
I2cwbyte Ds1307r
I2crbyte Mins , Ack
I2crbyte Hours , Nack


Hours = Hours And &B00111111 'removes bit6 & bit7

Hours = Makedec(hours) 'converts BCD into Decimal
Mins = Makedec(mins)


Tube(2) = Mins / 10 'splits the hours and minutes into
Temp = Tube(2) * 10 '4 digits so that it can be displayed
Tube(1) = Mins - Temp
Tube(4) = Hours / 10
Temp = Tube(4) * 10
Tube(3) = Hours - Temp

Temp = Tube(4)
X = 48
Gosub Clockpic
Temp = Tube(3)
X = 72
Gosub Clockpic
Temp = 11
X = 96
Gosub Clockpic
Temp = Tube(2)
X = 120
Gosub Clockpic
Temp = Tube(1)
X = 144
Gosub Clockpic

Return

Setclock:

Mins = Makebcd(mins)
Hours = Makebcd(hours)
Reset Hours.6
I2cstart
I2cwbyte Ds1307w
I2cwbyte Adsecs
I2cwbyte &B00000000
I2cwbyte Mins
I2cwbyte Hours
I2cstop

Hours = Hours And &B00111111 'removes bit6 & bit7

Hours = Makedec(hours) 'converts BCD into Decimal
Mins = Makedec(mins)

Return
Clockpic:

If Temp = 1 Then Showpic X , 0 , 1
If Temp = 2 Then Showpic X , 0 , 2
If Temp = 3 Then Showpic X , 0 , 3
If Temp = 4 Then Showpic X , 0 , 4
If Temp = 5 Then Showpic X , 0 , 5
If Temp = 6 Then Showpic X , 0 , 6
If Temp = 7 Then Showpic X , 0 , 7
If Temp = 8 Then Showpic X , 0 , 8
If Temp = 9 Then Showpic X , 0 , 9
If Temp = 0 Then Showpic X , 0 , 0
If Temp = 11 Then Showpic X , 0 , Dp


Return
Intro:
$bgf "wifiradio.bgf"
Play:
$bgf "play.bgf"
Pause:
$bgf "pause.bgf"
Stopp:
$bgf "stop.bgf"
Volume:
$bgf "volume.bgf"
Tuner:
$bgf "tuner.bgf"
Clock:
$bgf "clock.bgf"
0:
$bgf "0.bgf"
1:
$bgf "1.bgf"
2:
$bgf "2.bgf"
3:
$bgf "3.bgf"
4:
$bgf "4.bgf"
5:
$bgf "5.bgf"
6:
$bgf "6.bgf"
7:
$bgf "7.bgf"
8:
$bgf "8.bgf"
9:
$bgf "9.bgf"
Dp:
$bgf "dp.bgf"
Streep:
$bgf "streep.bgf"
Tunerlist:

Data " " , "1920 Network" , "KCEA" , "FM Tango Junin Argentina" , "TANGOCLUB"

Tunerlist2:

Data "http://64.5.130.43:80" , "http://198.182.76.2:8000" , "http://200.58.116.222:10580" , http://190.245.64.194:8000
« Previous StepDownload PDFView All StepsNext Step »

Pro

Get More Out of Instructables

Already have an Account?

close

All Steps Viewing
View all steps of an Instructable on the same page when you're a Pro Member.

Upgrade to Pro today!
91
Followers
25
Author:janw
My hobbies are mainly music and electronics but I like to read and learn about a lot more than that.