0
  • 聊天消息
  • 系統(tǒng)消息
  • 評論與回復(fù)
登錄后你可以
  • 下載海量資料
  • 學(xué)習(xí)在線課程
  • 觀看技術(shù)視頻
  • 寫文章/發(fā)帖/加入社區(qū)
會員中心
創(chuàng)作中心

完善資料讓更多小伙伴認(rèn)識你,還能領(lǐng)取20積分哦,立即完善>

3天內(nèi)不再提示

怎樣將Arduino數(shù)據(jù)直接存儲到MySQL

454398 ? 來源:網(wǎng)絡(luò)整理 ? 作者:網(wǎng)絡(luò)整理 ? 2019-11-20 17:08 ? 次閱讀

步驟1:設(shè)置Arduino

怎樣將Arduino數(shù)據(jù)直接存儲到MySQL

刻錄以下內(nèi)容

void setup()

{

Serial.begin(9600);

}

void loop()

{

int i=0,j=0;

i=analogRead(A0);

j=analogRead(A1);

Serial.print(i);

Serial.print(“,”);

Serial.println(i);

}

步驟2:設(shè)置啟動MySQL

為MySQL安裝Wamp服務(wù)器并將其配置為存儲數(shù)據(jù)

運行wamp服務(wù)器

打開MySQL控制臺

選擇數(shù)據(jù)庫

然后為您的數(shù)據(jù)創(chuàng)建表

create table data(sno int(4) primary key auto_increment,LDR int(4),TEMP int(4));

使用desc your_table_name顯示表詳細(xì)信息

desc data;

這就是數(shù)據(jù)庫的全部內(nèi)容,現(xiàn)在我們可以進(jìn)行處理了……

第3步:設(shè)置處理IDE

下載并安裝Processing IDE 2.2.1

將上述給定的ZIP壓縮到MyDocuments/Processing/Libraries中

現(xiàn)在打開正在處理的IDE和檢查庫是否已正確安裝(如上圖所示)

然后將以下代碼復(fù)制并進(jìn)行處理,并自行命名

/*

ARDUINO TO MYSQL THROUGH PROCESSING

Read Serial messages from Arduino then write it in MySQL.

Author : J.V.JohnsonSelva September 2016

*/

import de.bezier.data.sql.*; //import the MySQL library

import processing.serial.*; //import the Serial library

MySQL msql; //Create MySQL Object

String[] a;

int end = 10; // the number 10 is ASCII for linefeed (end of serial.println), later we will look for this to break up individual messages

String serial; // declare a new string called ‘serial’ 。 A string is a sequence of characters (data type know as “char”)

Serial port; // The serial port, this is a new instance of the Serial class (an Object)

void setup() {

String user = “root”;

String pass = “”;

String database = “iot_database”;

msql = new MySQL( this, “l(fā)ocalhost”, database, user, pass );

port = new Serial(this, Serial.list()[0], 9600); // initializing the object by assigning a port and baud rate (must match that of Arduino)

port.clear(); // function from serial library that throws out the first reading, in case we started reading in the middle of a string from Arduino

serial = port.readStringUntil(end); // function that reads the string from serial port until a println and then assigns string to our string variable (called ‘serial’)

serial = null; // initially, the string will be null (empty)

}

void draw()

{

while (port.available() 》 0)

{

//as long as there is data coming from serial port, read it and store it

serial = port.readStringUntil(end);

}

if (serial != null)

{

//if the string is not empty, print the following

//Note: the split function used below is not necessary if sending only a single variable. However, it is useful for parsing (separating) messages when

//reading from multiple inputs in Arduino. Below is example code for an Arduino sketch

a = split(serial, ‘,’); //a new array (called ‘a(chǎn)’) that stores values into separate cells (separated by commas specified in your Arduino program

println(a[0]); //print LDR value

println(a[1]); //print LM35 value

function();

}

}

void function()

