{
  "format": "evn-blocks",
  "version": 3,
  "title": "I2C: minimal",
  "needs": "an EVN IMU module (MPU-6500) on I2C port 1",
  "description": "Finds the EVN IMU module on I2C port 1 the safe way. A device answering at an address proves nothing (another chip can sit there), so the program also reads the chip's WHO_AM_I register (0x75), which an MPU-6500 answers with 0x70 (112). Only reads: the one byte written is the register number that the read sends first.",
  "workspace": {
    "blocks": {
      "languageVersion": 0,
      "blocks": [
        {
          "type": "evn_setup_start",
          "x": 30,
          "y": 30,
          "next": {
            "block": {
              "type": "evn_i2c_setup",
              "fields": {
                "PORT": "1"
              }
            }
          }
        },
        {
          "type": "evn_program_start",
          "x": 30,
          "y": 115,
          "next": {
            "block": {
              "type": "text_print",
              "inputs": {
                "TEXT": {
                  "block": {
                    "type": "text_join",
                    "inputs": {
                      "ADD0": {
                        "shadow": {
                          "type": "text",
                          "fields": {
                            "TEXT": "addresses answering on port 1: "
                          }
                        }
                      },
                      "ADD1": {
                        "block": {
                          "type": "evn_i2c_scan",
                          "fields": {
                            "PORT": "1"
                          }
                        }
                      }
                    },
                    "extraState": {
                      "itemCount": 2
                    }
                  }
                }
              },
              "next": {
                "block": {
                  "type": "controls_if",
                  "extraState": {
                    "hasElse": true
                  },
                  "inputs": {
                    "IF0": {
                      "block": {
                        "type": "logic_operation",
                        "fields": {
                          "OP": "AND"
                        },
                        "inputs": {
                          "A": {
                            "block": {
                              "type": "evn_i2c_probe",
                              "fields": {
                                "PORT": "1",
                                "ADDR": "68"
                              }
                            }
                          },
                          "B": {
                            "block": {
                              "type": "logic_compare",
                              "fields": {
                                "OP": "EQ"
                              },
                              "inputs": {
                                "A": {
                                  "block": {
                                    "type": "evn_i2c_read",
                                    "fields": {
                                      "PORT": "1",
                                      "ADDR": "68",
                                      "REG": "75",
                                      "FORMAT": "B"
                                    }
                                  }
                                },
                                "B": {
                                  "shadow": {
                                    "type": "math_number",
                                    "fields": {
                                      "NUM": 112
                                    }
                                  }
                                }
                              }
                            }
                          }
                        }
                      }
                    },
                    "DO0": {
                      "block": {
                        "type": "text_print",
                        "inputs": {
                          "TEXT": {
                            "shadow": {
                              "type": "text",
                              "fields": {
                                "TEXT": "an MPU-6500 IMU at 0x68"
                              }
                            }
                          }
                        }
                      }
                    },
                    "ELSE": {
                      "block": {
                        "type": "text_print",
                        "inputs": {
                          "TEXT": {
                            "shadow": {
                              "type": "text",
                              "fields": {
                                "TEXT": "no MPU-6500 on port 1"
                              }
                            }
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        }
      ]
    }
  }
}
