for orginal PCB
Dependencies: EthernetInterface SCP1000 WebSocketClient mbed-rtos mbed
Fork of ku-make_sensor201302 by
Revision 0:d368632c8662, committed 2012-12-06
- Comitter:
- kumajoi
- Date:
- Thu Dec 06 17:44:24 2012 +0000
- Child:
- 1:de9966da02f1
- Commit message:
- for MakeFairTokyo2012
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EthernetInterface.lib Thu Dec 06 17:44:24 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/EthernetInterface/#a0ee3ae75cfa
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/SCP1000.lib Thu Dec 06 17:44:24 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/kadams6/code/SCP1000/#47d6f205890b
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/WebSocketClient.lib Thu Dec 06 17:44:24 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/samux/code/WebSocketClient/#86e89a0369b9
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extlib/TextLCD.cpp Thu Dec 06 17:44:24 2012 +0000 @@ -0,0 +1,167 @@ +/* mbed TextLCD Library, for a 4-bit LCD based on HD44780 + * Copyright (c) 2007-2010, sford + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +/* + * Modified for star board orange by Shinichiro Nakamura. (CuBeatSystems) + * + * ID : shintamainjp + * Added : RW- + */ + +#include "TextLCD.h" +#include "mbed.h" + +TextLCD::TextLCD(PinName rs, PinName rw, PinName e, PinName d0, PinName d1, + PinName d2, PinName d3, LCDType type) : _rs(rs), _rw(rw), + _e(e), _d(d0, d1, d2, d3), + _type(type) { + + _e = 1; + _rs = 0; // command mode + _rw = 0; + + wait(0.015); // Wait 15ms to ensure powered up + + // send "Display Settings" 3 times (Only top nibble of 0x30 as we've got 4-bit bus) + for (int i=0; i<3; i++) { + writeByte(0x3); + wait(0.00164); // this command takes 1.64ms, so wait for it + } + writeByte(0x2); // 4-bit mode + wait(0.000040f); // most instructions take 40us + + writeCommand(0x28); // Function set 001 BW N F - - + writeCommand(0x0C); + writeCommand(0x6); // Cursor Direction and Display Shift : 0000 01 CD S (CD 0-left, 1-right S(hift) 0-no, 1-yes + cls(); +} + +void TextLCD::character(int column, int row, int c) { + int a = address(column, row); + writeCommand(a); + writeData(c); +} + +void TextLCD::cls() { + writeCommand(0x01); // cls, and set cursor to 0 + wait(0.00164f); // This command takes 1.64 ms + locate(0, 0); +} + +void TextLCD::locate(int column, int row) { + _column = column; + _row = row; +} + +int TextLCD::_putc(int value) { + if (value == '\n') { + _column = 0; + _row++; + if (_row >= rows()) { + _row = 0; + } + } else { + character(_column, _row, value); + _column++; + if (_column >= columns()) { + _column = 0; + _row++; + if (_row >= rows()) { + _row = 0; + } + } + } + return value; +} + +int TextLCD::_getc() { + return -1; +} + +void TextLCD::writeByte(int value) { + _d = value >> 4; + wait(0.000040f); // most instructions take 40us + _e = 0; + wait(0.000040f); + _e = 1; + _d = value >> 0; + wait(0.000040f); + _e = 0; + wait(0.000040f); // most instructions take 40us + _e = 1; +} + +void TextLCD::writeCommand(int command) { + _rs = 0; + writeByte(command); +} + +void TextLCD::writeData(int data) { + _rs = 1; + writeByte(data); +} + +int TextLCD::address(int column, int row) { + switch (_type) { + case LCD20x4: + switch (row) { + case 0: + return 0x80 + column; + case 1: + return 0xc0 + column; + case 2: + return 0x94 + column; + case 3: + return 0xd4 + column; + } + case LCD16x2B: + return 0x80 + (row * 40) + column; + case LCD16x2: + case LCD20x2: + default: + return 0x80 + (row * 0x40) + column; + } +} + +int TextLCD::columns() { + switch (_type) { + case LCD20x4: + case LCD20x2: + return 20; + case LCD16x2: + case LCD16x2B: + default: + return 16; + } +} + +int TextLCD::rows() { + switch (_type) { + case LCD20x4: + return 4; + case LCD16x2: + case LCD16x2B: + case LCD20x2: + default: + return 2; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/extlib/TextLCD.h Thu Dec 06 17:44:24 2012 +0000 @@ -0,0 +1,119 @@ +/* mbed TextLCD Library, for a 4-bit LCD based on HD44780 + * Copyright (c) 2007-2010, sford + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +/* + * Modified for star board orange by Shinichiro Nakamura. (CuBeatSystems) + * + * ID : shintamainjp + * Added : RW- + */ + +#ifndef MBED_TEXTLCD_H +#define MBED_TEXTLCD_H + +#include "mbed.h" + +/** A TextLCD interface for driving 4-bit HD44780-based LCDs + * + * Currently supports 16x2, 20x2 and 20x4 panels + * + * @code + * #include "mbed.h" + * #include "TextLCD.h" + * + * TextLCD lcd(p10, p12, p15, p16, p29, p30); // rs, e, d0-d3 + * + * int main() { + * lcd.printf("Hello World!\n"); + * } + * @endcode + */ +class TextLCD : public Stream { +public: + + /** LCD panel format */ + enum LCDType { + LCD16x2 /**< 16x2 LCD panel (default) */ + , LCD16x2B /**< 16x2 LCD panel alternate addressing */ + , LCD20x2 /**< 20x2 LCD panel */ + , LCD20x4 /**< 20x4 LCD panel */ + }; + + /** Create a TextLCD interface + * + * @param rs Instruction/data control line. + * @param rw Read/Write- control line. + * @param e Enable line (clock) + * @param d0-d3 Data lines + * @param type Sets the panel size/addressing mode (default = LCD16x2) + */ + TextLCD(PinName rs, PinName rw, PinName e, PinName d0, PinName d1, PinName d2, PinName d3, LCDType type = LCD16x2); + +#if DOXYGEN_ONLY + /** Write a character to the LCD + * + * @param c The character to write to the display + */ + int putc(int c); + + /** Write a formated string to the LCD + * + * @param format A printf-style format string, followed by the + * variables to use in formating the string. + */ + int printf(const char* format, ...); +#endif + + /** Locate to a screen column and row + * + * @param column The horizontal position from the left, indexed from 0 + * @param row The vertical position from the top, indexed from 0 + */ + void locate(int column, int row); + + /** Clear the screen and locate to 0,0 */ + void cls(); + + int rows(); + int columns(); + +protected: + + // Stream implementation functions + virtual int _putc(int value); + virtual int _getc(); + + int address(int column, int row); + void character(int column, int row, int c); + void writeByte(int value); + void writeCommand(int command); + void writeData(int data); + + DigitalOut _rs, _rw, _e; + BusOut _d; + LCDType _type; + + int _column; + int _row; +}; + +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Dec 06 17:44:24 2012 +0000 @@ -0,0 +1,104 @@ +#include "mbed.h" +#include "TextLCD.h" +#include "SCP1000.h" +#include "EthernetInterface.h" +#include "Websocket.h" + +DigitalOut myled(LED1); +TextLCD lcd(p24, p25, p26, p27, p28, p29, p30);; +AnalogIn light_in(p20); +AnalogIn temp_in(p19); +AnalogIn humid_in(p18); +SCP1000 scp1000(p11,p12,p13,p14); + +void splash(); +void splash() +{ + + lcd.cls(); + lcd.locate(0, 0); + lcd.printf("ku-make sensor"); + lcd.locate(0, 1); + lcd.printf("@kumajoi"); + wait(0.3); +} + +int main() +{ + splash(); + + const char apikey[] = "xxxxxxxxxxxxxxxxxxxxxx"; //your apikey + const char feed[]= "/feeds/00000"; //your feed URL + char cms[512]; + char recv[512]; + int token = 0; + EthernetInterface eth; + eth.init(); + eth.connect(); + wait(5); + lcd.cls(); + printf("IP Address is %s\n\r", eth.getIPAddress()); + lcd.printf("IP Address is %s\n\r", eth.getIPAddress()); + + while (1) { + Websocket ws("ws://api.cosm.com:8080/feeds/"); + ws.connect(); + if(ws.read(recv)) { + printf("rcv: %s\r\n", recv); + } + + float r_light, r_temp, r_humid, r_hpa; + float light, temp, humid, hpa; + + light = light_in; + temp = temp_in; + humid = humid_in; + hpa = scp1000.readPressure(); + + r_light = light * 3.3 * 5 / 0.013; + r_temp = temp * 3.3 * 100 - 60; + r_humid = humid * 3.3 * 100; + r_hpa = hpa / 100; + + + lcd.cls(); + lcd.locate(0, 0); + lcd.putc(0xB5); + lcd.putc(0xDD); + lcd.putc(0xC4); + lcd.putc(0xDE); + lcd.printf("%2.0f",r_temp); + lcd.putc(0xDf); + lcd.putc('C'); + lcd.printf(" %4.0fhPa", r_hpa); + lcd.locate(0, 1); + lcd.putc(0xBC); + lcd.putc(0xC2); + lcd.putc(0xC4); + lcd.putc(0xDE); + lcd.printf("%2.0f%% ",r_humid); + lcd.locate(9, 1); + lcd.printf("%4.0f", r_light); + lcd.putc(0xD9); + lcd.putc(0xB8); + lcd.putc(0xBD); + + myled = 1; + sprintf (cms,"{\"method\" : \"put\",\"resource\" : \"%s\",\"params\" : {},\"headers\" : {\"X-ApiKey\":\"%s\"},\"body\" :{\"version\" : \"1.0.0\",\"datastreams\" : [{\"id\" : \"3\",\"current_value\" : \"%4.0f\"},{\"id\" : \"4\",\"current_value\" : \"%4.0f\"},{\"id\" : \"5\",\"current_value\" : \"%3.0f\"},{\"id\" : \"6\",\"current_value\" : \"%3.0f\"}]},\"token\" : \"0x%d\"}\r\n",feed,apikey,r_hpa,r_light,r_temp,r_humid,token); + //set your ID and value + printf ("%s\r\n",cms); + token++; + int res = ws.send(cms); + myled= 0 ; + wait(5); + + if(ws.read(recv)) { + printf("rcv: %s\r\n", recv); + wait(1); + } + + ws.close(); + wait(300); + + } +} \ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Thu Dec 06 17:44:24 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#88a1a9c26ae3
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Dec 06 17:44:24 2012 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/63cdd78b2dc1 \ No newline at end of file