{

if ( msql.connect() )

{

msql.query( “insert into data(LDR,Temp)values(”+a[0]+“,”+a[1]+“)” );

}

else

{

// connection failed !

}

msql.close(); //Must close MySQL connection after Execution

}

第4步:執(zhí)行程序。

通過單擊“運行”按鈕運行程序,請關(guān)閉彈出窗口。關(guān)閉窗口將停止執(zhí)行,并在下面的查詢中查看在MySQL中存儲數(shù)據(jù)。..

select * from data;

查看數(shù)據(jù)插入器的數(shù)量可以使用下面的查詢。

select count(*) from data;

責(zé)任編輯:wv

聲明:本文內(nèi)容及配圖由入駐作者撰寫或者入駐合作網(wǎng)站授權(quán)轉(zhuǎn)載。文章觀點僅代表作者本人,不代表電子發(fā)燒友網(wǎng)立場。文章及其配圖僅供工程師學(xué)習(xí)之用,如有內(nèi)容侵權(quán)或者其他違規(guī)問題,請聯(lián)系本站處理。 舉報投訴
  • MySQL
    +關(guān)注

    關(guān)注

    1

    文章

    789

    瀏覽量

    26283
  • Arduino
    +關(guān)注

    關(guān)注

    187

    文章

    6453

    瀏覽量

    185927
