Working mbed code for the Adafruit 1958 radio transmitter. Does not include RDS support.
Dependencies: Adafruit_Si4713 TextLCD mbed
main.cpp@0:eae01b881372, 2017-01-25 (annotated)
- Committer:
- gjones20
- Date:
- Wed Jan 25 05:17:49 2017 +0000
- Revision:
- 0:eae01b881372
Working mbed code for the Adafruit 1958 radio transmitter. Does not include RDS support.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
gjones20 | 0:eae01b881372 | 1 | #include "mbed.h" |
gjones20 | 0:eae01b881372 | 2 | #include "TextLCD.h" |
gjones20 | 0:eae01b881372 | 3 | #include "Adafruit_Si4713.h" |
gjones20 | 0:eae01b881372 | 4 | |
gjones20 | 0:eae01b881372 | 5 | TextLCD lcd(p19,p20,p21,p22,p23,p24); |
gjones20 | 0:eae01b881372 | 6 | AnalogIn Ain(p18); |
gjones20 | 0:eae01b881372 | 7 | |
gjones20 | 0:eae01b881372 | 8 | InterruptIn decrease(p6); |
gjones20 | 0:eae01b881372 | 9 | InterruptIn increase(p7); |
gjones20 | 0:eae01b881372 | 10 | Timer debounce; |
gjones20 | 0:eae01b881372 | 11 | |
gjones20 | 0:eae01b881372 | 12 | uint16_t fmstation=10740; |
gjones20 | 0:eae01b881372 | 13 | |
gjones20 | 0:eae01b881372 | 14 | I2C myi2c(p9,p10); |
gjones20 | 0:eae01b881372 | 15 | Adafruit_Si4713 radio = Adafruit_Si4713(myi2c, p5, 0x63<<1); |
gjones20 | 0:eae01b881372 | 16 | |
gjones20 | 0:eae01b881372 | 17 | void StationDown(); |
gjones20 | 0:eae01b881372 | 18 | void StationUp(); |
gjones20 | 0:eae01b881372 | 19 | |
gjones20 | 0:eae01b881372 | 20 | void StationDown() { |
gjones20 | 0:eae01b881372 | 21 | if (debounce.read_ms()>200 && fmstation >= 8800) { |
gjones20 | 0:eae01b881372 | 22 | fmstation=fmstation-10; |
gjones20 | 0:eae01b881372 | 23 | radio.tuneFM(fmstation); |
gjones20 | 0:eae01b881372 | 24 | debounce.reset(); |
gjones20 | 0:eae01b881372 | 25 | } |
gjones20 | 0:eae01b881372 | 26 | } |
gjones20 | 0:eae01b881372 | 27 | |
gjones20 | 0:eae01b881372 | 28 | void StationUp() { |
gjones20 | 0:eae01b881372 | 29 | if (debounce.read_ms()>200 && fmstation <= 10800) { |
gjones20 | 0:eae01b881372 | 30 | fmstation=fmstation+10; |
gjones20 | 0:eae01b881372 | 31 | radio.tuneFM(fmstation); |
gjones20 | 0:eae01b881372 | 32 | debounce.reset(); |
gjones20 | 0:eae01b881372 | 33 | } |
gjones20 | 0:eae01b881372 | 34 | } |
gjones20 | 0:eae01b881372 | 35 | |
gjones20 | 0:eae01b881372 | 36 | int main() { |
gjones20 | 0:eae01b881372 | 37 | |
gjones20 | 0:eae01b881372 | 38 | printf("Adafruit Radio - Si4713 Test\r\n"); |
gjones20 | 0:eae01b881372 | 39 | |
gjones20 | 0:eae01b881372 | 40 | if (! radio.begin()) { |
gjones20 | 0:eae01b881372 | 41 | printf("Couldn't find radio?\r\n"); |
gjones20 | 0:eae01b881372 | 42 | while (1); |
gjones20 | 0:eae01b881372 | 43 | } |
gjones20 | 0:eae01b881372 | 44 | |
gjones20 | 0:eae01b881372 | 45 | /* |
gjones20 | 0:eae01b881372 | 46 | // Uncomment to scan power of entire range from 87.5 to 108.0 MHz |
gjones20 | 0:eae01b881372 | 47 | for (uint16_t f = 8750; f<10800; f+=10) { |
gjones20 | 0:eae01b881372 | 48 | radio.readTuneMeasure(f); |
gjones20 | 0:eae01b881372 | 49 | printf("Measuring %.1f\t",f/100.0); |
gjones20 | 0:eae01b881372 | 50 | radio.readTuneStatus(); |
gjones20 | 0:eae01b881372 | 51 | printf("%i\r\n",radio.currNoiseLevel); |
gjones20 | 0:eae01b881372 | 52 | } |
gjones20 | 0:eae01b881372 | 53 | */ |
gjones20 | 0:eae01b881372 | 54 | |
gjones20 | 0:eae01b881372 | 55 | printf("\n\rSet TX power"); |
gjones20 | 0:eae01b881372 | 56 | radio.setTXpower(115); // dBuV, 88-115 max |
gjones20 | 0:eae01b881372 | 57 | |
gjones20 | 0:eae01b881372 | 58 | |
gjones20 | 0:eae01b881372 | 59 | printf("\n\rTuning into %.1f\r\n",fmstation/100.0); |
gjones20 | 0:eae01b881372 | 60 | radio.tuneFM(fmstation); |
gjones20 | 0:eae01b881372 | 61 | |
gjones20 | 0:eae01b881372 | 62 | // This will tell you the status in case you want to read it from the chip |
gjones20 | 0:eae01b881372 | 63 | radio.readTuneStatus(); |
gjones20 | 0:eae01b881372 | 64 | printf("\tCurr freq: %d\r\n", radio.currFreq); |
gjones20 | 0:eae01b881372 | 65 | printf("\tCurr freqdBuV: %d\r\n", radio.currdBuV); |
gjones20 | 0:eae01b881372 | 66 | printf("\tCurr ANTcap: %d\r\n", radio.currAntCap); |
gjones20 | 0:eae01b881372 | 67 | |
gjones20 | 0:eae01b881372 | 68 | debounce.start(); |
gjones20 | 0:eae01b881372 | 69 | decrease.rise(&StationDown); |
gjones20 | 0:eae01b881372 | 70 | increase.rise(&StationUp); |
gjones20 | 0:eae01b881372 | 71 | |
gjones20 | 0:eae01b881372 | 72 | while(1) { |
gjones20 | 0:eae01b881372 | 73 | lcd.cls(); |
gjones20 | 0:eae01b881372 | 74 | lcd.printf("FM STATION\n"); |
gjones20 | 0:eae01b881372 | 75 | lcd.printf("%1.1f MHz",fmstation/100.0); |
gjones20 | 0:eae01b881372 | 76 | wait(0.25); |
gjones20 | 0:eae01b881372 | 77 | } |
gjones20 | 0:eae01b881372 | 78 | //printf("\n\rTuning into %.1f\r\n",fmstation/100.0); |
gjones20 | 0:eae01b881372 | 79 | |
gjones20 | 0:eae01b881372 | 80 | } |
gjones20 | 0:eae01b881372 | 81 |