“指南针”的版本间的差异

来自Microduino Wikipedia
跳转至: 导航搜索
设备
Pkj讨论 | 贡献
第2行: 第2行:
 
|-
 
|-
 
|
 
|
==目的==
+
==Objective==
  
本教程将教大家如何用Microduino-10DOF模块测到的磁场强度数据在Processing中显示一个指南针。
+
The course will show you how to simulate a compass in Processing by presenting the data of magnetic field strength detected by Microduino-10DOF module.
  
==设备==
+
==Equipments==
 
*'''[[Microduino-Core]]'''
 
*'''[[Microduino-Core]]'''
 
*'''[[Microduino-FT232R]]'''
 
*'''[[Microduino-FT232R]]'''
 
*'''[[Microduino-10DOF]]'''
 
*'''[[Microduino-10DOF]]'''
  
*其他硬件设备
+
*Other Hardware Equipments
**USB数据连接线  一根
+
**A USB cable
  
==原理图==
+
==Schematic Diagram==
  
直接使用Microduino-10DOF上的HMC5883L磁场强度传感器
+
The HMC5883L magnetic field strength sensor of Microduino-10DOF will be available.
  
==程序==
+
==Program==
  
compassMicroduino
+
Referring to  compassMicroduino
  
 
compass_simulator
 
compass_simulator
  
==调试==
+
==Debugging==
  
步骤一:按着原理图搭建硬件环境,像这样:
+
Step 1:Building the hardware environment according to the schematic diagram, just like this:
 
[[File:compass_simulatorConnectionDiagram.jpg|600px|center|thumb]]
 
[[File:compass_simulatorConnectionDiagram.jpg|600px|center|thumb]]
  
  
步骤二:解释一下代码:
+
Step 2:Here is the code we need:
  
本例需要两端的代码,Processing端和Microduino端
+
The code of the two ends (Processing and Microduino) 
  
 
Microduino:
 
Microduino:
  
//得到磁场强度数据后输出到串口以便Processing显示
+
//The data of the magnetic field strength will be exported into the serial port to be displayed on Processing 
  
 
   void loop()
 
   void loop()
第48行: 第48行:
 
Processing:
 
Processing:
  
//得到第一个串口的数据,并定义如果有换行就缓存
+
//After getting the data of the first serial port, defining them or caching them if there is a new line  // is always my  Arduino, so I open Serial.list()[0].
  // is always my  Arduino, so I open Serial.list()[0].
 
 
   // Open whatever port is the one you're using.
 
   // Open whatever port is the one you're using.
 
   myPort = new Serial(this, Serial.list()[0], 9600);
 
   myPort = new Serial(this, Serial.list()[0], 9600);
 
   myPort.bufferUntil('\n'); // Trigger a SerialEvent on new line
 
   myPort.bufferUntil('\n'); // Trigger a SerialEvent on new line
  
//把从Microduino接收到的数据取出来后以不同颜色的曲线图的形式显示在屏幕上,并标上标尺
+
//Presenting the data obtained from Microduino on the screen in the form of curves with different color and then marking them
  
函数说明:
+
Function Description:
  
//绘制磁场指针
+
//Drawing a magnetic field pointer
 
arrow(int x1, int y1, int x2, int y2, color c)
 
arrow(int x1, int y1, int x2, int y2, color c)
  
//判断是否可转换为数字
+
//Judging whether can convert them into numbers
 
isNumeric(String str)
 
isNumeric(String str)
  
步骤三:下载代码并编译通过。
+
Step 3:Uploading the code and compiling them successfully.
  
步骤四:运行后,用一块磁铁改变一下磁场,看看指针是否变化。
+
Step 4:After the system goes smoothly, you can use a magnet to change the magnetic field and see if there is any change.
  
==结果==
+
==Result==
  
屏幕上会显示一个简单的指南针,指针会随着磁场走,像这样:
+
There will be a simple compass displayed on the screen and the pointer will change along with the magnetic field. As follows:
 
[[File:compass_simulatorResult.jpg|600px|center|thumb]]
 
[[File:compass_simulatorResult.jpg|600px|center|thumb]]
  
  
==视频==
+
==Video==
  
  
 
|}
 
|}

2014年5月21日 (三) 07:17的版本

Objective

The course will show you how to simulate a compass in Processing by presenting the data of magnetic field strength detected by Microduino-10DOF module.

Equipments

  • Other Hardware Equipments
    • A USB cable

Schematic Diagram

The HMC5883L magnetic field strength sensor of Microduino-10DOF will be available.

Program

Referring to compassMicroduino

compass_simulator

Debugging

Step 1:Building the hardware environment according to the schematic diagram, just like this:

Compass simulatorConnectionDiagram.jpg


Step 2:Here is the code we need:

The code of the two ends (Processing and Microduino)

Microduino:

//The data of the magnetic field strength will be exported into the serial port to be displayed on Processing

 void loop()
 {
   mag.getHeading(&mx, &my, &mz);
   Serial.print(mx);
   Serial.print(",");
   Serial.println(my); 
 }

Processing:

//After getting the data of the first serial port, defining them or caching them if there is a new line // is always my Arduino, so I open Serial.list()[0].

 // Open whatever port is the one you're using.
 myPort = new Serial(this, Serial.list()[0], 9600);
 myPort.bufferUntil('\n'); // Trigger a SerialEvent on new line

//Presenting the data obtained from Microduino on the screen in the form of curves with different color and then marking them

Function Description:

//Drawing a magnetic field pointer arrow(int x1, int y1, int x2, int y2, color c)

//Judging whether can convert them into numbers isNumeric(String str)

Step 3:Uploading the code and compiling them successfully.

Step 4:After the system goes smoothly, you can use a magnet to change the magnetic field and see if there is any change.

Result

There will be a simple compass displayed on the screen and the pointer will change along with the magnetic field. As follows:


Video