收藏 人收藏

    評論

    相關(guān)推薦

    在FX3S上如何通過USB和GPIF數(shù)據(jù)存儲eMMC中?

    我使用的是賽普拉斯 FX3S。 S0 端口連接了 eMMC,F(xiàn)X3S 還連接了 TI DSP(TMS320C28346ZFE)。 我想通過 USB 數(shù)據(jù)和/或文件從主機 PC 存儲
    發(fā)表于 07-23 07:57

    MySQL的整體邏輯架構(gòu)

    支持多種存儲引擎是眾所周知的MySQL特性,也是MySQL架構(gòu)的關(guān)鍵優(yōu)勢之一。如果能夠理解MySQL Server與存儲引擎之間是
    的頭像 發(fā)表于 04-30 11:14 ?327次閱讀
    <b class='flag-5'>MySQL</b>的整體邏輯架構(gòu)

    如何MS訪問數(shù)據(jù)轉(zhuǎn)換為MySQL

    借助dbForgeStudio for MySQL,您可以輕松地數(shù)據(jù)從MicrosoftAccess遷移到MySQL,并保持數(shù)據(jù)和功能的完
    的頭像 發(fā)表于 01-23 13:47 ?325次閱讀
    如何<b class='flag-5'>將</b>MS訪問<b class='flag-5'>數(shù)據(jù)</b>轉(zhuǎn)換為<b class='flag-5'>MySQL</b>

    GitHub底層數(shù)據(jù)庫無縫升級MySQL 8.0的經(jīng)驗

    GitHub 團隊近日分享了他們 GitHub.com 的底層數(shù)據(jù)庫無縫升級 MySQL 8.0 的經(jīng)驗。 據(jù)介紹,GitHub 使用 MySQ
    的頭像 發(fā)表于 12-13 10:21 ?394次閱讀
    GitHub底層<b class='flag-5'>數(shù)據(jù)</b>庫無縫升級<b class='flag-5'>到</b><b class='flag-5'>MySQL</b> 8.0的經(jīng)驗

    MySQL執(zhí)行過程:如何進(jìn)行sql 優(yōu)化

    (1)客戶端發(fā)送一條查詢語句服務(wù)器; (2)服務(wù)器先查詢緩存,如果命中緩存,則立即返回存儲在緩存中的數(shù)據(jù); (3)未命中緩存后,MySQL 通過關(guān)鍵字
    的頭像 發(fā)表于 12-12 10:19 ?333次閱讀
    <b class='flag-5'>MySQL</b>執(zhí)行過程:如何進(jìn)行sql 優(yōu)化

    mysql數(shù)據(jù)庫基礎(chǔ)命令

    MySQL是一個流行的關(guān)系型數(shù)據(jù)庫管理系統(tǒng),經(jīng)常用于存儲、管理和操作數(shù)據(jù)。在本文中,我們詳細(xì)介紹MyS
    的頭像 發(fā)表于 12-06 10:56 ?441次閱讀

    mysql備份還原哪些方法

    和注意事項。 一、物理備份 物理備份是MySQL數(shù)據(jù)庫的全部數(shù)據(jù)文件直接復(fù)制另一個位置,可以
    的頭像 發(fā)表于 11-23 14:35 ?880次閱讀

    mysql數(shù)據(jù)庫備份與還原

    MySQL是一種常見的關(guān)系型數(shù)據(jù)庫管理系統(tǒng),用于存儲和管理數(shù)據(jù)。備份和還原數(shù)據(jù)庫是非常重要的操作,可以保護
    的頭像 發(fā)表于 11-23 14:32 ?1012次閱讀

    MySQL數(shù)據(jù)庫基礎(chǔ)知識

    MySQL 是一種開源的關(guān)系型數(shù)據(jù)庫管理系統(tǒng),它是目前最流行的數(shù)據(jù)庫之一。MySQL 提供了一種結(jié)構(gòu)化的方法來管理大量的數(shù)據(jù),并且具有高效、
    的頭像 發(fā)表于 11-21 11:09 ?834次閱讀

    mysql和sql server區(qū)別

    MySQL和SQL Server是兩種常見的關(guān)系型數(shù)據(jù)庫管理系統(tǒng)(RDBMS),用于存儲和管理數(shù)據(jù)庫。雖然它們都支持SQL語言,但在其他方面存在一些顯著的區(qū)別。以下是
    的頭像 發(fā)表于 11-21 11:07 ?1247次閱讀

    外部sql文件導(dǎo)入MySQL步驟

    外部sql文件導(dǎo)入MySQL是一項非常常見的操作,它允許我們事先準(zhǔn)備好的數(shù)據(jù)數(shù)據(jù)庫結(jié)構(gòu)導(dǎo)入
    的頭像 發(fā)表于 11-21 11:00 ?1207次閱讀

    MySQL導(dǎo)出的步驟

    MySQL是一種常用的關(guān)系型數(shù)據(jù)庫管理系統(tǒng),用于存儲和管理大量的結(jié)構(gòu)化數(shù)據(jù)。在實際應(yīng)用中,我們經(jīng)常需要將MySQL
    的頭像 發(fā)表于 11-21 10:58 ?662次閱讀

    數(shù)據(jù)mysql基本增刪改查

    MySQL是一種開源的關(guān)系型數(shù)據(jù)庫管理系統(tǒng),常用于Web應(yīng)用程序的數(shù)據(jù)存儲和管理。通過使用MySQL,用戶可以進(jìn)行
    的頭像 發(fā)表于 11-16 16:35 ?1352次閱讀

    mysql是一個什么類型的數(shù)據(jù)

    MySQL是一種關(guān)系型數(shù)據(jù)庫管理系統(tǒng)(RDBMS),用于存儲和管理大量結(jié)構(gòu)化數(shù)據(jù)。它被廣泛用于各種應(yīng)用程序和網(wǎng)站的后端,包括電子商務(wù)平臺、社交媒體網(wǎng)站、金融系統(tǒng)等等。
    的頭像 發(fā)表于 11-16 14:43 ?1434次閱讀

    如何數(shù)據(jù)MySQL遷移到Influxdb中

    如果以前是時序數(shù)據(jù)存放在MySQL,現(xiàn)在為了獲取更好的性能和使用可視化工具,我們需要將數(shù)據(jù)MySQL遷移到Influxdb中。 這看起來
    的頭像 發(fā)表于 11-02 10:54 ?1014次閱讀