极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 24924|回复: 21

How to use the GSM shield with Arduino Leonardo and Arduino Mega

[复制链接]
发表于 2014-9-10 13:27:20 | 显示全部楼层 |阅读模式
本帖最后由 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引脚吧?

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

 楼主| 发表于 2014-9-10 13:28:00 | 显示全部楼层
折弯折后,这块板子以后就废掉了。
回复 支持 反对

使用道具 举报

发表于 2014-9-11 10:30:17 | 显示全部楼层
有點不明白, Uno 跟 Mega 在 pin 2,3 上的 interrupt 設定是一樣的, 只有 Leonardo 是不同.
為何在 uno 上沒問題, 在 Mega 上就不行呢?
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-9-11 16:20:53 | 显示全部楼层
本帖最后由 kevinzhang 于 2014-9-11 16:39 编辑
Super169 发表于 2014-9-11 10:30
有點不明白, Uno 跟 Mega 在 pin 2,3 上的 interrupt 設定是一樣的, 只有 Leonardo 是不同.
為何在 uno 上 ...


越听越糊涂了。。。。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-9-11 16:56:26 | 显示全部楼层
不明白,等大神搭救
回复 支持 反对

使用道具 举报

发表于 2014-9-11 19:02:56 | 显示全部楼层
原作者既然明言要把第2腳彎曲至確保不跟 Mega 有任何接觸,相信必有其苦衷。

但按理 既然 Mega 第2腳已沒有用,應可把它設為輸入,這樣就算跟 GSM Shield 有電氣連接,也不應有問題才是。但,既然原作者已.....,若不怕造成損壞,也可作實驗一試,但後果要自負啊。
回复 支持 反对

使用道具 举报

发表于 2014-9-11 23:09:20 | 显示全部楼层
kevinzhang 发表于 2014-9-11 16:20
越听越糊涂了。。。。

因為它說:
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.
回复 支持 反对

使用道具 举报

发表于 2014-9-12 00:00:20 | 显示全部楼层
Super169 发表于 2014-9-11 23:09
因為它說:

原因在這:
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
回复 支持 反对

使用道具 举报

发表于 2014-9-12 02:36:06 | 显示全部楼层
本帖最后由 Super169 于 2014-9-12 02:40 编辑
eddiewwm 发表于 2014-9-12 00:00
原因在這:
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?

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-9-12 06:26:26 | 显示全部楼层
{:soso_e134:}{:soso_e134:}{:soso_e134:}
回复 支持 反对

使用道具 举报

发表于 2014-9-12 10:40:45 | 显示全部楼层
Super169 发表于 2014-9-12 02:36
這正是問題所在, 而非原因.....

pin 2 同 pin 3, 在 Uno 同 Mega 都係一樣的, 只係 Leonardo 有分別 ...

Mega2560 的 PinMapping:
http://arduino.cc/en/Hacking/PinMapping2560

若用 http://arduino.cc/en/Reference/AttachInterrupt 的描述,當然是問題,因為它本身就是問題的所在。
回复 支持 反对

使用道具 举报

发表于 2014-9-12 10:51:10 | 显示全部楼层
eddiewwm 发表于 2014-9-12 10:40
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 可唔可以直接少少謂解一下.
回复 支持 反对

使用道具 举报

 楼主| 发表于 2014-9-12 10:57:34 | 显示全部楼层
{:soso_e153:}晕啊{:soso_e134:}
回复 支持 反对

使用道具 举报

发表于 2014-9-12 11:44:52 | 显示全部楼层
Super169 发表于 2014-9-12 10:51
唔好意思, 都仲係唔明..

跟據 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

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复 支持 反对

使用道具 举报

发表于 2014-9-12 11:55:27 | 显示全部楼层
本帖最后由 Super169 于 2014-9-12 11:58 编辑
eddiewwm 发表于 2014-9-12 11:44
祇要實際看回電路圖和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 並非如此.



因為我是根據它的描述去想的, 所以才不明白.  如果這裡有錯的話 (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:} )

回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-15 02:15 , Processed in 0.037613 second(s), 20 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表