How to use the GSM shield with Arduino Leonardo and Arduino Mega
本帖最后由 kevinzhang 于 2014-9-10 16:50 编辑The GSM shield communicates with an attached Arduino through the Software Serial library. By default, communication between the modem and Arduino happens on digital pins 2 and 3. On the Uno this works without modification, but to use the Leonardo or Mega boards, some slight changes are required.
The GSM_TX pin, pin 2 on the shield, sends information to the Arduino. The Arduino relies on an interrupt to know when to read the information on this pin. The Leonardo and Mega do not have interrupt capabilities on pin 2.
You do not need to change any code to program the shield for use with the Mega or Leonardo, the library will change the Arduino's RX pin automatically depending on the board selected in the "Tools" menu of the IDE.
Arduino Mega
The GSM library uses digital pin 10 to communicate with the Mega. On the GSM shield, connect a jumper wire between digital pins 2 and 10.
Bend the male header attached to pin 2 on the GSM shield to the side so it does not connect with the Mega.
这是不是意味着需要折弯GSM Shield上的PIN2引脚吧? 折弯折后,这块板子以后就废掉了。:( 有點不明白, Uno 跟 Mega 在 pin 2,3 上的 interrupt 設定是一樣的, 只有 Leonardo 是不同.
為何在 uno 上沒問題, 在 Mega 上就不行呢? 本帖最后由 kevinzhang 于 2014-9-11 16:39 编辑
Super169 发表于 2014-9-11 10:30 static/image/common/back.gif
有點不明白, Uno 跟 Mega 在 pin 2,3 上的 interrupt 設定是一樣的, 只有 Leonardo 是不同.
為何在 uno 上 ...
:(越听越糊涂了。。。。
不明白,等大神搭救:( 原作者既然明言要把第2腳彎曲至確保不跟 Mega 有任何接觸,相信必有其苦衷。
但按理 既然 Mega 第2腳已沒有用,應可把它設為輸入,這樣就算跟 GSM Shield 有電氣連接,也不應有問題才是。但,既然原作者已.....,若不怕造成損壞,也可作實驗一試,但後果要自負啊。:D kevinzhang 发表于 2014-9-11 16:20 static/image/common/back.gif
越听越糊涂了。。。。
因為它說:
By default, communication between the modem and Arduino happens on digital pins 2 and 3. On the Uno this works without modification, but to use the Leonardo or Mega boards, some slight changes are required.
但 digital pin 2 and 3, 在 Uno 及 Mega 是一樣的, 只是 Leonardo 有分別, 所以不明白為何 Uno works without modification, but for Mega, some slight change are required.
Super169 发表于 2014-9-11 23:09 static/image/common/back.gif
因為它說:
原因在這:
The GSM_TX pin, pin 2 on the shield, sends information to the Arduino. The Arduino relies on an interrupt to know when to read the information on this pin. The Leonardo and Mega do not have interrupt capabilities on pin 2.
http://arduino.cc/en/Guide/GSMShieldLeonardoMega
本帖最后由 Super169 于 2014-9-12 02:40 编辑
eddiewwm 发表于 2014-9-12 00:00 static/image/common/back.gif
原因在這:
The GSM_TX pin, pin 2 on the shield, sends information to the Arduino. The Arduino rel ...
這正是問題所在, 而非原因.....
pin 2 同 pin 3, 在 Uno 同 Mega 都係一樣的, 只係 Leonardo 有分別:
http://arduino.cc/en/Reference/AttachInterrupt
大家既 pin2 都有 interrupt, 只不過係int.0 同 int.1 既分別.
如果話 Leonardo 唔同, 我無問題, 但係點解 Mega 明明同 Uno 一樣都唔得?而要改用 pin 10?
{:soso_e134:}{:soso_e134:}{:soso_e134:} Super169 发表于 2014-9-12 02:36 static/image/common/back.gif
這正是問題所在, 而非原因.....
pin 2 同 pin 3, 在 Uno 同 Mega 都係一樣的, 只係 Leonardo 有分別 ...
Mega2560 的 PinMapping:
http://arduino.cc/en/Hacking/PinMapping2560
若用 http://arduino.cc/en/Reference/AttachInterrupt 的描述,當然是問題,因為它本身就是問題的所在。:) eddiewwm 发表于 2014-9-12 10:40 static/image/common/back.gif
Mega2560 的 PinMapping:
http://arduino.cc/en/Hacking/PinMapping2560
唔好意思, 都仲係唔明..
跟據 GSM Sheild 講:
By default, communication between the modem and Arduino happens on digital pins 2 and 3.
The GSM_TX pin, pin 2 on the shield, sends information to the Arduino. The Arduino relies on an interrupt to know when to read the information on this pin. The Leonardo and Mega do not have interrupt capabilities on pin 2.
而 Uno 同 Mega 既 pin 2 同 3 都係會觸發 int.0 同 int.1 (而 Leonardo 就調轉左).
而佢又話:
The GSM library uses digital pin 10 to communicate with the Mega. On the GSM shield, connect a jumper wire between digital pins 2 and 10.
我就更加唔明, Mega 既 digital pin 10 反而無 interrupt 既.....
可能有 D 野我理解錯左, 所以有點混亂, 唔知 ching 可唔可以直接少少謂解一下. {:soso_e153:}晕啊{:soso_e134:} Super169 发表于 2014-9-12 10:51 static/image/common/back.gif
唔好意思, 都仲係唔明..
跟據 GSM Sheild 講:
祇要實際看回電路圖和PinMapping,相信以下這個才是正確:
對於第10腳的疑惑,其實原作者亦已在文中說明了:
http://arduino.cc/en/Guide/GSMShieldLeonardoMega
Arduino MegaThe GSM library uses digital pin 10 to communicate with the Mega. On the GSM shield, connect a jumper wire between digital pins 2 and 10.
Bend the male header attached to pin 2 on the GSM shield to the side so it does not connect with the Mega
本帖最后由 Super169 于 2014-9-12 11:58 编辑
eddiewwm 发表于 2014-9-12 11:44 static/image/common/back.gif
祇要實際看回電路圖和PinMapping,相信以下這個才是正確:
oh, 即是說, arduino.cc 中, 對 mega 的 interrupt 描述有錯 (跟 pin mapping 不同)?
http://arduino.cc/en/Main/ArduinoBoardMega2560
External Interrupts: 2 (interrupt 0), 3 (interrupt 1), 18 (interrupt 5), 19 (interrupt 4), 20 (interrupt 3), and 21 (interrupt 2)
而 attachInterrupt 中的列表也是一致的, 我沒想過 pin mapping 並非如此.
http://image.geek-workshop.com/forum/201409/12/023601dbjbctagyg994z4t.jpg
因為我是根據它的描述去想的, 所以才不明白.如果這裡有錯的話 (D2 跟 D3 並非對應 Int.0 及 Int.1), 那就可以解釋到為何跟 Uno 有分別了.
另外有關 digital pin 10....它的解釋有問題...因為 mega 的 D10 本身也沒有 INT 的...但 pin mapping 是 map 到 Int.4?
今晚回家用 mega 做個簡單測試, 就可以確認 Int.0 及 Int.1 對應 的 pin 是那個了.
(哈哈...希望我的山寨 Mega 跟原廠的一樣吧 {:soso_e121:} )
页:
[1]
2